name: mtusi-lab3 services: postgres: image: postgres:16.10-bookworm environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password command: - postgres - -c - fsync=on - -c - synchronous_commit=on - -c - full_page_writes=on - -c - max_connections=80 - -c - shared_buffers=64MB volumes: - postgres-data:/var/lib/postgresql/data secrets: - postgres_password healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 3s timeout: 3s retries: 20 start_period: 10s cpus: "1.00" mem_limit: 512m restart: unless-stopped networks: - lab redis: image: redis:7.4.2-bookworm command: - redis-server - --appendonly - "yes" - --appendfsync - everysec - --dir - /data - --save - "60" - "1" - --bind - 0.0.0.0 - --protected-mode - "no" volumes: - redis-data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 3s timeout: 3s retries: 20 start_period: 5s cpus: "0.25" mem_limit: 128m restart: unless-stopped networks: - lab migrate: build: . image: mtusi-lab3-api:local command: ["python", "/app/src/migrate.py"] environment: DATABASE_URL_FILE: /run/secrets/database_url secrets: - database_url depends_on: postgres: condition: service_healthy healthcheck: disable: true cpus: "0.50" mem_limit: 256m restart: "no" networks: - lab api: build: . image: mtusi-lab3-api:local environment: APP_HOST: 0.0.0.0 APP_PORT: "8080" APP_ENV: ${APP_ENV:-lab} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} SESSION_STORE: redis IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400} POOL_MAX: ${POOL_MAX:-10} DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url secrets: - database_url - cache_url depends_on: migrate: condition: service_completed_successfully redis: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"] interval: 5s timeout: 3s retries: 8 start_period: 25s init: true stop_grace_period: 10s cpus: "0.50" mem_limit: 256m deploy: replicas: 2 restart: unless-stopped networks: - lab lb: image: haproxy:2.8.14 volumes: - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro ports: - "127.0.0.1:${APP_PORT:-8080}:8080" depends_on: api: condition: service_healthy cpus: "0.25" mem_limit: 128m restart: unless-stopped networks: - lab networks: lab: name: mtusi-lab3-net volumes: postgres-data: redis-data: secrets: database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url postgres_password: file: ./secrets/postgres_password