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

feat(cli): add --command to sunodo shell #67

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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/twenty-walls-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

add `--command` to `sunodo shell` to allow defining a different shell, defaulting to `/bin/bash`
19 changes: 10 additions & 9 deletions apps/cli/src/commands/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ export default class Shell extends BaseCommand<typeof Shell> {
description: "run as root user",
default: false,
}),
command: Flags.string({
description: "shell command to use (eg.: /bin/bash)",
required: false,
default: "/bin/bash",
}),
};

private async startShell(
ext2Path: string,
runAsRoot: boolean,
): Promise<void> {
private async startShell(ext2Path: string): Promise<void> {
const { flags } = await this.parse(Shell);
const containerDir = "/mnt";
const bind = `${path.resolve(path.dirname(ext2Path))}:${containerDir}`;
const ext2 = path.join(containerDir, path.basename(ext2Path));
Expand All @@ -47,7 +50,7 @@ export default class Shell extends BaseCommand<typeof Shell> {
`--flash-drive=label:${driveLabel},filename:${ext2}`,
];

if (runAsRoot) {
if (flags["run-as-root"]) {
args.push("--append-init=USER=root");
}

Expand All @@ -57,14 +60,12 @@ export default class Shell extends BaseCommand<typeof Shell> {
args.push("-it");
}

await execa("docker", [...args, "--", "/bin/bash"], {
await execa("docker", [...args, "--", flags.command], {
stdio: "inherit",
});
}

public async run(): Promise<void> {
const { flags } = await this.parse(Shell);

// use pre-existing image or build dapp image
const ext2Path = this.getContextPath("image.ext2");
if (!fs.existsSync(ext2Path)) {
Expand All @@ -74,6 +75,6 @@ export default class Shell extends BaseCommand<typeof Shell> {
}

// execute the machine and save snapshot
await this.startShell(ext2Path, flags["run-as-root"]);
await this.startShell(ext2Path);
}
}
Loading