252 lines
6.5 KiB
YAML
252 lines
6.5 KiB
YAML
services:
|
|
load-balancer:
|
|
build:
|
|
context: .
|
|
dockerfile: infrastructure/haproxy/Dockerfile
|
|
image: mtusi2026lab3-load-balancer
|
|
ports:
|
|
- "127.0.0.1:${APP_PORT:-8080}:8080"
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
frontend:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test:
|
|
[
|
|
"CMD-SHELL",
|
|
"wget -qO- http://127.0.0.1:8080/health/ready || exit 1",
|
|
]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 3s
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
frontend:
|
|
build:
|
|
context: .
|
|
dockerfile: infrastructure/nginx/Dockerfile
|
|
image: mtusi2026lab3-web
|
|
expose:
|
|
- "8080"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/ >/dev/null || exit 1"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 3s
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.10"
|
|
memory: 64M
|
|
|
|
postgres:
|
|
image: postgres:16.15-alpine3.24@sha256:721873c34ceb9f8d8fc265984940dc982404c105f19ad51be9fdc5970a6080ea
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test:
|
|
[
|
|
"CMD-SHELL",
|
|
"pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_DB:-messenger}",
|
|
]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "${POSTGRES_CPU_LIMIT:-1.00}"
|
|
memory: ${POSTGRES_MEMORY_LIMIT:-512M}
|
|
|
|
redis:
|
|
image: redis:8.10.2-alpine3.23@sha256:3811787313eba226a2ef38658c6ccb91cd5e110edc89c37767de373120a0e5a0
|
|
command:
|
|
[
|
|
"redis-server",
|
|
"--save",
|
|
"",
|
|
"--appendonly",
|
|
"no",
|
|
"--maxmemory",
|
|
"64mb",
|
|
"--maxmemory-policy",
|
|
"allkeys-lru",
|
|
]
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 3s
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
migrate:
|
|
image: migrate/migrate:v4.20.1@sha256:76cc2074cb6642631f34a898ced71e6aeaa6b1a4d78c4daa743275a22e0c5be7
|
|
entrypoint: ["/bin/sh", "-ec"]
|
|
command:
|
|
- >
|
|
exec migrate
|
|
-path=/migrations
|
|
-database="$$(cat /run/secrets/database_url)"
|
|
up
|
|
secrets:
|
|
- database_url
|
|
volumes:
|
|
- ./migrations:/migrations:ro
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 64M
|
|
|
|
api:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
environment:
|
|
APP_HOST: ${APP_HOST:-0.0.0.0}
|
|
APP_PORT: ${APP_PORT:-8080}
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
SESSION_STORE: ${SESSION_STORE:-postgres}
|
|
SESSION_COOKIE_SECURE: ${SESSION_COOKIE_SECURE:-false}
|
|
CURSOR_SIGNING_KEY_FILE: ${CURSOR_SIGNING_KEY_FILE:-/run/secrets/cursor_signing_key}
|
|
|
|
CACHE_URL: ${CACHE_URL:-redis://redis:6379/0}
|
|
CACHE_TTL: ${CACHE_TTL:-5m}
|
|
CACHE_OPERATION_TIMEOUT: ${CACHE_OPERATION_TIMEOUT:-250ms}
|
|
CACHE_POOL_SIZE: ${CACHE_POOL_SIZE:-10}
|
|
|
|
DATABASE_URL_FILE: ${DATABASE_URL_FILE:-/run/secrets/database_url}
|
|
|
|
DB_MAX_CONNS: ${DB_MAX_CONNS:-10}
|
|
DB_MIN_CONNS: ${DB_MIN_CONNS:-2}
|
|
DB_MAX_CONN_LIFETIME: ${DB_MAX_CONN_LIFETIME:-30m}
|
|
DB_MAX_CONN_IDLE_TIME: ${DB_MAX_CONN_IDLE_TIME:-5m}
|
|
DB_HEALTH_CHECK_PERIOD: ${DB_HEALTH_CHECK_PERIOD:-30s}
|
|
DB_CONNECT_TIMEOUT: ${DB_CONNECT_TIMEOUT:-5s}
|
|
DB_QUERY_TIMEOUT: ${DB_QUERY_TIMEOUT:-3s}
|
|
|
|
READINESS_TIMEOUT: ${READINESS_TIMEOUT:-2s}
|
|
SHUTDOWN_DRAIN_DELAY: ${SHUTDOWN_DRAIN_DELAY:-2s}
|
|
SHUTDOWN_TIMEOUT: ${SHUTDOWN_TIMEOUT:-10s}
|
|
secrets:
|
|
- database_url
|
|
- cursor_signing_key
|
|
expose:
|
|
- "8080"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: "${API_CPU_LIMIT:-0.50}"
|
|
memory: ${API_MEMORY_LIMIT:-256M}
|
|
healthcheck:
|
|
test:
|
|
[
|
|
"CMD-SHELL",
|
|
"wget -qO- http://127.0.0.1:$${APP_PORT:-8080}/health/ready || exit 1",
|
|
]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
stop_grace_period: 15s
|
|
restart: unless-stopped
|
|
|
|
redis-insight:
|
|
image: redis/redisinsight:3.8.0@sha256:b5e19ee240abef6edb435871b90ff8a210995422e8e018ab61c0339d318a1f84
|
|
profiles: ["tools"]
|
|
ports:
|
|
- "127.0.0.1:${REDIS_INSIGHT_PORT:-5540}:5540"
|
|
volumes:
|
|
- redis_insight_data:/data
|
|
depends_on:
|
|
redis:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.50"
|
|
memory: 256M
|
|
|
|
postgres-restore:
|
|
image: postgres:16.15-alpine3.24@sha256:721873c34ceb9f8d8fc265984940dc982404c105f19ad51be9fdc5970a6080ea
|
|
profiles: ["recovery"]
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_DB: ${POSTGRES_RESTORE_DB:-messenger_restore_admin}
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- postgres_restore_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test:
|
|
[
|
|
"CMD-SHELL",
|
|
"pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_RESTORE_DB:-messenger_restore_admin}",
|
|
]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 512M
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_insight_data:
|
|
postgres_restore_data:
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password.txt
|
|
database_url:
|
|
file: ./secrets/database_url.txt
|
|
cursor_signing_key:
|
|
file: ./secrets/cursor_signing_key.txt
|