name: rfc-tier1

services:
  gitea:
    image: gitea/gitea:1.22
    environment:
      GITEA__security__INSTALL_LOCK: "true"
      GITEA__server__ROOT_URL: "http://gitea:3000/"
      GITEA__server__HTTP_PORT: "3000"
      GITEA__database__DB_TYPE: "sqlite3"
      GITEA__webhook__ALLOWED_HOST_LIST: "*"
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:3000/api/healthz"]
      interval: 5s
      timeout: 3s
      retries: 30
    ports:
      - "3001:3000"

  gitea-admin-init:
    image: gitea/gitea:1.22
    # The gitea CLI refuses to run as root (loadRunModeFrom [F] "not
    # supposed to be run as root"). Our custom entrypoint bypasses the
    # image's s6 init that normally drops to the git user, so set it here.
    user: git
    depends_on:
      gitea:
        condition: service_healthy
    volumes_from:
      - gitea
    entrypoint: ["/bin/sh", "-c"]
    command:
      - >
        gitea admin user create --admin --username giteaadmin
        --password giteaadmin-pass --email admin@example.test
        --must-change-password=false || true
    restart: "no"

  gitea-seed:
    image: alpine:3.20
    depends_on:
      gitea-admin-init:
        condition: service_completed_successfully
    env_file:
      - .env.tier1
    environment:
      GITEA_ADMIN_USER: giteaadmin
      GITEA_ADMIN_PASSWORD: giteaadmin-pass
      GITEA_BOT_PASSWORD: rfc-bot-pass
      SEED_OUT: /seed/.env.tier1.generated
    volumes:
      - ./seed-gitea.sh:/seed-gitea.sh:ro
      - ./generated:/seed
    entrypoint: ["/bin/sh", "-c"]
    command:
      - apk add --no-cache curl >/dev/null && sh /seed-gitea.sh
    restart: "no"

  backend:
    build:
      context: ..
      dockerfile: testing/backend.Dockerfile
    depends_on:
      gitea-seed:
        condition: service_completed_successfully
    env_file:
      - .env.tier1
      - ./generated/.env.tier1.generated
    volumes:
      - backend-data:/data
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/api/health').status==200 else 1)"]
      interval: 5s
      timeout: 3s
      retries: 30

  web:
    build:
      context: ..
      dockerfile: testing/web.Dockerfile
    depends_on:
      backend:
        condition: service_healthy
    ports:
      - "8080:80"

  mailpit:
    image: axllent/mailpit:latest
    ports:
      - "8025:8025"
      - "1025:1025"

volumes:
  backend-data:
