version: "3.9"

services:
  api:
    image: ghcr.io/acme/podcast-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: ${AWS_REGION:-us-east-1}
      CDN_BASE_URL: ${CDN_BASE_URL}
      RSS_BASE_URL: ${PUBLIC_BASE_URL}/feeds
      JWT_SECRET: ${JWT_SECRET}
      AUDIO_MAX_UPLOAD_MB: "500"
      TRANSCODING_QUEUE: audio-transcoding
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:8080/health"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 30s

  worker:
    image: ghcr.io/acme/podcast-platform-worker:2.8.1
    restart: unless-stopped
    command: ["worker", "--queue", "audio-transcoding", "--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: ${AWS_REGION:-us-east-1}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      FFMPEG_PRESETS: "mp3-128k,aac-96k"
    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", "--maxmemory", "512mb", "--maxmemory-policy", "allkeys-lru"]
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

volumes:
  postgres_data:
  redis_data: