From 55f8c26fe51d57cfbdb174c1421a0d6a80e2fffa Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Tue, 3 Dec 2024 11:06:24 -0300 Subject: [PATCH 1/2] feat(cli): expose graphql endpoint --- .changeset/heavy-penguins-act.md | 5 ++ apps/cli/src/commands/run.ts | 11 ++++ apps/cli/src/node/docker-compose-graphql.yaml | 51 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .changeset/heavy-penguins-act.md create mode 100644 apps/cli/src/node/docker-compose-graphql.yaml diff --git a/.changeset/heavy-penguins-act.md b/.changeset/heavy-penguins-act.md new file mode 100644 index 00000000..ce6f4941 --- /dev/null +++ b/.changeset/heavy-penguins-act.md @@ -0,0 +1,5 @@ +--- +"@cartesi/cli": major +--- + +expose graphql endpoint diff --git a/apps/cli/src/commands/run.ts b/apps/cli/src/commands/run.ts index 4dd12bb6..f989f437 100644 --- a/apps/cli/src/commands/run.ts +++ b/apps/cli/src/commands/run.ts @@ -35,6 +35,12 @@ export default class Run extends BaseCommand { "disable local paymaster service to save machine resources", summary: "disable paymaster service", }), + "disable-graphql": Flags.boolean({ + default: false, + description: + "disable local graphql service to save machine resources", + summary: "disable graphql service", + }), "epoch-length": Flags.integer({ description: "length of an epoch (in blocks)", default: 720, @@ -136,6 +142,11 @@ export default class Run extends BaseCommand { // proxy composeFiles.push("docker-compose-proxy.yaml"); + // graphql + if (!flags["disable-graphql"]) { + composeFiles.push("docker-compose-graphql.yaml"); + } + // anvil composeFiles.push("docker-compose-anvil.yaml"); diff --git a/apps/cli/src/node/docker-compose-graphql.yaml b/apps/cli/src/node/docker-compose-graphql.yaml new file mode 100644 index 00000000..2f4431fe --- /dev/null +++ b/apps/cli/src/node/docker-compose-graphql.yaml @@ -0,0 +1,51 @@ +services: + graphql_database_creator: + image: postgres:15-alpine + command: ["createdb", "hlgraphql"] + depends_on: + database: + condition: service_healthy + environment: + PGHOST: ${PGHOST:-database} + PGPORT: ${PGPORT:-5432} + PGUSER: ${PGUSER:-postgres} + PGPASSWORD: ${PGPASSWORD:-password} + PGDATABASE: ${PGDATABASE:-postgres} + + graphql: + image: cartesi/sdk:devel + environment: + POSTGRES_GRAPHQL_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/hlgraphql?sslmode=disable + POSTGRES_NODE_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/${PGDATABASE:-postgres}?sslmode=disable + expose: + - 8080 + command: ["cartesi-rollups-hl-graphql", "--graphile-disable-sync"] + depends_on: + graphql_database_creator: + condition: service_completed_successfully + + prompt: + image: debian:bookworm-slim + environment: + PROMPT_TXT_04_GRAPHQL: "graphql endpoint running at http://localhost:${CARTESI_LISTEN_PORT}/graphql/" + + traefik-config-generator: + environment: + TRAEFIK_CONFIG_GRAPHQL: | + http: + routers: + graphql: + rule: "PathPrefix(`/graphql`)" + middlewares: + - "remove-graphql-prefix" + service: graphql + middlewares: + remove-graphql-prefix: + replacePathRegex: + regex: "^/graphql/(.*)" + replacement: "/$1" + services: + graphql: + loadBalancer: + servers: + - url: "http://graphql:8080" From 77e05068d13cea4482716d96063946a969587cd9 Mon Sep 17 00:00:00 2001 From: Enderson Maia Date: Tue, 3 Dec 2024 16:25:49 -0300 Subject: [PATCH 2/2] fixup! feat(cli): expose graphql endpoint --- apps/cli/src/node/docker-compose-graphql.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/cli/src/node/docker-compose-graphql.yaml b/apps/cli/src/node/docker-compose-graphql.yaml index 2f4431fe..2797d2a1 100644 --- a/apps/cli/src/node/docker-compose-graphql.yaml +++ b/apps/cli/src/node/docker-compose-graphql.yaml @@ -1,7 +1,7 @@ services: graphql_database_creator: image: postgres:15-alpine - command: ["createdb", "hlgraphql"] + command: ["createdb", "graphql"] depends_on: database: condition: service_healthy @@ -15,7 +15,7 @@ services: graphql: image: cartesi/sdk:devel environment: - POSTGRES_GRAPHQL_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/hlgraphql?sslmode=disable + POSTGRES_GRAPHQL_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/graphql?sslmode=disable POSTGRES_NODE_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/${PGDATABASE:-postgres}?sslmode=disable expose: - 8080