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

Expose GraphQL endpoint in CLI #134

Open
wants to merge 2 commits into
base: feature/cli-run-v2
Choose a base branch
from
Open
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/heavy-penguins-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

expose graphql endpoint
11 changes: 11 additions & 0 deletions apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
false,
)
.option("--enable-espresso", "enable espresso development node", false)
.option(
"--disable-graphql",
"disable local graphql service to save machine resources",
false,
)
.option(
"--no-backend",
"run a node without the application code",
Expand Down Expand Up @@ -75,6 +80,7 @@
disableBundler,
disablePaymaster,
enableEspresso,
disableGraphql,
backend,
verbose,
port,
Expand Down Expand Up @@ -166,6 +172,11 @@
composeFiles.push("docker-compose-espresso.yaml");
}

// graphql
if (!disableGraphql) {
composeFiles.push("docker-compose-graphql.yaml");
}

// load the no-backend compose file
if (backend) {
composeFiles.push("docker-compose-host.yaml");
Expand Down Expand Up @@ -221,7 +232,7 @@
});
} catch (e: unknown) {
// 130 is a graceful shutdown, so we can swallow it
if ((e as any).exitCode !== 130) {

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
throw e;
}
} finally {
Expand Down
67 changes: 67 additions & 0 deletions apps/cli/src/node/docker-compose-graphql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
services:
graphql_database_creator:
image: postgres:16-alpine
command: ["createdb", "graphql"]
depends_on:
database:
condition: service_healthy
environment:
PGHOST: ${PGHOST:-database}
PGPORT: ${PGPORT:-5432}
PGUSER: ${PGUSER:-postgres}
PGPASSWORD: ${PGPASSWORD:-password}
PGDATABASE: ${PGDATABASE:-postgres}

graphql_database_migration:
image: cartesi/sdk:0.12.0-alpha.8
environment:
POSTGRES_GRAPHQL_DB_URL: &graphql_db_url postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/graphql?sslmode=disable
command:
- /bin/bash
- -c
- |
migrate \
-source file:///usr/share/cartesi/rollups-graphql/migrations \
-database $$POSTGRES_GRAPHQL_DB_URL \
up
depends_on:
graphql_database_creator:
condition: service_completed_successfully

graphql:
image: cartesi/sdk:0.12.0-alpha.8
environment:
POSTGRES_GRAPHQL_DB_URL: *graphql_db_url
POSTGRES_NODE_DB_URL: postgres://${PGUSER:-postgres}:${PGPASSWORD:-password}@${PGHOST:-database}:${PGPORT:-5432}/${PGDATABASE:-postgres}?sslmode=disable
expose:
- 8080
command: ["cartesi-rollups-graphql"]
depends_on:
graphql_database_migration:
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"
14 changes: 1 addition & 13 deletions apps/cli/src/node/docker-compose-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ services:
prompt:
image: debian:bookworm-slim
environment:
PROMPT_TXT_02_GRAPHQL: "GraphQL running at http://localhost:${CARTESI_LISTEN_PORT}/graphql"
PROMPT_TXT_03_INSPECT: "Inspect running at http://localhost:${CARTESI_LISTEN_PORT}/inspect/"

traefik-config-generator:
Expand All @@ -48,15 +47,4 @@ services:
inspect_server:
loadBalancer:
servers:
- url: "http://validator:10012/inspect"
TRAEFIK_CONFIG_GRAPHQL_SERVER: |
http:
routers:
graphql_server:
rule: "PathPrefix(`/graphql`)"
service: graphql_server
services:
graphql_server:
loadBalancer:
servers:
- url: "http://validator:10000/graphql"
- url: "http://validator:10000/inspect"
Loading