version: "3.9"

services:
  api:
    image: ghcr.io/acme-podcasts/platform-api:2.8.1
    restart: unless-stopped
    environment:
      APP_ENV: production
      PORT: "8080"
      DATABASE_URL: postgresql://podcast:${POSTGRES_PASSWORD}@postgres:5432/podcast
      REDIS_URL: redis://redis:6379/0
      STORAGE_ENDPOINT: https://s3.amazonaws.com
      STORAGE_BUCKET: ${STORAGE_BUCKET}
      STORAGE_REGION: us-east-1
      STORAGE_ACCESS_KEY_ID: ${STORAGE_ACCESS_KEY_ID}
      STORAGE_SECRET_ACCESS_KEY: ${STORAGE_SECRET_ACCESS_KEY}
      PUBLIC_BASE_URL: https://podcasts.example.com
      CDN_BASE_URL: https://media.example.com
      RSS_CACHE_TTL_SECONDS: "300"
      MAX_UPLOAD_SIZE_MB: "1024"
      TRANSCODING_QUEUE: podcast-transcoding
      LOG_LEVEL: info
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s
    networks:
      - backend

  worker:
    image: ghcr.io/acme-podcasts/platform-worker:2.8.1
    restart: unless-stopped
    command: ["./podcast-worker", "--concurrency=4"]
    environment:
      APP_ENV: production
      DATABASE_URL: postgresql://podcast:${POSTGRES_PASSWORD}@postgres:5432/podcast
      REDIS_URL: redis://redis:6379/0
      STORAGE_BUCKET: ${STORAGE_BUCKET}
      STORAGE_REGION: us-east-1
      STORAGE_ACCESS_KEY_ID: ${STORAGE_ACCESS_KEY_ID}
      STORAGE_SECRET_ACCESS_KEY: ${STORAGE_SECRET_ACCESS_KEY}
      FFMPEG_PRESET: medium
      NORMALIZE_AUDIO: "true"
      TARGET_LOUDNESS_LUFS: "-16"
      LOG_LEVEL: info
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - backend

  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: podcast
      POSTGRES_USER: podcast
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U podcast -d podcast"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - backend

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes", "--maxmemory", "512mb", "--maxmemory-policy", "allkeys-lru"]
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5
    networks:
      - backend

volumes:
  postgres_data:
  redis_data:

networks:
  backend:
    driver: bridge