version: "3.9"

services:
  roaster-controller:
    image: ghcr.io/leafworks/tea-roaster-controller:1.8.2
    restart: unless-stopped
    environment:
      ROASTER_NAME: "small-batch-01"
      BATCH_CAPACITY_KG: "5"
      DEFAULT_PROFILE: "oolong-medium"
      CONTROL_INTERVAL_MS: "500"
      LOG_LEVEL: "info"
      MQTT_BROKER_URL: "mqtt://mqtt:1883"
      DATABASE_URL: "postgresql://roaster:${DB_PASSWORD}@database:5432/roastery"
    devices:
      - "/dev/ttyUSB0:/dev/ttyUSB0"
    volumes:
      - "./profiles:/app/profiles:ro"
      - "./data/logs:/app/logs"
    ports:
      - "8080:8080"
    depends_on:
      database:
        condition: service_healthy
      mqtt:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:8080/health"]
      interval: 15s
      timeout: 3s
      retries: 5
      start_period: 20s

  mqtt:
    image: eclipse-mosquitto:2.0
    restart: unless-stopped
    volumes:
      - "./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro"
      - "mqtt-data:/mosquitto/data"
    ports:
      - "1883:1883"

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

volumes:
  mqtt-data:
  database-data: