Skip to content

Commit

Permalink
feat: self-hosted hasura for DataLayer graphql API (#23)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Closes GIT-76 GIT-77

## Description

- add a new Hasura service to docker-compose for serving the GraphQL of
the data layer

Note: this Hasura is a different service from the one that gets exposed
for Envio
  • Loading branch information
0xnigir1 authored Nov 6, 2024
1 parent 630bb88 commit c55bdd1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 11 deletions.
16 changes: 16 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ DATALAYER_PG_USER=postgres
DATALAYER_PG_DATABASE=datalayer-postgres
DATALAYER_POSTGRES_EXPOSED_PORT=5434

######################################################
############### DATALAYER HASURA API #################
######################################################
#for reference on Hasura configuration, see: https://hasura.io/docs/2.0/deployment/graphql-engine-flags/reference/
DATALAYER_HASURA_EXPOSED_PORT=8082
DATALAYER_HASURA_ENABLE_CONSOLE=true
DATALAYER_HASURA_ADMIN_SECRET=my-admin-secret
DATALAYER_HASURA_UNAUTHORIZED_ROLE=public
DATALAYER_HASURA_CORS_DOMAIN=*
DATALAYER_HASURA_ENABLE_TELEMETRY=false
# HASURA_GRAPHQL_METADATA_DATABASE_EXTENSIONS_SCHEMA: "chain_data_schema_1"
## enable debugging mode. It is recommended to disable this in production
DATALAYER_HASURA_DEV_MODE=true
DATALAYER_HASURA_ADMIN_INTERNAL_ERRORS=true
## uncomment next line to run console offline (i.e load console assets from server instead of CDN)
# HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets

############################################################
############### ENVIO POSTGRES & INDEXER ###################
Expand Down
66 changes: 55 additions & 11 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
datalayer-postgres:
datalayer-postgres-db:
image: postgres:16
restart: always
ports:
Expand All @@ -14,7 +14,50 @@ services:
POSTGRES_PASSWORD: ${DATALAYER_POSTGRES_PASSWORD}
networks:
- datalayer
envio-postgres:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DATALAYER_PG_USER}"]
interval: 5s
timeout: 5s
retries: 5

datalayer-graphql-api:
image: hasura/graphql-engine:v2.44.0
ports:
- "${DATALAYER_HASURA_EXPOSED_PORT:-8082}:8080"
restart: always
env_file:
- .env
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://${DATALAYER_PG_USER}:${DATALAYER_POSTGRES_PASSWORD}@datalayer-postgres-db:5432/${DATALAYER_PG_DATABASE}
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://${DATALAYER_PG_USER}:${DATALAYER_POSTGRES_PASSWORD}@datalayer-postgres-db:5432/${DATALAYER_PG_DATABASE}
HASURA_GRAPHQL_ENABLE_CONSOLE: ${DATALAYER_HASURA_ENABLE_CONSOLE:-true}
HASURA_GRAPHQL_ADMIN_SECRET: ${DATALAYER_HASURA_ADMIN_SECRET:-secret}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: ${DATALAYER_HASURA_UNAUTHORIZED_ROLE:-public}
HASURA_GRAPHQL_CORS_DOMAIN: ${DATALAYER_HASURA_CORS_DOMAIN:-*}
HASURA_GRAPHQL_ENABLE_TELEMETRY: ${DATALAYER_HASURA_ENABLE_TELEMETRY:-false}
HASURA_GRAPHQL_EXPERIMENTAL_FEATURES: bigquery_string_numeric_input
HASURA_GRAPHQL_BIGQUERY_STRING_NUMERIC_INPUT: true
# HASURA_GRAPHQL_METADATA_DATABASE_EXTENSIONS_SCHEMA: ${DATALAYER_HASURA_METADATA_DATABASE_EXTENSIONS_SCHEMA:-chain_data_schema_1}
## enable debugging mode. It is recommended to disable this in production
HASURA_GRAPHQL_DEV_MODE: ${DATALAYER_HASURA_DEV_MODE:-true}
HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup, http-log, webhook-log, websocket-log, query-log"
HASURA_GRAPHQL_ENABLED_APIS: "graphql,metrics"
HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS: ${DATALAYER_HASURA_ADMIN_INTERNAL_ERRORS:-true}
## uncomment next line to run console offline (i.e load console assets from server instead of CDN)
# HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
depends_on:
datalayer-postgres-db:
condition: service_healthy
healthcheck:
test: timeout 1s bash -c ':> /dev/tcp/127.0.0.1/8080' || exit 1
interval: 5s
timeout: 2s
retries: 50
start_period: 5s
networks:
- datalayer

indexer-postgres-db:
image: postgres:16
restart: always
ports:
Expand All @@ -28,14 +71,14 @@ services:
POSTGRES_USER: ${ENVIO_PG_USER}
POSTGRES_PASSWORD: ${ENVIO_POSTGRES_PASSWORD}
networks:
- indexer-service
graphql-engine:
- indexer
indexer-graphql-api:
image: hasura/graphql-engine:v2.23.0
ports:
- "${HASURA_EXPOSED_PORT:-8080}:${PORT:-8080}"
user: 1001:1001
depends_on:
- "envio-postgres"
- "indexer-postgres-db"
restart: always
env_file:
- .env
Expand All @@ -46,24 +89,25 @@ services:
retries: 50
start_period: 5s
networks:
- indexer-service
indexer-service:
- indexer
indexer:
build:
context: ./apps/indexer
dockerfile: Dockerfile
depends_on:
- "envio-postgres"
- "graphql-engine"
- "indexer-postgres-db"
- "indexer-graphql-api"
restart: always
env_file:
- .env
networks:
- indexer-service
- indexer
- datalayer
volumes:
db_data:
ganache-data:
networks:
indexer-service:
indexer:
name: indexer_test_network
datalayer:
name: datalayer_test_network

0 comments on commit c55bdd1

Please sign in to comment.