Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use crane to build rootfs #1

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-boxes-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": minor
---

bump to cartesi/sdk:0.6.0 in build and shell
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
36 changes: 16 additions & 20 deletions apps/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
const CARTESI_DEFAULT_RAM_SIZE = "128Mi";

const CARTESI_LABEL_SDK_VERSION = `${CARTESI_LABEL_PREFIX}.sdk_version`;
const CARTESI_DEFAULT_SDK_VERSION = "0.4.0";
const CARTESI_DEFAULT_SDK_VERSION = "0.6.0";

export default class BuildApplication extends BaseCommand<
typeof BuildApplication
Expand Down Expand Up @@ -141,32 +141,19 @@
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 @@
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
2 changes: 1 addition & 1 deletion apps/cli/src/commands/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Shell extends BaseCommand<typeof Shell> {
const ext2 = path.join(containerDir, path.basename(ext2Path));
const ramSize = "128Mi";
const driveLabel = "root";
const sdkImage = "cartesi/sdk:0.4.0"; // XXX: how to resolve sdk version?
const sdkImage = "cartesi/sdk:0.6.0"; // XXX: how to resolve sdk version?
const args = [
"run",
"--interactive",
Expand Down
Loading