forked from mtusi2026/mtusi2026lab3
133 lines
3.0 KiB
YAML
133 lines
3.0 KiB
YAML
x-api-env: &api-env
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
SESSION_STORE: postgres
|
|
SHUTDOWN_TIMEOUT_SECONDS: 10
|
|
DRAIN_SECONDS: 3
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:17-alpine@sha256:b0f9560a2de083e2cc7382e75f808c7381a32852a7ec49117deedb300e552b24
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
POSTGRES_DB: messenger
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- pg_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
networks:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507
|
|
command: ["valkey-server", "--appendonly", "yes", "--save", "60", "1"]
|
|
volumes:
|
|
- valkey_data:/data
|
|
healthcheck:
|
|
test: ["CMD", "valkey-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
networks:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtusi-messenger:lab3
|
|
command: ["migrate"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
networks:
|
|
- backend
|
|
restart: "no"
|
|
|
|
api:
|
|
image: mtusi-messenger:lab3
|
|
environment: *api-env
|
|
secrets:
|
|
- database_url
|
|
- cache_url
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
valkey:
|
|
condition: service_healthy
|
|
stop_grace_period: 15s
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
networks:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
lb:
|
|
image: haproxy:3.0-alpine@sha256:cf3af0facf7eb22b9fee463daf0fbc07ead740b8150696dce724264faf7b4318
|
|
ports:
|
|
- "127.0.0.1:8080:8080"
|
|
volumes:
|
|
- ./lb/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
depends_on:
|
|
- api
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
networks:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
cache_url:
|
|
file: ./secrets/cache_url
|
|
|
|
volumes:
|
|
pg_data:
|
|
valkey_data:
|
|
|
|
networks:
|
|
backend:
|
|
driver: bridge
|