name: mtusi-lab3 x-app: &app image: mtusi-messenger:lab3 build: {context: ., target: runtime} environment: &environment APP_HOST: 0.0.0.0 APP_PORT: "8080" APP_ENV: ${APP_ENV:-lab} APP_VERSION: ${APP_VERSION:-lab3-v1} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} SESSION_STORE: redis DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url CURSOR_KEY_FILE: /run/secrets/cursor_key secrets: [database_url, cache_url, cursor_key] networks: [data] cpus: 1.0 mem_limit: 256m stop_grace_period: 8s services: postgres: image: postgres:17.6-bookworm environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [postgres_data:/var/lib/postgresql/data] networks: [data] healthcheck: test: [CMD-SHELL, "pg_isready -U messenger -d messenger"] interval: 2s timeout: 2s retries: 30 cpus: 1.0 mem_limit: 512m stop_grace_period: 10s redis: image: redis:7.4.5-bookworm command: [sh, -ec, 'exec redis-server /usr/local/etc/redis/redis.conf --requirepass "$$(cat /run/secrets/redis_password)"'] secrets: [redis_password] volumes: - redis_data:/data - ./infra/redis.conf:/usr/local/etc/redis/redis.conf:ro networks: [data] healthcheck: test: [CMD-SHELL, 'REDISCLI_AUTH="$$(cat /run/secrets/redis_password)" redis-cli ping | grep -q PONG'] interval: 2s timeout: 2s retries: 30 cpus: 0.5 mem_limit: 192m stop_grace_period: 10s migrate: <<: *app command: [python, -m, app.migrate] depends_on: postgres: {condition: service_healthy} restart: "no" api: <<: *app deploy: replicas: ${API_REPLICAS:-2} depends_on: migrate: {condition: service_completed_successfully} redis: {condition: service_healthy} networks: [edge, data] lb: image: haproxy:3.0.12-alpine volumes: - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro ports: - "127.0.0.1:${API_PORT:-8080}:8080" networks: [edge] depends_on: api: {condition: service_healthy} cpus: 0.5 mem_limit: 128m stop_grace_period: 8s healthcheck: test: [CMD, wget, -q, -O, /dev/null, "http://127.0.0.1:8080/health/ready"] interval: 2s timeout: 2s retries: 30 checks: profiles: [tools] image: mtusi-messenger:lab3-checks build: {context: ., target: checks} environment: <<: *environment BASE_URL: http://lb:8080 COMPOSE_PROJECT_NAME: ${COMPOSE_PROJECT_NAME:-mtusi-lab3} secrets: [database_url, cache_url, cursor_key] volumes: - .:/checks - /var/run/docker.sock:/var/run/docker.sock networks: [edge, data] cpus: 1.0 mem_limit: 256m networks: edge: data: internal: true volumes: postgres_data: redis_data: secrets: postgres_password: {file: ./secrets/postgres_password} redis_password: {file: ./secrets/redis_password} database_url: {file: ./secrets/database_url} cache_url: {file: ./secrets/cache_url} cursor_key: {file: ./secrets/cursor_key}