services:
  gpu-monitor:
    build: .
    privileged: true  # 하드웨어 센서 접근을 위해 필요
    devices:
      - /dev/i2c-0:/dev/i2c-0
      - /dev/i2c-1:/dev/i2c-1
    volumes:
      - .:/app
      - ./logs:/app/logs
      - /sys/class/hwmon:/sys/class/hwmon:ro  # 하드웨어 센서 접근
      - /sys/class/thermal:/sys/class/thermal:ro  # 열 센서 접근
      - /sys/class/drm:/sys/class/drm:ro  # GPU 정보 접근
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - SLACK_WEBHOOK_URL=${SLACK_WEBHOOK_URL}
      - DATABASE_URL=${DATABASE_URL}
      - INFLUXDB_URL=http://influxdb:8086
      - INFLUXDB_TOKEN=${INFLUXDB_TOKEN}
      - INFLUXDB_ORG=${INFLUXDB_ORG}
      - INFLUXDB_BUCKET=${INFLUXDB_BUCKET}
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    ports:
      - "8002:8002"  # GPU 모니터링 서비스
      - "8004:8004"  # API 서비스
    depends_on:
      - influxdb
    restart: unless-stopped

  influxdb:
    image: influxdb:2.7
    ports:
      - "8086:8086"
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=${INFLUXDB_USER}
      - DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUXDB_PASSWORD}
      - DOCKER_INFLUXDB_INIT_ORG=${INFLUXDB_ORG}
      - DOCKER_INFLUXDB_INIT_BUCKET=${INFLUXDB_BUCKET}
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDB_TOKEN}
    volumes:
      - influxdb-data:/var/lib/influxdb2
    restart: unless-stopped

  grafana:
    image: grafana/grafana:10.0.0
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER:-admin}
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin}
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_SERVER_HTTP_PORT=3000
      - GF_SERVER_DOMAIN=localhost
      - GF_SERVER_ROOT_URL=http://localhost:3000
      - GF_SERVER_ENFORCE_DOMAIN=false
    volumes:
      - grafana-data:/var/lib/grafana
      - ./grafana/provisioning:/etc/grafana/provisioning
    depends_on:
      - influxdb
    restart: unless-stopped

volumes:
  influxdb-data:
  grafana-data: 