name: leaf-and-ember

x-app-env: &app-env
  APP_ENV: production
  LOG_LEVEL: info
  DATABASE_URL: postgres://tea_roaster:${POSTGRES_PASSWORD}@postgres:5432/roastery
  REDIS_URL: redis://redis:6379/0
  ROAST_BATCH_MAX_KG: "12"
  ROAST_PROFILE_PATH: /app/config/roast-profiles
  INVENTORY_LOW_STOCK_THRESHOLD_KG: "5"

services:
  api:
    image: ghcr.io/leaf-and-ember/roastery-api:1.8.2
    restart: unless-stopped
    environment:
      <<: *app-env
      PORT: "8080"
    ports:
      - "8080:8080"
    volumes:
      - roast_profiles:/app/config/roast-profiles:ro
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started

  roast-scheduler:
    image: ghcr.io/leaf-and-ember/roastery-worker:1.8.2
    restart: unless-stopped
    command: ["node", "workers/roast-scheduler.js"]
    environment:
      <<: *app-env
      SCHEDULE_WINDOW_DAYS: "10"
      DEFAULT_COOLING_MINUTES: "18"
    depends_on:
      api:
        condition: service_started

  label-worker:
    image: ghcr.io/leaf-and-ember/roastery-worker:1.8.2
    restart: unless-stopped
    command: ["node", "workers/print-labels.js"]
    environment:
      <<: *app-env
      LABEL_PRINTER_HOST: label-printer.local
      LABEL_TEMPLATE: retail-125g-v3
    depends_on:
      redis:
        condition: service_started

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

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

volumes:
  postgres_data:
  redis_data:
  roast_profiles: