Files
mtusi2026lab3-fork/compose.yaml
T

128 lines
2.7 KiB
YAML

name: mtusi-messenger-lab3
services:
postgres:
image: postgres:16.4-alpine
restart: unless-stopped
environment:
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
POSTGRES_DB: messenger
secrets:
- postgres_password
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s
networks:
- internal
redis:
image: redis:7.4-alpine
restart: unless-stopped
command:
- redis-server
- --appendonly
- "yes"
- --appendfsync
- everysec
- --save
- "60 1000"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s
networks:
- internal
migrate:
build:
context: .
dockerfile: Dockerfile
image: mtusi-messenger-api:lab3
restart: "no"
command: ["migrate"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets:
- database_url
depends_on:
postgres:
condition: service_healthy
networks:
- internal
api:
build:
context: .
dockerfile: Dockerfile
image: mtusi-messenger-api:lab3
restart: unless-stopped
environment:
APP_HOST: "0.0.0.0"
APP_PORT: "8080"
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
SESSION_STORE: "redis"
SESSION_TTL_SECONDS: "3600"
IDEMPOTENCY_TTL_SECONDS: "86400"
secrets:
- database_url
- cache_url
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
expose:
- "8080"
stop_grace_period: 15s
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:8080/health/ready >/dev/null || exit 1"]
interval: 5s
timeout: 3s
retries: 5
start_period: 10s
deploy:
replicas: 2
networks:
- internal
lb:
image: nginx:1.27.4-alpine
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api:
condition: service_started
networks:
- internal
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
cache_url:
file: ./secrets/cache_url
volumes:
postgres_data:
redis_data:
networks:
internal:
driver: bridge