version: '3.9'

services:
  app:
    build: .
    container_name: inventario-farmacia-app
    environment:
      DATABASE_URL: ${DATABASE_URL:-file:/app/data/prod.db}
      ADMIN_PASSWORD: ${ADMIN_PASSWORD}
      SESSION_SECRET: ${SESSION_SECRET}
      NODE_ENV: production
      NEXT_TELEMETRY_DISABLED: 1
    volumes:
      - inventario_data:/app/data
    restart: unless-stopped
    healthcheck:
      test: ['CMD', 'wget', '-qO-', 'http://127.0.0.1:3000/api/health']
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s

  caddy:
    image: caddy:2.9-alpine
    container_name: inventario-farmacia-caddy
    depends_on:
      app:
        condition: service_healthy
    ports:
      - '80:80'
      - '443:443'
    environment:
      DOMAIN: ${DOMAIN}
      LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
    volumes:
      - ./deploy/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    restart: unless-stopped

volumes:
  inventario_data:
  caddy_data:
  caddy_config:
