forked from mtusi2026/mtusi2026lab3
119 lines
3.6 KiB
YAML
119 lines
3.6 KiB
YAML
name: mtusi2026lab3
|
|
x-api: &api
|
|
image: ${API_IMAGE:-mtusi-messenger:lab3}
|
|
build: .
|
|
restart: unless-stopped
|
|
cpus: ${API_CPUS:-1}
|
|
mem_limit: ${API_MEMORY:-512m}
|
|
environment: &environment
|
|
APP_ENABLED: "true"
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
APP_READ_TIMEOUT: 5s
|
|
APP_WRITE_TIMEOUT: 5s
|
|
APP_IDLE_TIMEOUT: 60s
|
|
APP_SHUTDOWN_TIMEOUT: 8s
|
|
APPLICATION_LOG_LEVEL: ${APPLICATION_LOG_LEVEL:-warn}
|
|
APPLICATION_ENVIRONMENT: prod
|
|
APPLICATION_SHUTDOWN_TIMEOUT: 8s
|
|
POSTGRES_HOST: postgres
|
|
POSTGRES_PORT: 5432
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}
|
|
POSTGRES_DATABASE: messenger
|
|
POSTGRES_VERSION_TABLE: versions
|
|
POSTGRES_RUN_MIGRATIONS: "false"
|
|
POSTGRES_MAX_CONNECTIONS: ${POSTGRES_MAX_CONNECTIONS:-8}
|
|
POSTGRES_CONNECT_TIMEOUT: 500ms
|
|
POSTGRES_QUERY_TIMEOUT: 2s
|
|
REDIS_HOST: redis
|
|
REDIS_PORT: 6379
|
|
REDIS_DB: 0
|
|
REDIS_USERNAME: default
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:?Run scripts/bootstrap.sh}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
JWT_ACCESS_TOKEN_LIFETIME: 15m
|
|
JWT_PRIVATE_KEY_PATH: /run/certs/private_key.pem
|
|
JWT_PUBLIC_KEY_PATH: /run/certs/public_key.pem
|
|
volumes:
|
|
- ./secrets/lab3:/run/certs:ro
|
|
stop_grace_period: 10s
|
|
services:
|
|
api:
|
|
<<: *api
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
migrate:
|
|
<<: *api
|
|
# The migration command uses only PostgreSQL: no signing keys or Redis credentials.
|
|
volumes: []
|
|
environment:
|
|
<<: *environment
|
|
REDIS_PASSWORD: ""
|
|
restart: "no"
|
|
command: [migrate]
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
healthcheck:
|
|
disable: true
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
lb:
|
|
image: ${HAPROXY_IMAGE:-haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0}
|
|
restart: unless-stopped
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
ports:
|
|
- "127.0.0.1:${HOST_PORT:-18080}:8080"
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_started
|
|
healthcheck:
|
|
test: [CMD, wget, -q, -O, /dev/null, http://127.0.0.1:8080/health/ready]
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 5
|
|
stop_grace_period: 10s
|
|
postgres:
|
|
image: postgres:17.11-alpine3.23@sha256:05aa77262db9277fde6374bb2f901c9604b8a9373029e1a7993440c6aae48736
|
|
restart: unless-stopped
|
|
cpus: 2
|
|
mem_limit: 1g
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}
|
|
POSTGRES_DB: messenger
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 30
|
|
stop_grace_period: 30s
|
|
redis:
|
|
image: redis:8.2.11-alpine3.22@sha256:489a769e0a54dc245896132a15c72d2bc7296719954da99398f43a3877e5f8eb
|
|
restart: unless-stopped
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
environment:
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:?Run scripts/bootstrap.sh}
|
|
command: [sh, -c, 'exec docker-entrypoint.sh redis-server --appendonly yes --maxmemory 64mb --maxmemory-policy allkeys-lru --requirepass "$$REDIS_PASSWORD"']
|
|
volumes:
|
|
- redis_data:/data
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'REDISCLI_AUTH="$$REDIS_PASSWORD" redis-cli --no-auth-warning ping | grep -qx PONG']
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 20
|
|
stop_grace_period: 10s
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|