name: cedar-kettle-roastery

x-app-env: &app-env
  NODE_ENV: production
  LOG_LEVEL: info
  DATABASE_URL: postgres://tea_roaster:${POSTGRES_PASSWORD}@postgres:5432/tea_roaster
  REDIS_URL: redis://redis:6379/0
  ROAST_BATCH_MAX_KG: "18"
  DEFAULT_ORIGIN_TIMEZONE: America/Toronto
  ENABLE_CUPPING_NOTES: "true"

services:
  api:
    image: ghcr.io/cedar-kettle/roastery-api:${APP_VERSION:-latest}
    restart: unless-stopped
    environment:
      <<: *app-env
      PORT: "8080"
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
      interval: 30s
      timeout: 5s
      retries: 3

  roast-worker:
    image: ghcr.io/cedar-kettle/roastery-api:${APP_VERSION:-latest}
    restart: unless-stopped
    command: ["node", "workers/roast-scheduler.js"]
    environment:
      <<: *app-env
      SENSOR_POLL_INTERVAL_SECONDS: "15"
      BATCH_COOLDOWN_MINUTES: "25"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started

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

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - tea-roaster-queue:/data

volumes:
  tea-roaster-db:
  tea-roaster-queue: