forked from mtusi2026/mtusi2026lab3
63 lines
1.9 KiB
YAML
63 lines
1.9 KiB
YAML
x-api: &api
|
|
build: .
|
|
environment:
|
|
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:-messenger_local_only}@postgres:5432/${POSTGRES_DB:-messenger}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
stop_grace_period: 12s
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2)"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 5
|
|
start_period: 5s
|
|
services:
|
|
postgres:
|
|
image: postgres:16.8-alpine
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger_local_only}
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
migrate:
|
|
build: .
|
|
command: ["python", "migrate.py"]
|
|
environment:
|
|
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:-messenger_local_only}@postgres:5432/${POSTGRES_DB:-messenger}
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
api1:
|
|
<<: *api
|
|
environment:
|
|
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:-messenger_local_only}@postgres:5432/${POSTGRES_DB:-messenger}
|
|
INSTANCE_ID: api1
|
|
api2:
|
|
<<: *api
|
|
environment:
|
|
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:-messenger_local_only}@postgres:5432/${POSTGRES_DB:-messenger}
|
|
INSTANCE_ID: api2
|
|
lb:
|
|
image: nginx:1.27.5-alpine
|
|
ports:
|
|
- "8080:8080"
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
depends_on:
|
|
api1:
|
|
condition: service_healthy
|
|
api2:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
volumes:
|
|
postgres_data:
|