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

Add cpu and mem limits options #65

Merged
merged 2 commits into from
Aug 21, 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
5 changes: 5 additions & 0 deletions .changeset/chatty-toes-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

adds --dry-run to run command
5 changes: 5 additions & 0 deletions .changeset/tidy-dolphins-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

add --cpus and --memory to run command
32 changes: 32 additions & 0 deletions apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@
description: "port to listen for incoming connections",
default: 8080,
}),
cpus: Flags.integer({
description:
"Define the number of CPUs to use (eg.: 1) for the rollups-node",
summary: "number of cpu limits for the rollups-node",
}),
memory: Flags.integer({
description:
"Define the amount of memory to use for the rollups-node in MB (eg.: 1024)",
summary: "memory limit for the rollups-node in MB",
}),
"dry-run": Flags.boolean({
description: "show the docker compose configuration",
default: false,
hidden: true,
}),
};

public async run(): Promise<void> {
Expand Down Expand Up @@ -99,10 +114,18 @@
CARTESI_SNAPSHOT_DIR: "/usr/share/rollups-node/snapshot",
CARTESI_BIN_PATH: binPath,
CARTESI_LISTEN_PORT: listenPort.toString(),
CARTESI_VALIDATOR_CPUS: flags.cpus?.toString(),
CARTESI_VALIDATOR_MEMORY: flags.memory?.toString(),
};

// validator
const composeFiles = ["docker-compose-validator.yaml"];
if (flags.cpus) {
composeFiles.push("docker-compose-validator-cpus.yaml");
}
if (flags.memory) {
composeFiles.push("docker-compose-validator-memory.yaml");
}

// prompt
composeFiles.push("docker-compose-prompt.yaml");
Expand Down Expand Up @@ -169,6 +192,15 @@
process.on("SIGINT", () => {});

try {
if (flags["dry-run"]) {
// show the docker compose configuration
await execa("docker", [...compose_args, "config"], {
env,
stdio: "inherit",
});
return;
}

// run compose environment
await execa("docker", [...compose_args, "up", ...up_args], {
env,
Expand All @@ -176,7 +208,7 @@
});
} catch (e: unknown) {
// 130 is a graceful shutdown, so we can swallow it
if ((e as any).exitCode !== 130) {

Check warning on line 211 in apps/cli/src/commands/run.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
throw e;
}
} finally {
Expand Down
6 changes: 6 additions & 0 deletions apps/cli/src/node/docker-compose-validator-cpus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
validator:
deploy:
resources:
limits:
cpus: "${CARTESI_VALIDATOR_CPUS}"
6 changes: 6 additions & 0 deletions apps/cli/src/node/docker-compose-validator-memory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
validator:
deploy:
resources:
limits:
memory: "${CARTESI_VALIDATOR_MEMORY}M"
Loading