postgres migrate

This commit is contained in:
Ravi Prasad
2025-06-18 19:52:47 -05:00
parent d8e6cdfccf
commit 0aac099136
4 changed files with 123 additions and 66 deletions
+48 -28
View File
@@ -1,56 +1,74 @@
version: '3.8'
services:
db-init:
build:
context: .
dockerfile: Dockerfile
# NEW: Add a dedicated PostgreSQL database service
postgres:
image: postgres:15-alpine
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
ports:
- '${DB_PORT}:5432' # Expose DB port to host machine for local tools
volumes:
- './data:/app/data'
# now invoke your new subcommand
command: ["/nba_go", "import-data"]
restart: "no" # so it doesnt keep trying forever
healthcheck: # optional: mark healthy when the DB file exists
test: ["CMD", "test", "-f", "/app/data/nba.db"]
- postgres_data:/var/lib/postgresql/data # Persist data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
interval: 10s
timeout: 5s
retries: 3
retries: 5
networks:
- api.network
api1:
env_file: .env
volumes:
- './data:/app/data'
# MODIFIED: This service now runs migrations and imports against the live Postgres DB
db-init:
build: .
ports:
- '5001:5000'
restart: always
env_file: .env
command: ["/nba_go", "import-data"]
depends_on:
db-init:
postgres:
condition: service_healthy
networks:
- api.network
restart: "no"
# MODIFIED: All API services now depend on postgres being healthy.
# The volume mount for './data' is no longer needed.
api1:
build: .
env_file: .env
ports:
- '5001:5000'
depends_on:
postgres:
condition: service_healthy
networks:
- api.network
restart: always
api2:
env_file: .env
volumes:
- './data:/app/data'
build: .
env_file: .env
ports:
- '5002:5000'
depends_on:
postgres:
condition: service_healthy
networks:
- api.network
restart: always
api3:
env_file: .env
volumes:
- './data:/app/data'
build: .
env_file: .env
ports:
- '5003:5000'
depends_on:
postgres:
condition: service_healthy
networks:
- api.network
restart: always
nginx:
image: 'nginx:stable'
@@ -97,7 +115,9 @@ services:
restart: unless-stopped
volumes:
prometheus_data: null
grafana_data: null
postgres_data: # New volume for Postgres
prometheus_data:
grafana_data:
networks:
api.network: null
api.network: null