forked from mtusi2026/mtusi2026lab3
Lab 3: solution for grade 3 - BPI2304 Vardanyan
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
services:
|
||||
db:
|
||||
image: postgres:16.8-alpine
|
||||
environment:
|
||||
POSTGRES_DB: lab3
|
||||
POSTGRES_USER: labuser
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U labuser -d lab3"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
restart: unless-stopped
|
||||
|
||||
migrate:
|
||||
image: postgres:16.8-alpine
|
||||
environment:
|
||||
PGHOST: db
|
||||
PGPORT: "5432"
|
||||
PGDATABASE: lab3
|
||||
PGUSER: labuser
|
||||
PGPASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
||||
volumes:
|
||||
- ./db/migrations:/migrations:ro
|
||||
command: ["sh", "-ec", "psql -v ON_ERROR_STOP=1 -f /migrations/001_init.sql"]
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
api1:
|
||||
build: .
|
||||
environment: &api_env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8080"
|
||||
PGHOST: db
|
||||
PGPORT: "5432"
|
||||
PGDATABASE: lab3
|
||||
PGUSER: labuser
|
||||
PGPASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
INSTANCE_ID: api1
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
healthcheck: &api_health
|
||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
restart: unless-stopped
|
||||
stop_grace_period: 5s
|
||||
|
||||
api2:
|
||||
build: .
|
||||
environment:
|
||||
<<: *api_env
|
||||
INSTANCE_ID: api2
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
healthcheck: *api_health
|
||||
restart: unless-stopped
|
||||
stop_grace_period: 5s
|
||||
|
||||
lb:
|
||||
image: nginx:1.28.0-alpine
|
||||
ports:
|
||||
- "127.0.0.1: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:
|
||||
Reference in New Issue
Block a user