From e1acf89bd12b49a4b89dfd9e8040893c9c3d2b2a Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Mon, 15 Apr 2024 11:51:40 +0100 Subject: [PATCH] feat(cli): use crane to build rootfs tarball --- .changeset/tiny-cats-tickle.md | 5 +++++ apps/cli/src/commands/build.ts | 34 +++++++++++++++------------------- 2 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 .changeset/tiny-cats-tickle.md diff --git a/.changeset/tiny-cats-tickle.md b/.changeset/tiny-cats-tickle.md new file mode 100644 index 00000000..9e89d664 --- /dev/null +++ b/.changeset/tiny-cats-tickle.md @@ -0,0 +1,5 @@ +--- +"@cartesi/cli": patch +--- + +use crane to build rootfs tarball diff --git a/apps/cli/src/commands/build.ts b/apps/cli/src/commands/build.ts index d14e3ac7..aa25675c 100644 --- a/apps/cli/src/commands/build.ts +++ b/apps/cli/src/commands/build.ts @@ -141,32 +141,19 @@ Update your application Dockerfile using one of the templates at https://github. return info; } - // creates a rootfs tarball from the image - // this process is not always fully reproducible - // FIXME: we could use the image and create a flat rootfs without - // `docker container create` (use undocker, umoci, a native typescript implementation, etc.) + // saves the OCI Image to a tarball private async createTarball( image: string, outputFilePath: string, ): Promise { // create docker tarball from app image const { stdout: appCid } = await execa("docker", [ - "container", - "create", - "--platform", - "linux/riscv64", + "image", + "save", image, - ]); - - await execa("docker", [ - "container", - "export", "-o", outputFilePath, - appCid, ]); - - await execa("docker", ["container", "rm", appCid]); } // this wraps the call to the sdk image with a one-shot approach @@ -201,15 +188,24 @@ Update your application Dockerfile using one of the templates at https://github. await execa("docker", ["container", "rm", cid]); } - // returns the command to create rootfs from a tarball + // returns the command to create rootfs tarball from an OCI Image tarball private static createRootfsTarCommand(): string[] { - return [ + const cmd = [ + "cat", + "/tmp/input", + "|", + "crane", + "export", + "-", // OCI Image from stdin + "-", // rootfs tarball to stdout + "|", "bsdtar", "-cf", "/tmp/output", "--format=gnutar", - "@/tmp/input", + "@/dev/stdin", // rootfs tarball from stdin ]; + return ["/usr/bin/env", "bash", "-c", cmd.join(" ")]; } // returns the command to create ext2 from a rootfs