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

Docker build context #84

Merged
merged 2 commits into from
Oct 14, 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
7 changes: 4 additions & 3 deletions apps/cli/src/builder/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { tarToExt } from "./index.js";

type ImageBuildOptions = Pick<
DockerDriveConfig,
"dockerfile" | "tags" | "target"
"context" | "dockerfile" | "tags" | "target"
>;

type ImageInfo = {
Expand All @@ -22,7 +22,7 @@ type ImageInfo = {
* Build Docker image (linux/riscv64). Returns image id.
*/
const buildImage = async (options: ImageBuildOptions): Promise<string> => {
const { dockerfile, tags, target } = options;
const { context, dockerfile, tags, target } = options;
const buildResult = tmp.tmpNameSync();
const args = [
"buildx",
Expand All @@ -32,6 +32,7 @@ const buildImage = async (options: ImageBuildOptions): Promise<string> => {
"--load",
"--iidfile",
buildResult,
context,
];

// set tags for the image built
Expand All @@ -41,7 +42,7 @@ const buildImage = async (options: ImageBuildOptions): Promise<string> => {
args.push("--target", target);
}

await execa("docker", [...args, process.cwd()], { stdio: "inherit" });
await execa("docker", args, { stdio: "inherit" });
return fs.readFileSync(buildResult, "utf8");
};

Expand Down
4 changes: 4 additions & 0 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
const DEFAULT_FORMAT = "ext2";
const DEFAULT_RAM = "128Mi";
const DEFAULT_RAM_IMAGE_DOCKER = "/usr/share/cartesi-machine/images/linux.bin";

Check warning on line 11 in apps/cli/src/config.ts

View workflow job for this annotation

GitHub Actions / lint

'DEFAULT_RAM_IMAGE_DOCKER' is assigned a value but never used
const DEFAULT_RAM_IMAGE_LINUX = "/usr/share/cartesi-machine/images/linux.bin";
const DEFAULT_RAM_IMAGE_MAC =
"/opt/homebrew/share/cartesi-machine/images/linux.bin";
Expand All @@ -35,6 +35,7 @@

export type DockerDriveConfig = {
builder: "docker";
context: string;
dockerfile: string;
extraSize: number; // default is 0 (no extra size)
format: DriveFormat;
Expand Down Expand Up @@ -98,6 +99,7 @@

export const defaultRootDriveConfig = (): DriveConfig => ({
builder: "docker",
context: ".",
dockerfile: "Dockerfile", // file on current working directory
extraSize: 0,
format: DEFAULT_FORMAT,
Expand Down Expand Up @@ -333,6 +335,7 @@
}
case "docker": {
const {
context,
dockerfile,
extraSize,
format,
Expand All @@ -346,6 +349,7 @@
return {
builder: "docker",
image: parseOptionalString(image),
context: parseString(context, "."),
dockerfile: parseString(dockerfile, "Dockerfile"),
extraSize: parseBytes(extraSize, 0),
format: parseFormat(format),
Expand Down
12 changes: 12 additions & 0 deletions apps/cli/src/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export const bootMachine = async (
(variable) => `--append-entrypoint=export "${variable}"`,
);

// check if we need a rootfstype boot arg
const root = config.drives.root;
if (root?.format === "sqfs") {
const definedRootfsType = config.machine.bootargs.find((arg) =>
arg.startsWith("rootfstype="),
);
// not checking here if user intentionally defined wrong type
if (!definedRootfsType) {
config.machine.bootargs.push("rootfstype=squashfs");
}
}

// bootargs from config string array
const bootargs = machine.bootargs.map(
(arg) => `--append-bootargs="${arg}"`,
Expand Down
Loading