services:
  postgres:
    image: ${POSTGRES_IMAGE:-docker.1ms.run/library/postgres:16}
    container_name: maas-base-db
    restart: unless-stopped
    environment:
      POSTGRES_USER: gpustack
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-gpustack}
      POSTGRES_DB: gpustack
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U gpustack"]
      interval: 5s
      timeout: 5s
      retries: 5

  maas-base-server:
    build:
      context: ..
      dockerfile: pack/Dockerfile
    container_name: maas-base-server
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      GPUSTACK_DATABASE_URL: postgresql://gpustack:${POSTGRES_PASSWORD:-gpustack}@postgres:5432/gpustack
      GPUSTACK_DISABLE_BUILTIN_OBSERVABILITY: "true"
      GPUSTACK_GRAFANA_URL: ${GPUSTACK_GRAFANA_URL:-http://localhost:3000}
    volumes:
      - maas-base-data:/var/lib/gpustack
    ports:
      - "80:80"
      - "10161:10161"

  prometheus:
    image: ${PROMETHEUS_IMAGE:-docker.1ms.run/prom/prometheus:latest}
    container_name: maas-base-prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--web.enable-remote-write-receiver'
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prom_data:/prometheus

  grafana:
    image: ${GRAFANA_IMAGE:-docker.1ms.run/grafana/grafana:latest}
    container_name: maas-base-grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      GF_SERVER_HTTP_PORT: "3000"
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-grafana}
      GF_FEATURE_TOGGLES_ENABLE: flameGraph traceqlSearch traceQLStreaming correlations metricsSummary traceqlEditor traceToMetrics traceToProfiles
    volumes:
      - ./grafana/grafana_provisioning:/etc/grafana/provisioning:ro
      - ./grafana/grafana_dashboards:/etc/dashboards:ro

volumes:
  postgres-data: {}
  prom_data: {}
  maas-base-data: {}
