# Runnable lab2 stack: API + PostgreSQL + Redis (sessions, AOF). services: postgres: image: postgres:16.6-bookworm environment: POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password POSTGRES_DB: messenger secrets: - postgres_password ports: # Local-only for IDE clients (PyCharm Database tool); not for remote exposure. - "127.0.0.1:5432:5432" volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 5s timeout: 3s retries: 10 start_period: 10s networks: - labnet redis: image: redis:7.4.2-bookworm command: - redis-server - --appendonly - "yes" - --appendfsync - everysec - --dir - /data volumes: - redisdata:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 10 start_period: 5s networks: - labnet api: build: context: . dockerfile: Dockerfile image: mtusi-messenger:lab2 ports: - "127.0.0.1:8080:8080" environment: APP_HOST: "0.0.0.0" APP_PORT: "8080" APP_ENV: lab SESSION_TTL_SECONDS: "${SESSION_TTL_SECONDS:-3600}" SESSION_STORE: redis DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url MIGRATIONS_DIR: /app/migrations secrets: - database_url - cache_url depends_on: postgres: condition: service_healthy 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: 12 start_period: 20s networks: - labnet secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url volumes: pgdata: redisdata: networks: labnet: driver: bridge