##
# BuildGrid Compose manifest for BuildStream.
#
# Spins-up a unnamed and unauthenticated grid:
#  - Controller + CAS + AC at http://localhost:50051
#
# BuildStream configuration snippet:
#
#    remote-execution:
#      execution-service:
#        url: http://localhost:50051
#      action-cache-service:
#        url: http://localhost:50051
#      storage-service:
#        url: http://localhost:50051
#
# Basic usage:
#  - docker-compose -f ci.buildgrid.yml up
#  - docker-compose -f ci.buildgrid.yml down
#
version: "3.2"

services:
  database:
    image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildgrid-postgres:nightly
    environment:
      POSTGRES_USER: bgd
      POSTGRES_PASSWORD: insecure
      POSTGRES_DB: bgd
    volumes:
      - type: volume
        source: db
        target: /var/lib/postgresql
    networks:
      - grid
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "bgd"]
      interval: 1s
      timeout: 5s
      retries: 10

  controller:
    image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildgrid:nightly
    command: [
      "bgd", "server", "start", "-v",
      "/etc/buildgrid/default.yml"]
    ports:
      - 50051:50051
    networks:
      - grid
    depends_on:
      database:
        condition: service_healthy

  bot:
    image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildbox:nightly
    command: [
      "sh", "-c", "sleep 15 && ( buildbox-casd --cas-remote=http://controller:50051 /var/lib/buildgrid/cache & buildbox-worker --request-timeout=30 --bots-remote=http://controller:50051 --cas-remote=unix:/var/lib/buildgrid/cache/casd.sock --buildbox-run=buildbox-run-bubblewrap --platform OSFamily=linux --platform ISA=x86-64 --verbose )"]
    privileged: true
    volumes:
      - type: volume
        source: cache
        target: /var/lib/buildgrid/cache
    depends_on:
      - controller
    networks:
      - grid

networks:
  grid:
    driver: bridge

volumes:
  cache:
  db:
