version: "3.9"

services:
  api:
    image: registry.example.com/podcaster/api:1.18.3
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      APP_ENV: production
      PUBLIC_BASE_URL: https://podcasts.example.com
      DATABASE_URL: postgres://podcast:${POSTGRES_PASSWORD}@postgres:5432/podcast
      REDIS_URL: redis://redis:6379/0
      STORAGE_DRIVER: s3
      S3_ENDPOINT: https://s3.us-east-1.amazonaws.com
      S3_BUCKET: podcast-media-prod
      S3_REGION: us-east-1
      TRANSCODE_QUEUE: audio-jobs
      RSS_CACHE_TTL_SECONDS: "300"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  worker:
    image: registry.example.com/podcaster/worker:1.18.3
    restart: unless-stopped
    command: ["podcaster-worker", "--queue", "audio-jobs"]
    environment:
      DATABASE_URL: postgres://podcast:${POSTGRES_PASSWORD}@postgres:5432/podcast
      REDIS_URL: redis://redis:6379/0
      S3_BUCKET: podcast-media-prod
      MAX_CONCURRENT_TRANSCODES: "4"
      AUDIO_OUTPUT_FORMATS: mp3,aac
    depends_on:
      api:
        condition: service_started

  postgres:
    image: postgres:16
    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
    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: