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

improve docker compose setup #851

Merged
merged 3 commits into from
Sep 20, 2024
Merged
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: 4 additions & 1 deletion .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 @@ -18,8 +20,9 @@ DB_GEMINI_3H_TESTNET_REWARDS=gemini_3h_testnet_rewards

DB_GEMINI_3G_TESTNET_REWARDS=gemini_3g_testnet_rewards

HASURA_GRAPHQL_PORT=8080
HASURA_GRAPHQL_ADMIN_SECRET=helloworld

HASURA_GRAPHQL_ENABLE_CONSOLE=false
HASURA_GRAPHQL_JWT_SECRET='{ "type": "HS256", "key": "<jwt-secret>" }'
HASURA_GRAPHQL_JWT_SECRET='{ "type": "HS256", "key": "this_is_a_mock_secret_with_32_chars" }'
HASURA_GRAPHQL_CORS_DOMAIN="*"
6 changes: 1 addition & 5 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
version: "3"

volumes:
db_data: {}
version: "3.9"

services:
postgres:
volumes:
- db_data:/var/lib/postgresql/data
- type: bind
source: /home/ubuntu/postgresql/conf/postgresql.conf
target: /etc/postgresql/postgresql.conf
Expand Down
61 changes: 35 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
version: "3.8"
version: "3.9"

volumes:
postgres_db: {}

services:
# Postgres Database
postgres:
container_name: 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
restart: unless-stopped
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- "${DB_PORT}:${DB_PORT}"
volumes:
- ./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

# Hasura GraphQL Engine
hasura_engine:
container_name: explorer-graphql
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
restart: unless-stopped
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
jfrank-summit marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -57,37 +63,35 @@ 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:
- "8080:8080"
volumes:
- ./indexers/db/migrations:/hasura-migrations
- ./indexers/db/metadata:/hasura-metadata
- "${HASURA_GRAPHQL_PORT}:8080"
command:
- graphql-engine
- serve

# Gemini 3H Subquery Nodes
gemini_3h_accounts-subquery-node:
profiles: [gemini_3h, gemini_3h_accounts]
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
CHAIN_ID: ${GEMINI_3H_CHAIN_ID}
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_ACCOUNTS}
Expand All @@ -110,14 +114,15 @@ services:
retries: 10

gemini_3h_consensus-subquery-node:
profiles: [gemini_3h, gemini_3h_consensus]
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
CHAIN_ID: ${GEMINI_3H_CHAIN_ID}
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_CONSENSUS}
Expand All @@ -140,14 +145,15 @@ services:
retries: 10

gemini_3h_leaderboard-subquery-node:
profiles: [gemini_3h, gemini_3h_leaderboard]
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
CHAIN_ID: ${GEMINI_3H_CHAIN_ID}
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_LEADERBOARD}
Expand All @@ -170,14 +176,15 @@ services:
retries: 10

gemini_3h_staking-subquery-node:
profiles: [gemini_3h, gemini_3h_staking]
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3H_RPC}
CHAIN_ID: "0x0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34"
CHAIN_ID: ${GEMINI_3H_CHAIN_ID}
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3H_STAKING}
Expand All @@ -200,14 +207,15 @@ services:
retries: 10

gemini_3g_testnet_rewards-subquery-node:
profiles: [gemini_3g, gemini_3g_testnet_rewards]
image: subquerynetwork/subql-node-substrate:latest
depends_on:
"postgres":
condition: service_healthy
restart: unless-stopped
environment:
ENDPOINT: ${GEMINI_3G_RPC}
CHAIN_ID: "0x418040fc282f5e5ddd432c46d05297636f6f75ce68d66499ff4cbda69ccd180b"
CHAIN_ID: ${GEMINI_3G_CHAIN_ID}
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASSWORD}
DB_DATABASE: ${DB_GEMINI_3G_TESTNET_REWARDS}
Expand All @@ -224,7 +232,8 @@ services:
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://staking-subquery-node:3000/ready"]
test:
["CMD", "curl", "-f", "http://testnet-rewards-subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10
8 changes: 6 additions & 2 deletions indexers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
"db"
],
"scripts": {
"dev": "lerna run codegen && lerna run build && docker compose -f ../docker-compose.yml up --remove-orphans",
"prod": "lerna run codegen && lerna run build && docker compose -f ../docker-compose.yml -f ../docker-compose.prod.yml up --remove-orphans -d",
"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
Loading