forgejo-runner

git clone git://git.lin.moe/forgejo-runner.git

  1## Docker compose with docker-in-docker
  2
  3The `compose-forgejo-and-runner.yml` compose file runs a Forgejo
  4instance and registers a `Forgejo runner`. A docker server is also
  5launched within a container (using
  6[dind](https://hub.docker.com/_/docker/tags?name=dind)) and will be
  7used by the `Forgejo runner` to execute the workflows.
  8
  9### Quick start
 10
 11```sh
 12rm -fr /srv/runner-data /srv/forgejo-data
 13secret=$(openssl rand -hex 20)
 14sed -i -e "s/{SHARED_SECRET}/$secret/" compose-forgejo-and-runner.yml
 15docker compose -f compose-forgejo-and-runner.yml up -d
 16```
 17
 18Visit http://0.0.0.0:8080/admin/actions/runners with login `root` and password `{ROOT_PASSWORD}` and see the runner is registered with the label `docker`.
 19
 20> NOTE: the `Your ROOT_URL in app.ini is "http://localhost:3000/", it's unlikely matching the site you are visiting.` message is a warning that can be ignored in the context of this example.
 21
 22```sh
 23docker compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml up demo-workflow
 24```
 25
 26Visit http://0.0.0.0:8080/root/test/actions/runs/1 and see that the job ran.
 27
 28
 29### Running
 30
 31Create a shared secret with:
 32
 33```sh
 34openssl rand -hex 20
 35```
 36
 37Replace all occurences of {SHARED_SECRET} in
 38[compose-forgejo-and-runner.yml](compose-forgejo-and-runner.yml).
 39
 40> **NOTE:** a token obtained from the Forgejo web interface cannot be used as a shared secret.
 41
 42Replace {ROOT_PASSWORD} with a secure password in
 43[compose-forgejo-and-runner.yml](compose-forgejo-and-runner.yml).
 44
 45```sh
 46docker compose -f compose-forgejo-and-runner.yml up
 47Creating docker-compose_docker-in-docker_1 ... done
 48Creating docker-compose_forgejo_1          ... done
 49Creating docker-compose_runner-register_1  ... done
 50...
 51docker-in-docker_1  | time="2023-08-24T10:22:15.023338461Z" level=warning msg="WARNING: API is accessible on http://0.0.0.0:2376
 52...
 53forgejo_1           | 2023/08/24 10:22:14 ...s/graceful/server.go:75:func1() [D] Starting server on tcp:0.0.0.0:3000 (PID: 19)
 54...
 55runner-daemon_1     | time="2023-08-24T10:22:16Z" level=info msg="Starting runner daemon"
 56```
 57
 58### Manual testing
 59
 60To login the Forgejo instance:
 61
 62* URL: http://0.0.0.0:8080
 63* user: `root`
 64* password: `{ROOT_PASSWORD}`
 65
 66`Forgejo Actions` is enabled by default when creating a repository.
 67
 68## Tests workflow
 69
 70The `compose-demo-workflow.yml` compose file runs two demo workflows:
 71* one to verify the `Forgejo runner` can pick up a task from the Forgejo instance
 72and run it to completion.
 73* one to verify docker can be run inside the `Forgejo runner` container.
 74
 75A new repository is created in root/test with the following workflows:
 76
 77#### `.forgejo/workflows/demo.yml`:
 78
 79```yaml
 80on: [push]
 81jobs:
 82  test:
 83    runs-on: docker
 84    steps:
 85      - run: echo All Good
 86```
 87
 88#### `.forgejo/workflows/demo_docker.yml`
 89
 90```yaml
 91on: [push]
 92jobs:
 93  test_docker:
 94    runs-on: ubuntu-22.04
 95    steps:
 96      - run: docker info
 97```
 98
 99A wait loop expects the status of the check associated with the
100commit in Forgejo to show "success" to assert the workflow was run.
101
102### Running
103
104```sh
105$ docker-compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml up demo-workflow
106...
107demo-workflow_1     | To http://forgejo:3000/root/test
108demo-workflow_1     |  + 5ce134e...261cc79 main -> main (forced update)
109demo-workflow_1     | branch 'main' set up to track 'http://root:admin1234@forgejo:3000/root/test/main'.
110...
111demo-workflow_1     | running
112...
113```