Skip to content

Commit

Permalink
feat(cli): use crane to build rootfs tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
endersonmaia committed Apr 30, 2024
1 parent aaf524e commit e54f675
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-cats-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sunodo/cli": patch
---

use crane to build rootfs tarball
34 changes: 15 additions & 19 deletions apps/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
// create docker tarball from app image
const { stdout: appCid } = await execa("docker", [

Check warning on line 150 in apps/cli/src/commands/build.ts

View workflow job for this annotation

GitHub Actions / lint

'appCid' is assigned a value but never used
"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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e54f675

Please sign in to comment.