version: "3.9"

services:
  api:
    image: ghcr.io/acme/podcast-platform-api:2.8.1
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      APP_ENV: production
      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
      CDN_BASE_URL: https://media.example.com
      RSS_BASE_URL: https://feeds.example.com
      MAX_UPLOAD_SIZE_MB: "500"
      TRANSCODE_QUEUE: podcast-transcoding
      LOG_LEVEL: info
    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

  worker:
    image: ghcr.io/acme/podcast-platform-worker:2.8.1
    restart: unless-stopped
    command: ["./podcast-worker", "--concurrency", "4"]
    environment:
      DATABASE_URL: postgresql://podcast:${POSTGRES_PASSWORD}@postgres:5432/podcast
      REDIS_URL: redis://redis:6379/0
      STORAGE_BUCKET: ${STORAGE_BUCKET}
      STORAGE_REGION: us-east-1
      FFMPEG_PRESET: medium
      OUTPUT_FORMATS: mp3,aac
      NORMALIZE_LOUDNESS: "true"
      TARGET_LUFS: "-16"
      LOG_LEVEL: info
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  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

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

volumes:
  postgres-data:
  redis-data: