# Local Gitea + Actions runner for verifying .gitea/workflows/*.
# Runs natively on arm64 (Apple Silicon) — every image below is multi-arch.
#
# Browser:   http://localhost:3000
# API:       http://localhost:3000/api/v1
# Push URL:  http://galaxy:galaxy-dev@localhost:3000/galaxy/galaxy.git
# Actions:   http://localhost:3000/galaxy/galaxy/actions
#
# `bootstrap.sh` (or `make up`) brings everything up and registers the
# runner. State persists in named Docker volumes; `make clean` wipes them.

services:
  gitea:
    image: gitea/gitea:1.23
    container_name: galaxy-local-gitea
    restart: unless-stopped
    environment:
      USER_UID: "1000"
      USER_GID: "1000"
      GITEA__database__DB_TYPE: sqlite3
      GITEA__database__PATH: /data/gitea/gitea.db
      # ROOT_URL uses the in-network hostname so the runner and spawned
      # workflow containers reach Gitea through the compose network.
      # The browser still works at http://localhost:3000 via the port
      # mapping below; UI-generated copy URLs may show "gitea:3000",
      # which is harmless for local dev.
      GITEA__server__ROOT_URL: http://gitea:3000/
      GITEA__server__SSH_PORT: "2222"
      GITEA__actions__ENABLED: "true"
      GITEA__security__INSTALL_LOCK: "true"
      GITEA__service__DISABLE_REGISTRATION: "true"
    ports:
      - "3000:3000"
      - "2222:22"
    volumes:
      - gitea-data:/data
    networks:
      - gitea-net
    healthcheck:
      test:
        - CMD-SHELL
        - wget -q -O- http://localhost:3000/api/v1/version >/dev/null || exit 1
      interval: 5s
      timeout: 3s
      retries: 30
      start_period: 5s

  runner:
    image: gitea/act_runner:0.6.1
    container_name: galaxy-local-runner
    restart: unless-stopped
    depends_on:
      gitea:
        condition: service_healthy
    environment:
      CONFIG_FILE: /config/config.yaml
      GITEA_INSTANCE_URL: http://gitea:3000
      # Provided by bootstrap.sh in the .env file. After the first
      # successful registration, act_runner persists credentials in
      # /data/.runner and ignores this token on subsequent restarts.
      GITEA_RUNNER_REGISTRATION_TOKEN: ${RUNNER_TOKEN:-}
      GITEA_RUNNER_NAME: galaxy-local
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - runner-data:/data
      - ./config.yaml:/config/config.yaml:ro
    networks:
      - gitea-net

networks:
  gitea-net:
    name: galaxy-local-gitea-net

volumes:
  gitea-data:
    name: galaxy-local-gitea-data
  runner-data:
    name: galaxy-local-runner-data
