Skip to content

Commit

Permalink
feat(cli): restrict rollups-node resources
Browse files Browse the repository at this point in the history
now it is possible to define limits for memory and cpu used for the
rollups-node (validator) container, the defaults are generous but can be
redefined
  • Loading branch information
endersonmaia committed Aug 21, 2024
1 parent d19aaf5 commit c3c649b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
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
22 changes: 20 additions & 2 deletions apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ export default class Run extends BaseCommand<typeof Run> {
description: "port to listen for incoming connections",
default: 8080,
}),
"show-config": Flags.boolean({
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,
Expand Down Expand Up @@ -104,10 +114,18 @@ export default class Run extends BaseCommand<typeof Run> {
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 @@ -174,7 +192,7 @@ export default class Run extends BaseCommand<typeof Run> {
process.on("SIGINT", () => {});

try {
if (flags["show-config"]) {
if (flags["dry-run"]) {
// show the docker compose configuration
await execa("docker", [...compose_args, "config"], {
env,
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"

0 comments on commit c3c649b

Please sign in to comment.