1## Docker compose with docker-in-docker23The `compose-forgejo-and-runner.yml` compose file runs a Forgejo4instance and registers a `Forgejo runner`. A docker server is also5launched within a container (using6[dind](https://hub.docker.com/_/docker/tags?name=dind)) and will be7used by the `Forgejo runner` to execute the workflows.89### Quick start1011```sh12rm -fr /srv/runner-data /srv/forgejo-data13secret=$(openssl rand -hex 20)14sed -i -e "s/{SHARED_SECRET}/$secret/" compose-forgejo-and-runner.yml15docker compose -f compose-forgejo-and-runner.yml up -d16```1718Visit 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`.1920> 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.2122```sh23docker compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml up demo-workflow24```2526Visit http://0.0.0.0:8080/root/test/actions/runs/1 and see that the job ran.272829### Running3031Create a shared secret with:3233```sh34openssl rand -hex 2035```3637Replace all occurences of {SHARED_SECRET} in38[compose-forgejo-and-runner.yml](compose-forgejo-and-runner.yml).3940> **NOTE:** a token obtained from the Forgejo web interface cannot be used as a shared secret.4142Replace {ROOT_PASSWORD} with a secure password in43[compose-forgejo-and-runner.yml](compose-forgejo-and-runner.yml).4445```sh46docker compose -f compose-forgejo-and-runner.yml up47Creating docker-compose_docker-in-docker_1 ... done48Creating docker-compose_forgejo_1 ... done49Creating docker-compose_runner-register_1 ... done50...51docker-in-docker_1 | time="2023-08-24T10:22:15.023338461Z" level=warning msg="WARNING: API is accessible on http://0.0.0.0:237652...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```5758### Manual testing5960To login the Forgejo instance:6162* URL: http://0.0.0.0:808063* user: `root`64* password: `{ROOT_PASSWORD}`6566`Forgejo Actions` is enabled by default when creating a repository.6768## Tests workflow6970The `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 instance72and run it to completion.73* one to verify docker can be run inside the `Forgejo runner` container.7475A new repository is created in root/test with the following workflows:7677#### `.forgejo/workflows/demo.yml`:7879```yaml80on: [push]81jobs:82 test:83 runs-on: docker84 steps:85 - run: echo All Good86```8788#### `.forgejo/workflows/demo_docker.yml`8990```yaml91on: [push]92jobs:93 test_docker:94 runs-on: ubuntu-22.0495 steps:96 - run: docker info97```9899A wait loop expects the status of the check associated with the100commit in Forgejo to show "success" to assert the workflow was run.101102### Running103104```sh105$ docker-compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml up demo-workflow106...107demo-workflow_1 | To http://forgejo:3000/root/test108demo-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 | running112...113```