From ea68daa35d33cd56426674c09d5131864bd74d74 Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Wed, 21 Aug 2024 15:33:26 -0300 Subject: [PATCH] feat(cli): restrict rollups-node resources 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 --- .changeset/tidy-dolphins-serve.md | 5 +++++ apps/cli/src/commands/run.ts | 22 +++++++++++++++++-- .../node/docker-compose-validator-cpus.yaml | 6 +++++ .../node/docker-compose-validator-memory.yaml | 6 +++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .changeset/tidy-dolphins-serve.md create mode 100644 apps/cli/src/node/docker-compose-validator-cpus.yaml create mode 100644 apps/cli/src/node/docker-compose-validator-memory.yaml diff --git a/.changeset/tidy-dolphins-serve.md b/.changeset/tidy-dolphins-serve.md new file mode 100644 index 00000000..c0fe308a --- /dev/null +++ b/.changeset/tidy-dolphins-serve.md @@ -0,0 +1,5 @@ +--- +"@cartesi/cli": patch +--- + +add --cpus and --memory to run command diff --git a/apps/cli/src/commands/run.ts b/apps/cli/src/commands/run.ts index bf1ce3ed..4dd12bb6 100644 --- a/apps/cli/src/commands/run.ts +++ b/apps/cli/src/commands/run.ts @@ -54,7 +54,17 @@ export default class Run extends BaseCommand { 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, @@ -104,10 +114,18 @@ export default class Run extends BaseCommand { 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"); @@ -174,7 +192,7 @@ export default class Run extends BaseCommand { process.on("SIGINT", () => {}); try { - if (flags["show-config"]) { + if (flags["dry-run"]) { // show the docker compose configuration await execa("docker", [...compose_args, "config"], { env, diff --git a/apps/cli/src/node/docker-compose-validator-cpus.yaml b/apps/cli/src/node/docker-compose-validator-cpus.yaml new file mode 100644 index 00000000..eec5a1f5 --- /dev/null +++ b/apps/cli/src/node/docker-compose-validator-cpus.yaml @@ -0,0 +1,6 @@ +services: + validator: + deploy: + resources: + limits: + cpus: "${CARTESI_VALIDATOR_CPUS}" diff --git a/apps/cli/src/node/docker-compose-validator-memory.yaml b/apps/cli/src/node/docker-compose-validator-memory.yaml new file mode 100644 index 00000000..7334ef48 --- /dev/null +++ b/apps/cli/src/node/docker-compose-validator-memory.yaml @@ -0,0 +1,6 @@ +services: + validator: + deploy: + resources: + limits: + memory: "${CARTESI_VALIDATOR_MEMORY}M"