Skip to content

Commit aeba159

Browse files
committed
feat(cli): additional config flags to drive machine build
1 parent 33bb766 commit aeba159

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.changeset/dirty-crabs-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cartesi/cli": patch
3+
---
4+
5+
additional config flags to drive machine build

apps/cli/src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export type MachineConfig = {
151151
ramLength: string;
152152
ramImage: string;
153153
store?: string;
154+
useDockerEnv: boolean; // inject docker image ENV into cartesi-machine ENV
155+
useDockerWorkdir: boolean; // inject docker image WORKDIR into cartesi-machine WORKDIR
154156
user?: string; // default given by cartesi-machine
155157
};
156158

@@ -183,6 +185,8 @@ export const defaultMachineConfig = (): MachineConfig => ({
183185
ramLength: DEFAULT_RAM,
184186
ramImage: DEFAULT_RAM_IMAGE,
185187
store: "image",
188+
useDockerEnv: true,
189+
useDockerWorkdir: true,
186190
user: undefined,
187191
});
188192

@@ -378,6 +382,8 @@ const parseMachine = (value: TomlPrimitive): MachineConfig => {
378382
ramLength: parseString(toml.ram_length, DEFAULT_RAM),
379383
ramImage: parseString(toml.ram_image, DEFAULT_RAM_IMAGE),
380384
store: "image",
385+
useDockerEnv: parseBoolean(toml.use_docker_env, true),
386+
useDockerWorkdir: parseBoolean(toml.use_docker_workdir, true),
381387
user: parseOptionalString(toml.user),
382388
};
383389
};

apps/cli/src/machine.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ export const bootMachine = (
3535
ramLength,
3636
ramImage,
3737
store,
38+
useDockerEnv,
39+
useDockerWorkdir,
3840
user,
3941
} = machine;
4042

4143
// list of environment variables of docker image
42-
const env = info?.env ?? [];
44+
const env = useDockerEnv ? (info?.env ?? []) : [];
4345
const envs = env.map((variable) => `--env=${variable}`);
4446

4547
// check if we need a rootfstype boot arg
@@ -92,7 +94,7 @@ export const bootMachine = (
9294
if (finalHash) {
9395
args.push("--final-hash");
9496
}
95-
if (info?.workdir) {
97+
if (useDockerWorkdir && info?.workdir) {
9698
args.push(`--workdir="${info.workdir}"`);
9799
}
98100
if (interactive) {

apps/cli/tests/unit/config/fixtures/full.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# no_rollup = false
1010
# ram_image = "/usr/share/cartesi-machine/images/linux.bin" # directory inside SDK image
1111
# ram_length = "128Mi"
12+
# use_docker_env = true
13+
# use_docker_workdir = true
14+
# user = "dapp"
1215

1316
# [drives.root]
1417
# builder = "docker"
@@ -41,4 +44,3 @@
4144
# builder = "none"
4245
# filename = "./games/doom.sqfs"
4346
# mount = "/usr/local/games/doom"
44-

0 commit comments

Comments
 (0)