Skip to content

Commit

Permalink
improve docker setup with profile
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Sep 19, 2024
1 parent be3d539 commit ef757d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
11 changes: 9 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NODE_ENV=development

DB_USER=postgres
DB_DATABASE=postgres
DB_PASSWORD=postgres
Expand All @@ -19,7 +21,12 @@ DB_GEMINI_3H_TESTNET_REWARDS=gemini_3h_testnet_rewards
DB_GEMINI_3G_TESTNET_REWARDS=gemini_3g_testnet_rewards

HASURA_GRAPHQL_ADMIN_SECRET=helloworld
HASURA_GRAPHQL_PORT=8080

HASURA_GRAPHQL_ENABLE_CONSOLE=false
HASURA_GRAPHQL_JWT_SECRET='{ "type": "HS256", "key": "<jwt-secret>" }'
HASURA_GRAPHQL_CORS_DOMAIN="*"
HASURA_GRAPHQL_JWT_SECRET='{ "type": "HS256", "key": "this_is_a_mock_secret_with_32_chars" }'
HASURA_GRAPHQL_CORS_DOMAIN="*"

REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=redis
55 changes: 34 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
version: "3.8"
version: "3.9"

volumes:
postgres_data: {}
redis_data: {}
postgres_db: {}
redis_db: {}

services:
# Postgres Database
postgres:
image: postgres:16-alpine
volumes:
- postgres_db:/var/lib/postgresql/data
- ./indexers/db/docker-entrypoint-initdb.d/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_PORT: ${DB_PORT}
POSTGRES_HOST: ${DB_HOST}
ports:
- "${DB_PORT}:${DB_PORT}"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./indexers/db/docker-entrypoint-initdb.d/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
- "${DB_PORT}:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped

# Hasura GraphQL Engine
hasura_engine:
hasura:
image: hasura/graphql-engine:v2.40.0.cli-migrations-v3
depends_on:
- "postgres"
restart: always
volumes:
- ./indexers/db/migrations:/hasura-migrations
- ./indexers/db/metadata:/hasura-metadata
environment:
# Essential Environment Variables
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_CONSENSUS}
HASURA_GRAPHQL_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_CONSENSUS} # Main database connection
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_CONSENSUS}
HASURA_GRAPHQL_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_CONSENSUS} # Main database connection
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET} # Admin access secret
HASURA_GRAPHQL_JWT_SECRET: ${HASURA_GRAPHQL_JWT_SECRET} # JWT authentication secret

Expand Down Expand Up @@ -60,33 +65,33 @@ services:
HASURA_GRAPHQL_ENABLE_ALLOWLIST: "true" # Enable query allowlisting

# Gemini 3H Databases
HASURA_GRAPHQL_GEMINI_3H_CONSENSUS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_CONSENSUS}
HASURA_GRAPHQL_GEMINI_3H_ACCOUNTS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_ACCOUNTS}
HASURA_GRAPHQL_GEMINI_3H_LEADERBOARD_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_LEADERBOARD}
HASURA_GRAPHQL_GEMINI_3H_STAKING_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_STAKING}
HASURA_GRAPHQL_GEMINI_3H_TESTNET_REWARDS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3H_TESTNET_REWARDS}
HASURA_GRAPHQL_GEMINI_3H_CONSENSUS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_CONSENSUS}
HASURA_GRAPHQL_GEMINI_3H_ACCOUNTS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_ACCOUNTS}
HASURA_GRAPHQL_GEMINI_3H_LEADERBOARD_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_LEADERBOARD}
HASURA_GRAPHQL_GEMINI_3H_STAKING_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_STAKING}
HASURA_GRAPHQL_GEMINI_3H_TESTNET_REWARDS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3H_TESTNET_REWARDS}

# Gemini 3G Database
HASURA_GRAPHQL_GEMINI_3G_TESTNET_REWARDS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_GEMINI_3G_TESTNET_REWARDS}
HASURA_GRAPHQL_GEMINI_3G_TESTNET_REWARDS_DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_GEMINI_3G_TESTNET_REWARDS}

# Hasura Migrations and Metadata
HASURA_GRAPHQL_MIGRATIONS_DIR: /hasura-migrations
HASURA_GRAPHQL_METADATA_DIR: /hasura-metadata
ports:
- "${HASURA_GRAPHQL_PORT}:${HASURA_GRAPHQL_PORT}"
volumes:
- ./indexers/db/migrations:/hasura-migrations
- ./indexers/db/metadata:/hasura-metadata
- "${HASURA_GRAPHQL_PORT}:8080"
command:
- graphql-engine
- serve
restart: unless-stopped

# Gemini 3H Subquery Nodes
gemini_3h_accounts-subquery-node:
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
profiles:
- gemini_3h
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
Expand Down Expand Up @@ -117,6 +122,8 @@ services:
depends_on:
"postgres":
condition: service_healthy
profiles:
- gemini_3h
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
Expand Down Expand Up @@ -147,6 +154,8 @@ services:
depends_on:
"postgres":
condition: service_healthy
profiles:
- gemini_3h
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
Expand Down Expand Up @@ -177,6 +186,8 @@ services:
depends_on:
"postgres":
condition: service_healthy
profiles:
- gemini_3h
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
Expand Down Expand Up @@ -207,6 +218,8 @@ services:
depends_on:
"postgres":
condition: service_healthy
profiles:
- gemini_3g
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3G_RPC}
Expand Down
10 changes: 6 additions & 4 deletions indexers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"db"
],
"scripts": {
"docker:dev": "docker compose -p dev-astral-indexers -f ../docker-compose.yml up --remove-orphans",
"docker:prod": "docker compose -p prod-astral-indexers -f ../docker-compose.yml -f ../docker-compose.prod.yml up --remove-orphans -d",
"dev": "lerna run codegen && lerna run build && yarn docker:dev",
"prod": "lerna run codegen && lerna run build && yarn docker:prod",
"docker:dev:up": "docker compose -p dev-astral-indexers -f ../docker-compose.yml --profile gemini_3h --profile gemini_3g up --remove-orphans",
"docker:prod:up": "docker compose -p prod-astral-indexers -f ../docker-compose.yml -f ../docker-compose.prod.yml --profile gemini_3h --profile gemini_3g up --remove-orphans -d",
"docker:dev:down": "docker compose -p dev-astral-indexers -f ../docker-compose.yml down",
"docker:prod:down": "docker compose -p prod-astral-indexers -f ../docker-compose.yml -f ../docker-compose.prod.yml down",
"dev": "lerna run codegen && lerna run build && yarn docker:dev:up",
"prod": "lerna run codegen && lerna run build && yarn docker:prod:up",
"build": "lerna run build",
"codegen": "lerna run codegen",
"prepack": "lerna run prepack",
Expand Down

0 comments on commit ef757d0

Please sign in to comment.