x-app: &app image: mtusi-messenger:${COMPOSE_PROJECT_NAME} build: . environment: &app-environment DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url CURSOR_SECRET_FILE: /run/secrets/cursor_secret SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} WEB_CONCURRENCY: ${WEB_CONCURRENCY:-4} LOG_LEVEL: ${LOG_LEVEL:-INFO} secrets: [database_url, cache_url, cursor_secret] networks: [backend] x-ready: &ready test: ["CMD", "python", "-c", "import urllib.request,sys;sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2).status==200 else 1)"] interval: 3s timeout: 3s retries: 5 start_period: 15s start_interval: 200ms services: postgres: image: postgres:17.11-alpine@sha256:266d3c257594e195b309ae9d1805e54c788f1d7b375f56bf6c367aac6c917e7b user: "70:70" environment: POSTGRES_DB: messenger POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [pgdata:/var/lib/postgresql/data] shm_size: 256m healthcheck: test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "messenger", "-d", "messenger"] interval: 2s timeout: 3s retries: 30 start_period: 10s start_interval: 200ms stop_grace_period: 10s restart: unless-stopped networks: [backend] valkey: image: valkey/valkey:8.1.11-alpine@sha256:2602ace2be6569bc2bbb06f873776516ab9089821525be34f4305c67eb9db02a user: "999:1000" command: - valkey-server - /run/secrets/valkey.conf - --appendonly - "yes" - --appendfsync - always - --maxmemory - 64mb - --maxmemory-policy - volatile-lru secrets: [valkey.conf] volumes: [valkeydata:/data] healthcheck: test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(sed -n 's/^requirepass //p' /run/secrets/valkey.conf)\" valkey-cli ping | grep -q PONG"] interval: 2s timeout: 3s retries: 30 stop_grace_period: 10s restart: unless-stopped networks: [backend] postgres-restore: image: postgres:17.11-alpine@sha256:266d3c257594e195b309ae9d1805e54c788f1d7b375f56bf6c367aac6c917e7b profiles: [track] user: "70:70" environment: POSTGRES_DB: track POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: - pgrestore:/var/lib/postgresql/data - ./backups:/backups:ro shm_size: 256m healthcheck: test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "messenger", "-d", "track"] interval: 2s timeout: 3s retries: 30 start_period: 10s start_interval: 200ms stop_grace_period: 10s networks: [backend] migrate: <<: *app command: ["python", "-m", "messenger.migrate"] healthcheck: disable: true restart: "no" depends_on: postgres: condition: service_healthy api: <<: *app ports: ["127.0.0.1:${API_PORT:-8080}:8080"] healthcheck: *ready stop_grace_period: 10s restart: unless-stopped depends_on: migrate: condition: service_completed_successfully valkey: condition: service_started api-shortttl: <<: *app profiles: [faults] environment: <<: *app-environment SESSION_TTL_SECONDS: "2" WEB_CONCURRENCY: "1" ports: ["127.0.0.1:${SHORTTTL_PORT:-8082}:8080"] healthcheck: *ready stop_grace_period: 10s restart: unless-stopped depends_on: migrate: condition: service_completed_successfully valkey: condition: service_started secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url valkey.conf: file: ./secrets/valkey.conf cache_url: file: ./secrets/cache_url cursor_secret: file: ./secrets/cursor_secret volumes: pgdata: valkeydata: pgrestore: networks: backend: