# Provisioning Platform Services
# Docker Compose configuration for running all platform services

services:
  # Orchestrator - Core workflow coordination
  orchestrator:
    build:
      context: ../../crates/orchestrator
      dockerfile: Dockerfile
    container_name: provisioning-orchestrator
    ports:
      - "8080:8080"
    volumes:
      - orchestrator-data:/data
      - orchestrator-logs:/var/log/orchestrator
      - /var/run/docker.sock:/var/run/docker.sock  # For test environment service
    environment:
      - RUST_LOG=info
      - DATA_DIR=/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s
    restart: unless-stopped
    networks:
      - provisioning-net

  # Control Center - Web UI
  control-center:
    build:
      context: ../../crates/control-center
      dockerfile: Dockerfile
    container_name: provisioning-control-center
    command: ["control-center", "--config", "/etc/provisioning/config.defaults.toml"]
    ports:
      - "8081:8081"
    volumes:
      - control-center-data:/data
    environment:
      - ORCHESTRATOR_URL=http://orchestrator:8080
      - RUST_LOG=info
    depends_on:
      orchestrator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8081/health"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s
    restart: unless-stopped
    networks:
      - provisioning-net

  # CoreDNS - Local DNS resolution
  coredns:
    image: coredns/coredns:1.11.1
    container_name: provisioning-coredns
    ports:
      - "5353:53/udp"
      - "5353:53/tcp"
    volumes:
      - ../../config/coredns/Corefile:/Corefile:ro
      - ../../config/coredns/zones:/zones:ro
    command: ["-conf", "/Corefile"]
    # Health check disabled - minimal image has no networking tools
    restart: unless-stopped
    networks:
      - provisioning-net

  # Gitea - Git server
  gitea:
    image: gitea/gitea:1.21
    container_name: provisioning-gitea
    ports:
      - "3000:3000"
      - "222:22"
    volumes:
      - gitea-data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=sqlite3
      - GITEA__server__DOMAIN=localhost
      - GITEA__server__HTTP_PORT=3000
      - GITEA__server__ROOT_URL=http://localhost:3000/
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/api/healthz"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 30s
    restart: unless-stopped
    networks:
      - provisioning-net

  # OCI Registry - Container registry (Zot)
  oci-registry:
    image: ghcr.io/project-zot/zot:latest
    container_name: provisioning-oci-registry
    ports:
      - "5000:5000"
    volumes:
      - oci-registry-data:/var/lib/registry
      - ../oci-registry/config.json:/etc/zot/config.json:ro
    environment:
      - ZOT_LOG_LEVEL=info
    # Health check disabled - minimal image has no networking tools
    restart: unless-stopped
    networks:
      - provisioning-net

  # MCP Server - Model Context Protocol
  mcp-server:
    build:
      context: ../../crates/mcp-server
      dockerfile: Dockerfile
    container_name: provisioning-mcp-server
    ports:
      - "8082:8082"
    volumes:
      - mcp-server-data:/data
    environment:
      - ORCHESTRATOR_URL=http://orchestrator:8080
    depends_on:
      orchestrator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8082/health"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s
    restart: unless-stopped
    networks:
      - provisioning-net

  # API Gateway - Unified REST API
  api-gateway:
    build:
      context: ../api-gateway
      dockerfile: Dockerfile
    container_name: provisioning-api-gateway
    ports:
      - "8083:8083"
    environment:
      - ORCHESTRATOR_URL=http://orchestrator:8080
      - CONTROL_CENTER_URL=http://control-center:8081
      - MCP_SERVER_URL=http://mcp-server:8082
    depends_on:
      orchestrator:
        condition: service_healthy
      control-center:
        condition: service_healthy
      mcp-server:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8083/health"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s
    restart: unless-stopped
    networks:
      - provisioning-net

volumes:
  orchestrator-data:
    driver: local
  orchestrator-logs:
    driver: local
  control-center-data:
    driver: local
  gitea-data:
    driver: local
  oci-registry-data:
    driver: local
  mcp-server-data:
    driver: local

networks:
  provisioning-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/16
