services:
  bmp:
    build: .
    image: bmp-rewrite:latest
    restart: unless-stopped
    env_file:
      - .env
    environment:
      NODE_ENV: production
      PORT: 3000
      BMP_DATA_DIR: /data
    volumes:
      - bmp_data:/data
    healthcheck:
      test: ["CMD", "bun", "-e", "const r = await fetch('http://127.0.0.1:3000/healthz'); if (!r.ok) process.exit(1);"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s

  caddy:
    image: caddy:2-alpine
    restart: unless-stopped
    depends_on:
      bmp:
        condition: service_healthy
    environment:
      APP_DOMAIN: "${APP_DOMAIN:-:80}"
      MAX_UPLOAD_SIZE: "${MAX_UPLOAD_SIZE:-20MB}"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config

volumes:
  bmp_data:
  caddy_data:
  caddy_config:
