services:
  buildbot-master:
    image: 'buildbot/buildbot-master:${BUILDBOT_IMAGE_TAG:-v4.1.0}'
    hostname: buildbot-master
    restart: unless-stopped
    ports:
      - 8010:8010
    environment:
      - 'BUILDBOT_CONFIG_DIR=${BUILDBOT_CONFIG_DIR:-config}'
      # - 'BUILDBOT_CONFIG_URL=${BUILDBOT_CONFIG_URL:-https://git.braak.pro/api/packages/bartvdbraak/generic/builder.braak.pro/main/config.tar.gz}'
      - 'BUILDBOT_WORKER_PORT=${BUILDBOT_WORKER_PORT:-9989}'
      - 'BUILDBOT_WEB_URL=${BUILDBOT_WEB_URL:-http://localhost:8010/}'
      - 'BUILDBOT_WEB_PORT=${BUILDBOT_WEB_PORT:-tcp:port=8010}'
      - 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-changeme123}'
      - 'POSTGRES_USER=${POSTGRES_USER:-buildbot}'
      - 'POSTGRES_DB=${POSTGRES_DB:-buildbot}'
      - 'BUILDBOT_DB_URL=postgresql+psycopg2://{POSTGRES_USER}:{POSTGRES_PASSWORD}@postgresql/{POSTGRES_DB}'
    healthcheck:
      test:
        - CMD
        - curl
        - '-f'
        - '$${BUILDBOT_WEB_URL}'
      interval: 2s
      timeout: 10s
      retries: 15
    depends_on:
      postgresql:
        condition: service_healthy
    volumes:
      - ./buildbot/config:/buildbot/config
      - ./buildbot/master.cfg:/buildbot/master.cfg
    networks:
      buildbot: null
  postgresql:
    image: 'postgres:${POSTGRES_IMAGE_TAG:-16-alpine}'
    restart: unless-stopped
    healthcheck:
      test:
        - CMD-SHELL
        - 'pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}'
      interval: 2s
      timeout: 10s
      retries: 15
    volumes:
      - 'buildbot-db:/var/lib/postgresql/data'
    environment:
      - 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-changeme123}'
      - 'POSTGRES_USER=${POSTGRES_USER:-buildbot}'
      - 'POSTGRES_DB=${POSTGRES_DB:-buildbot}'
    networks:
      buildbot: null
  buildbot-worker:
    image: 'buildbot/buildbot-worker:${BUILDBOT_IMAGE_TAG:-v4.1.0}'
    restart: unless-stopped
    environment:
      - 'BUILDMASTER=${BUILDMASTER:-buildbot-master}'
      - 'BUILDMASTER_PORT=${BUILDBOT_WORKER_PORT:-9989}'
      - 'WORKERNAME=${WORKERNAME:-example-worker}'
      - 'WORKERPASS=${WORKERPASS:-pass}'
      - 'WORKER_ENVIRONMENT_BLACKLIST=${WORKER_ENVIRONMENT_BLACKLIST:-DOCKER_BUILDBOT* BUILDBOT_ENV_* BUILDBOT_1* WORKER_ENVIRONMENT_BLACKLIST}'
    healthcheck:
      test:
        - CMD
        - curl
        - '-f'
        - 'http://$${BUILDMASTER}:$${BUILDMASTER_PORT}'
      interval: 5s
      timeout: 20s
      retries: 10
    networks:
      buildbot: null
volumes:
  buildbot-db: {}
networks:
  buildbot: {}