Files
mtusi2026lab4/compose.yaml
T
2026-10-31 20:10:31 +03:00

155 lines
3.7 KiB
YAML

name: mtusi2026lab
x-api-build: &api-build
image: mtusi2026lab-api:local
build:
context: .
dockerfile: Dockerfile
x-api-environment: &api-environment
APP_HOST: 0.0.0.0
APP_PORT: "8080"
DB_POOL_MAX_CONNS: ${DB_POOL_MAX_CONNS:-10}
DATABASE_URL: postgres://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-messenger}?sslmode=disable
CACHE_URL: redis://redis:6379/0
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
services:
postgres:
image: postgres:16.10-alpine
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-messenger}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:-messenger}
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 3s
timeout: 3s
retries: 20
start_period: 5s
deploy:
resources:
limits:
cpus: "${POSTGRES_CPU_LIMIT:-1.0}"
memory: "${POSTGRES_MEM_LIMIT:-512M}"
redis:
image: redis:7.4.7-alpine
restart: unless-stopped
command:
[
"redis-server",
"--appendonly",
"yes",
"--appendfsync",
"everysec",
"--save",
"",
]
volumes:
- redisdata:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 3s
timeout: 3s
retries: 20
start_period: 3s
deploy:
resources:
limits:
cpus: "${REDIS_CPU_LIMIT:-0.50}"
memory: "${REDIS_MEM_LIMIT:-256M}"
migrate:
<<: *api-build
restart: "no"
depends_on:
postgres:
condition: service_healthy
environment:
<<: *api-environment
MIGRATE_ONLY: "true"
api:
<<: *api-build
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
environment:
<<: *api-environment
RUN_MIGRATIONS: "false"
expose:
- "8080"
healthcheck:
test:
["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:8080/health/ready"]
interval: 2s
timeout: 2s
retries: 10
start_period: 10s
stop_grace_period: 15s
deploy:
replicas: ${API_REPLICAS:-2}
resources:
limits:
cpus: "${API_CPU_LIMIT:-0.50}"
memory: "${API_MEM_LIMIT:-256M}"
haproxy:
image: haproxy:3.2.6-alpine
restart: unless-stopped
depends_on:
api:
condition: service_healthy
ports:
- "${LB_PORT:-8080}:8080"
- "${HAPROXY_STATS_PORT:-8404}:8404"
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
healthcheck:
test:
["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/stats"]
interval: 2s
timeout: 2s
retries: 10
start_period: 5s
deploy:
resources:
limits:
cpus: "${HAPROXY_CPU_LIMIT:-0.50}"
memory: "${HAPROXY_MEM_LIMIT:-128M}"
k6:
image: grafana/k6:1.3.0
profiles: ["load"]
depends_on:
haproxy:
condition: service_healthy
user: "0:0"
environment:
BASE_URL: http://haproxy:8080
VUS: ${K6_VUS:-10}
DURATION: ${K6_DURATION:-60s}
volumes:
- ./load:/scripts:ro
- ./evidence:/results
command: ["run", "/scripts/messages.js"]
deploy:
resources:
limits:
cpus: "${K6_CPU_LIMIT:-1.0}"
memory: "${K6_MEM_LIMIT:-512M}"
volumes:
pgdata:
redisdata: