Forgejo
Forgejo is a self-hosted Git forge: repositories, issues, pull requests, packages, and Forgejo Actions for CI, through a separate runner. It is where an agent’s code lands, and the runner is where it gets built, which makes it a good stack to see Kaio’s host access check at work on something that needs it.
1. Write the Compose file
Section titled “1. Write the Compose file”services: forgejo: image: codeberg.org/forgejo/forgejo:${FORGEJO_TAG:-17} restart: unless-stopped environment: - USER_UID=1000 - USER_GID=1000 - FORGEJO__database__DB_TYPE=postgres - FORGEJO__database__HOST=db:5432 - FORGEJO__database__NAME=forgejo - FORGEJO__database__USER=forgejo - FORGEJO__database__PASSWD=${POSTGRES_PASSWORD} - FORGEJO__server__ROOT_URL=${ROOT_URL} - FORGEJO__server__SSH_PORT=222 - RUNNER_SECRET=${RUNNER_SECRET} ports: - "127.0.0.1:3000:3000" - "222:22" volumes: - forgejo:/data depends_on: db: condition: service_healthy
db: image: docker.io/library/postgres:17 restart: unless-stopped environment: - POSTGRES_USER=forgejo - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - POSTGRES_DB=forgejo volumes: - db:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U forgejo -d forgejo"] interval: 5s timeout: 5s retries: 10
docker: image: docker.io/library/docker:dind restart: unless-stopped privileged: true command: ["dockerd", "-H", "tcp://0.0.0.0:2375", "--tls=false"]
runner: image: data.forgejo.org/forgejo/runner:${RUNNER_TAG:-13} restart: unless-stopped environment: - DOCKER_HOST=tcp://docker:2375 command: ["forgejo-runner", "daemon", "--config", "/config.yml"] configs: - source: runner target: /config.yml depends_on: - docker - forgejo
configs: runner: content: | server: connections: forgejo: url: http://forgejo:3000/ uuid: ${RUNNER_UUID} token: ${RUNNER_SECRET} runner: labels: - docker:docker://node:20-bookworm
volumes: forgejo: db:- Everything Forgejo keeps, repositories included, is in the
forgejoanddbnamed volumes. Nothing is mounted from the host, sostack copy --with-volumescarries the whole forge. - The runner’s configuration is written by Compose itself, from
configs.content, with its secret interpolated from Kaio’s environment: no file beside thecompose.yml, nothing to forget on a copy. It needs Docker Compose 2.23 or later. - Jobs run in the
dockerservice, a Docker daemon of the stack’s own, not on the host’s. The runner reaches it over the stack’s network only; port 2375 is published nowhere. - The web UI stays on the loopback for a reverse proxy
to serve; SSH is published on
222, whichSSH_PORTputs in the clone URLs.
2. Write its variables
Section titled “2. Write its variables”FORGEJO_TAG=17RUNNER_TAG=13ROOT_URL=https://git.example.net/POSTGRES_PASSWORD=generate-with-openssl-rand-hex-32RUNNER_SECRET=generate-with-openssl-rand-hex-20RUNNER_UUID=RUNNER_SECRET must be 40 hexadecimal characters, which is what
openssl rand -hex 20 prints. Both it and the database password are flagged as
secrets by their names. RUNNER_UUID
stays empty until step 4.
3. Deploy it, and read the refusal
Section titled “3. Deploy it, and read the refusal”kaio-cli stack deploy forgejo ./compose.yml --env-file .envError: deploy stack refused: This file hands the host to a service: docker runs privileged, with every device and capability of the host. Nothing was deployed. Rerun with --accept-risks to go ahead anywayThat is the Docker-in-Docker service, and the refusal is right: a privileged container is root on the host, and the jobs it runs come from whoever can push a workflow to the forge. Nothing ran. Deploying it is a second command, made on purpose:
kaio-cli stack deploy forgejo ./compose.yml --env-file .env --accept-risksStack forgejo deployment started.warning: docker runs privileged, with every device and capability of the hostThe deploy leaves a warn event naming the risk, and the stack keeps the HOST ACCESS mark on its row, and
kaio_stack_host_access{stack="forgejo"} reads 1, for as long as the file
asks for it. It is the price of building containers in CI. Pay it on purpose:
run this stack on a node of its own, or drop the docker and runner services
and keep the forge alone, which carries no mark at all.
The runner restarts in a loop for now, since it is not registered yet. Open
http://localhost:3000: the first visit is Forgejo’s installation page, with
the database already filled in from the variables, and it creates the
administrator.
4. Register the runner
Section titled “4. Register the runner”Forgejo registers a runner from its shared secret, offline. Open a shell in the
forgejo container and run it as the git user:
kaio-cli container shell <forgejo-container>su git -c "forgejo forgejo-cli actions register --name kaio-runner --secret $RUNNER_SECRET"It prints a UUID. Hand it to the stack and apply, accepting the same risk again, since an apply brings the file up as a deploy does:
kaio-cli stack env set forgejo RUNNER_UUID=<the-uuid>kaio-cli stack apply forgejo --accept-risksThe apply rewrites the runner’s configuration with the UUID, the runner
connects, and it appears in Forgejo’s site administration under Actions. A
workflow with runs-on: docker now runs in a node:20-bookworm container on
the stack’s own daemon. See Forgejo’s
runner configuration
for more labels.
To rotate the secret, change its last 24 characters, register again with the
new value, then stack env set and stack apply --accept-risks.
5. Run it day to day
Section titled “5. Run it day to day”kaio-cli stack check-update forgejo # did the 17 tag move?kaio-cli stack update forgejo --waitkaio-cli stack scan forgejokaio-cli stack versions forgejo--wait answers once every container runs again and Postgres passes its
healthcheck, and puts back the images the stack ran before when it does not get
there.
17 follows the latest minor release of that major version. Moving to the next
major is a stack env set forgejo FORGEJO_TAG=... and an apply, after reading
Forgejo’s release notes and backing up the two volumes: a rollback restores the
tag, not the database migrations the newer version ran.
An update pulls the images and recreates the containers without asking, since
the file does not change. An apply or a rollback is refused until it is run with
--accept-risks, and through MCP an agent at write gets the same refusal on
kaio_stack_apply, kaio_stack_rollback and kaio_stack_copy until it passes
accept_risks, because the file asks for privileged. That is the point: the
privileged daemon stays a decision a person made.
Kaio, built by Régis Gaidot