Skip to content

Commit

Permalink
cli: enforce build for linux/riscv64 platform (#73)
Browse files Browse the repository at this point in the history
* feat(cli): enforce build for linux/riscv64 platform

since the target is always a Cartesi Machine (riscv64), cartesi build
should enforce the docker build environment via --platform argument
  • Loading branch information
endersonmaia authored Oct 22, 2024
1 parent 3b23e6e commit 29ba930
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-ghosts-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

enforce build for linux/riscv64 platform
10 changes: 9 additions & 1 deletion apps/cli/src/builder/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const buildImage = async (options: ImageBuildOptions): Promise<string> => {
const args = [
"buildx",
"build",
"--platform",
"linux/riscv64",
"--file",
dockerfile,
"--load",
Expand Down Expand Up @@ -89,7 +91,13 @@ export const build = async (
const filename = `${name}.${format}`;

// use pre-existing image or build docker image
const image = drive.image || (await buildImage(drive));
let image: string;
if (drive.image) {
image = drive.image;
await execa("docker", ["image", "pull", image]);
} else {
image = await buildImage(drive);
}

// get image info
const imageInfo = await getImageInfo(image);
Expand Down
2 changes: 0 additions & 2 deletions apps/cli/test/builder/data/Dockerfile.nonriscv

This file was deleted.

3 changes: 1 addition & 2 deletions apps/cli/test/builder/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ describe("when building with the docker builder", () => {
const drive: DockerDriveConfig = {
builder: "docker",
context: path.join(__dirname, "data"),
dockerfile: path.join(__dirname, "data", "Dockerfile.nonriscv"),
extraSize: 0,
format: "ext2",
tags: [],
image: undefined,
image: "debian:bookworm-slim",
target: undefined,
};
await expect(build("root", drive, image, destination)).rejects.toThrow(
Expand Down

0 comments on commit 29ba930

Please sign in to comment.