# Runnable lab2 stand: API + PostgreSQL + Redis (sessions with AOF). x-lab-number: 2 services: postgres: image: postgres:16.4-bookworm environment: POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password POSTGRES_DB: messenger ports: - "127.0.0.1:15432:5432" secrets: - postgres_password volumes: - pg_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 5s timeout: 3s retries: 10 restart: unless-stopped redis: image: redis:7.4.1-bookworm command: - redis-server - --appendonly - "yes" - --appendfsync - everysec - --dir - /data ports: - "127.0.0.1:6379:6379" volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 10 restart: unless-stopped api: build: context: . dockerfile: Dockerfile 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 DB_CONNECT_TIMEOUT: "5" DB_POOL_MIN: "1" DB_POOL_MAX: "10" REDIS_SOCKET_TIMEOUT: "3" 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 start_period: 20s retries: 10 restart: unless-stopped volumes: pg_data: redis_data: secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url