name: legate-dev

services:
  postgres:
    image: postgres:17-alpine
    environment:
      POSTGRES_USER: legate
      POSTGRES_PASSWORD: ${LEGATE_DATABASE_PASSWORD:-legate-dev-only}
      POSTGRES_DB: legate
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U legate -d legate"]
      interval: 2s
      timeout: 3s
      retries: 30
    volumes:
      - postgres-data:/var/lib/postgresql/data

  redis:
    image: redis:8-alpine
    command: ["redis-server", "--appendonly", "yes"]
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 2s
      timeout: 3s
      retries: 30
    volumes:
      - redis-data:/data

  central:
    image: ghcr.io/bit-fortress/legate:${LEGATE_VERSION:-edge}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    command:
      - --listen=:8080
      - --database-dsn=postgres://legate:${LEGATE_DATABASE_PASSWORD:-legate-dev-only}@postgres:5432/legate?sslmode=disable
      - --redis-addr=redis:6379
      - --redis-prefix=legate-dev
      - --admin-auth-mode=disabled
      - --instance-id=legate-dev-central
    healthcheck:
      test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/api/healthz"]
      interval: 3s
      timeout: 5s
      retries: 40
    ports:
      - "127.0.0.1:${LEGATE_GATEWAY_PORT:-8081}:8080"
    volumes:
      - central-telemetry-state:/var/lib/legate/telemetry

  console:
    image: ghcr.io/bit-fortress/legate-console:${LEGATE_CONSOLE_VERSION:-edge}
    depends_on:
      central:
        condition: service_healthy
    environment:
      API_UPSTREAM: http://central:8080
    ports:
      - "127.0.0.1:${LEGATE_CONSOLE_PORT:-8080}:80"

  sidecar:
    profiles: ["sidecar"]
    image: ghcr.io/bit-fortress/legate-sidecar:${LEGATE_VERSION:-edge}
    depends_on:
      central:
        condition: service_healthy
      redis:
        condition: service_healthy
    command:
      - --listen=:8081
      - --control-plane=http://central:8080
      - --central-gateway=http://central:8080
      - --telemetry-base-url=http://central:8080
      - --workspace=${LEGATE_SIDECAR_WORKSPACE:-default}
      - --token=${LEGATE_SIDECAR_TOKEN:-}
      - --instance-id=${LEGATE_SIDECAR_INSTANCE_ID:-local-sidecar-1}
      - --sync-interval=10s
      - --redis-addr=redis:6379
      - --redis-prefix=legate-dev
    ports:
      - "127.0.0.1:${LEGATE_SIDECAR_PORT:-8082}:8081"
    volumes:
      - sidecar-telemetry-state:/var/lib/legate-sidecar/telemetry

volumes:
  postgres-data:
  redis-data:
  central-telemetry-state:
  sidecar-telemetry-state:
