Skip to content

Commit f0fae11

Browse files
committed
feat(cli): use crane to build rootfs tarball
1 parent aa088e9 commit f0fae11

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

.changeset/tiny-cats-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sunodo/cli": patch
3+
---
4+
5+
use crane to build rootfs tarball

apps/cli/src/commands/build.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,19 @@ Update your application Dockerfile using one of the templates at https://github.
141141
return info;
142142
}
143143

144-
// creates a rootfs tarball from the image
145-
// this process is not always fully reproducible
146-
// FIXME: we could use the image and create a flat rootfs without
147-
// `docker container create` (use undocker, umoci, a native typescript implementation, etc.)
144+
// saves the OCI Image to a tarball
148145
private async createTarball(
149146
image: string,
150147
outputFilePath: string,
151148
): Promise<void> {
152149
// create docker tarball from app image
153150
const { stdout: appCid } = await execa("docker", [
154-
"container",
155-
"create",
156-
"--platform",
157-
"linux/riscv64",
151+
"image",
152+
"save",
158153
image,
159-
]);
160-
161-
await execa("docker", [
162-
"container",
163-
"export",
164154
"-o",
165155
outputFilePath,
166-
appCid,
167156
]);
168-
169-
await execa("docker", ["container", "rm", appCid]);
170157
}
171158

172159
// 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.
201188
await execa("docker", ["container", "rm", cid]);
202189
}
203190

204-
// returns the command to create rootfs from a tarball
191+
// returns the command to create rootfs tarball from an OCI Image tarball
205192
private static createRootfsTarCommand(): string[] {
206-
return [
193+
const cmd = [
194+
"cat",
195+
"/tmp/input",
196+
"|",
197+
"crane",
198+
"export",
199+
"-", // OCI Image from stdin
200+
"-", // rootfs tarball to stdout
201+
"|",
207202
"bsdtar",
208203
"-cf",
209204
"/tmp/output",
210205
"--format=gnutar",
211-
"@/tmp/input",
206+
"@/dev/stdin", // rootfs tarball from stdin
212207
];
208+
return ["/usr/bin/env", "bash", "-c", cmd.join(" ")];
213209
}
214210

215211
// returns the command to create ext2 from a rootfs

0 commit comments

Comments
 (0)