# Production-mode compose for DevOps Dashboard
# Usage:
#   docker compose up --build
#
# Requires:
#   - backend/.env populated (copy from backend/.env.example)
#   - web/.env.local populated (copy from web/.env.local.example)
#
# For hot-reload dev mode use:
#   docker compose -f docker-compose.yml -f docker-compose.dev.yml up

services:
  # ---------------------------------------------------------------------------
  # Backend — DevOps API service
  # ---------------------------------------------------------------------------
  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
      args:
        BYTELYST_PACKAGE_SOURCE: ${BYTELYST_PACKAGE_SOURCE:-vendor}
    container_name: devops-backend
    env_file:
      - backend/.env
    environment:
      - VM_SCRIPTS_PATH=/vm-scripts/VMs/HostingerVM
      - VM_LOG_DIR=/host-logs
      - HERMES_DASHBOARD_ALERT_LOG=/var/log/hermes-dashboard-warnings.log
    ports:
      - '127.0.0.1:4004:4004'
    networks:
      - default
      - platform_net
    volumes:
      # Read-only access to VM management scripts
      - /opt/bytelyst/learning_ai_devops_tools/scripts:/vm-scripts:ro
      # Read-write access to VM log files (cleanup + health-check write here)
      - /var/log/vm-cleanup.log:/host-logs/vm-cleanup.log
      - /var/log/vm-health-check.log:/host-logs/vm-health-check.log
      - /var/log/docker-watchdog.log:/host-logs/docker-watchdog.log
      - /var/log/hermes-dashboard-warnings.log:/var/log/hermes-dashboard-warnings.log
      # Docker socket — allows running docker commands against the host daemon
      # (same pattern as Portainer/cAdvisor; container already runs as root)
      - /var/run/docker.sock:/var/run/docker.sock
    extra_hosts:
      # Reach the host for Ollama API (port 11434) and host-only services
      - "host-gateway:host-gateway"
    restart: unless-stopped
    deploy:
      resources:
        limits:
          memory: 512m
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:4004/health']
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 15s

  # ---------------------------------------------------------------------------
  # Web — Next.js dashboard
  # ---------------------------------------------------------------------------
  web:
    build:
      context: .
      dockerfile: web/Dockerfile
      args:
        BYTELYST_PACKAGE_SOURCE: ${BYTELYST_PACKAGE_SOURCE:-vendor}
        NEXT_PUBLIC_PRODUCT_ID: ${NEXT_PUBLIC_PRODUCT_ID:-devops}
        NEXT_PUBLIC_PLATFORM_URL: https://api.bytelyst.com/platform/api
        NEXT_PUBLIC_DEVOPS_API_URL: ${NEXT_PUBLIC_DEVOPS_API_URL-}
    container_name: devops-web
    ports:
      - '127.0.0.1:3049:3000'
    networks:
      - default
      - platform_net
    restart: unless-stopped
    deploy:
      resources:
        limits:
          memory: 512m
    depends_on:
      backend:
        condition: service_healthy
    environment:
      - NODE_ENV=production

networks:
  default: {}
  platform_net:
    external: true
    name: learning_ai_common_plat_default
