From 448fe60e5466024d9a4f49ddc9b58f45ce44b28c Mon Sep 17 00:00:00 2001 From: Danilo Tuler Date: Mon, 5 Aug 2024 22:37:48 -0300 Subject: [PATCH] feat(cli): flags to disable optional services (explorer, bundler, paymaster) --- .changeset/curvy-cougars-allow.md | 5 +++ apps/cli/src/commands/run.ts | 30 +++++++++++++++-- ...se-aa.yaml => docker-compose-bundler.yaml} | 29 +--------------- .../cli/src/node/docker-compose-database.yaml | 5 --- .../cli/src/node/docker-compose-explorer.yaml | 3 ++ .../src/node/docker-compose-paymaster.yaml | 33 +++++++++++++++++++ 6 files changed, 70 insertions(+), 35 deletions(-) create mode 100644 .changeset/curvy-cougars-allow.md rename apps/cli/src/node/{docker-compose-aa.yaml => docker-compose-bundler.yaml} (64%) create mode 100644 apps/cli/src/node/docker-compose-paymaster.yaml diff --git a/.changeset/curvy-cougars-allow.md b/.changeset/curvy-cougars-allow.md new file mode 100644 index 00000000..2c12b7ed --- /dev/null +++ b/.changeset/curvy-cougars-allow.md @@ -0,0 +1,5 @@ +--- +"@cartesi/cli": minor +--- + +flags to disable optional services (explorer, bundler, paymaster) diff --git a/apps/cli/src/commands/run.ts b/apps/cli/src/commands/run.ts index 4ea2fabc..f3364147 100644 --- a/apps/cli/src/commands/run.ts +++ b/apps/cli/src/commands/run.ts @@ -17,6 +17,24 @@ export default class Run extends BaseCommand { description: "interval between blocks (in seconds)", default: 5, }), + "disable-explorer": Flags.boolean({ + default: false, + description: + "disable local explorer service to save machine resources", + summary: "disable explorer service", + }), + "disable-bundler": Flags.boolean({ + default: false, + description: + "disable local bundler service to save machine resources", + summary: "disable bundler service", + }), + "disable-paymaster": Flags.boolean({ + default: false, + description: + "disable local paymaster service to save machine resources", + summary: "disable paymaster service", + }), "epoch-length": Flags.integer({ description: "length of an epoch (in blocks)", default: 720, @@ -99,10 +117,18 @@ export default class Run extends BaseCommand { composeFiles.push("docker-compose-anvil.yaml"); // explorer - composeFiles.push("docker-compose-explorer.yaml"); + if (!flags["disable-explorer"]) { + composeFiles.push("docker-compose-explorer.yaml"); + } // account abstraction - composeFiles.push("docker-compose-aa.yaml"); + if (!flags["disable-bundler"]) { + composeFiles.push("docker-compose-bundler.yaml"); + } + if (!flags["disable-paymaster"] && !flags["disable-bundler"]) { + // only add paymaster if bundler is enabled + composeFiles.push("docker-compose-paymaster.yaml"); + } // load the no-backend compose file if (flags["no-backend"]) { diff --git a/apps/cli/src/node/docker-compose-aa.yaml b/apps/cli/src/node/docker-compose-bundler.yaml similarity index 64% rename from apps/cli/src/node/docker-compose-aa.yaml rename to apps/cli/src/node/docker-compose-bundler.yaml index 7b9465ff..3295d207 100644 --- a/apps/cli/src/node/docker-compose-aa.yaml +++ b/apps/cli/src/node/docker-compose-bundler.yaml @@ -30,40 +30,13 @@ services: - "--polling-interval" - "100" - "--enable-debug-endpoints" - - mock-verifying-paymaster: - image: cartesi/sdk:0.10.0 - command: "mock-verifying-paymaster" - environment: - - ALTO_RPC=http://alto:4337 - - ANVIL_RPC=http://anvil:8545 - prompt: image: debian:bookworm-slim environment: - PROMPT_TXT_06_PAYMASTER: "Paymaster running at http://localhost:${CARTESI_LISTEN_PORT}/paymaster/" - PROMPT_TXT_07_BUNDLER: "Bundler running at http://localhost:${CARTESI_LISTEN_PORT}/bundler/" + PROMPT_TXT_06_BUNDLER: "Bundler running at http://localhost:${CARTESI_LISTEN_PORT}/bundler/rpc" traefik-config-generator: environment: - TRAEFIK_CONFIG_PAYMASTER: | - http: - routers: - paymaster: - rule: "PathPrefix(`/paymaster`)" - middlewares: - - "remove-paymaster-prefix" - service: paymaster - middlewares: - remove-paymaster-prefix: - replacePathRegex: - regex: "^/paymaster/(.*)" - replacement: "/$1" - services: - paymaster: - loadBalancer: - servers: - - url: "http://mock-verifying-paymaster:3000" TRAEFIK_CONFIG_BUNDLER: | http: routers: diff --git a/apps/cli/src/node/docker-compose-database.yaml b/apps/cli/src/node/docker-compose-database.yaml index 0b8bc704..fb661ab1 100644 --- a/apps/cli/src/node/docker-compose-database.yaml +++ b/apps/cli/src/node/docker-compose-database.yaml @@ -8,8 +8,3 @@ services: retries: 5 environment: - POSTGRES_PASSWORD=password - - database_creator: - depends_on: - database: - condition: service_healthy diff --git a/apps/cli/src/node/docker-compose-explorer.yaml b/apps/cli/src/node/docker-compose-explorer.yaml index 551dc793..f73b2fb2 100644 --- a/apps/cli/src/node/docker-compose-explorer.yaml +++ b/apps/cli/src/node/docker-compose-explorer.yaml @@ -2,6 +2,9 @@ services: database_creator: image: postgres:15-alpine command: ["createdb", "squid"] + depends_on: + database: + condition: service_healthy environment: PGHOST: ${PGHOST:-database} PGPORT: ${PGPORT:-5432} diff --git a/apps/cli/src/node/docker-compose-paymaster.yaml b/apps/cli/src/node/docker-compose-paymaster.yaml new file mode 100644 index 00000000..6829ed3a --- /dev/null +++ b/apps/cli/src/node/docker-compose-paymaster.yaml @@ -0,0 +1,33 @@ +services: + mock-verifying-paymaster: + image: cartesi/sdk:0.10.0 + command: "mock-verifying-paymaster" + environment: + - ALTO_RPC=http://alto:4337 + - ANVIL_RPC=http://anvil:8545 + + prompt: + image: debian:bookworm-slim + environment: + PROMPT_TXT_07_PAYMASTER: "Paymaster running at http://localhost:${CARTESI_LISTEN_PORT}/paymaster/" + + traefik-config-generator: + environment: + TRAEFIK_CONFIG_PAYMASTER: | + http: + routers: + paymaster: + rule: "PathPrefix(`/paymaster`)" + middlewares: + - "remove-paymaster-prefix" + service: paymaster + middlewares: + remove-paymaster-prefix: + replacePathRegex: + regex: "^/paymaster/(.*)" + replacement: "/$1" + services: + paymaster: + loadBalancer: + servers: + - url: "http://mock-verifying-paymaster:3000"