2023-08-24 05:28:17 -05:00
## Docker compose with docker-in-docker
2023-06-05 03:46:15 -05:00
2023-08-24 05:28:17 -05:00
The `compose-forgejo-and-runner.yml` compose file runs a Forgejo
instance and registers a `Forgejo runner` . A docker server is also
launched within a container (using
[dind ](https://hub.docker.com/_/docker/tags?name=dind )) and will be
used by the `Forgejo runner` to execute the workflows.
2023-10-06 09:56:24 -05:00
### Quick start
```sh
rm -fr /srv/runner-data /srv/forgejo-data
secret=$(openssl rand -hex 20)
sed -i -e "s/{SHARED_SECRET}/$secret/" compose-forgejo-and-runner.yml
docker compose -f compose-forgejo-and-runner.yml up -d
2024-04-07 09:53:48 -05:00
```
Visit 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` .
> 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.
```sh
2023-10-06 09:56:24 -05:00
docker compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml up demo-workflow
```
2024-04-07 09:53:48 -05:00
Visit http://0.0.0.0:8080/root/test/actions/runs/1 and see that the job ran.
2023-08-24 05:28:17 -05:00
### Running
2023-09-04 11:19:15 -05:00
Create a shared secret with:
```sh
openssl rand -hex 20
```
Replace all occurences of {SHARED_SECRET} in
[compose-forgejo-and-runner.yml ](compose-forgejo-and-runner.yml ).
> **NOTE:** a token obtained from the Forgejo web interface cannot be used as a shared secret.
Replace {ROOT_PASSWORD} with a secure password in
[compose-forgejo-and-runner.yml ](compose-forgejo-and-runner.yml ).
2023-08-24 05:28:17 -05:00
```sh
2024-04-07 09:53:48 -05:00
docker compose -f compose-forgejo-and-runner.yml up
2023-08-24 05:28:17 -05:00
Creating docker-compose_docker-in-docker_1 ... done
Creating docker-compose_forgejo_1 ... done
Creating docker-compose_runner-register_1 ... done
...
2024-04-07 11:07:00 -05:00
docker-in-docker_1 | time="2023-08-24T10:22:15.023338461Z" level=warning msg="WARNING: API is accessible on http://0.0.0.0:2376
2023-08-24 05:28:17 -05:00
...
forgejo_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)
...
runner-daemon_1 | time="2023-08-24T10:22:16Z" level=info msg="Starting runner daemon"
```
### Manual testing
To login the Forgejo instance:
* URL: http://0.0.0.0:8080
2024-04-07 09:53:48 -05:00
* user: `root`
* password: `{ROOT_PASSWORD}`
2023-08-24 05:28:17 -05:00
`Forgejo Actions` is enabled by default when creating a repository.
## Tests workflow
2024-04-07 11:07:00 -05:00
The `compose-demo-workflow.yml` compose file runs two demo workflows:
* one to verify the `Forgejo runner` can pick up a task from the Forgejo instance
2023-08-24 05:28:17 -05:00
and run it to completion.
2024-04-07 11:07:00 -05:00
* one to verify docker can be run inside the `Forgejo runner` container.
2023-08-24 05:28:17 -05:00
2024-04-07 11:07:00 -05:00
A new repository is created in root/test with the following workflows:
#### `.forgejo/workflows/demo.yml`:
2023-08-24 05:28:17 -05:00
```yaml
on: [push]
jobs:
test:
runs-on: docker
steps:
- run: echo All Good
```
2024-04-07 11:07:00 -05:00
#### `.forgejo/workflows/demo_docker.yml`
```yaml
on: [push]
jobs:
test_docker:
runs-on: ubuntu-22.04
steps:
- run: docker info
```
2023-08-24 05:28:17 -05:00
A wait loop expects the status of the check associated with the
commit in Forgejo to show "success" to assert the workflow was run.
### Running
```sh
$ docker-compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml up demo-workflow
...
demo-workflow_1 | To http://forgejo:3000/root/test
demo-workflow_1 | + 5ce134e...261cc79 main -> main (forced update)
demo-workflow_1 | branch 'main' set up to track 'http://root:admin1234@forgejo:3000/root/test/main'.
...
demo-workflow_1 | running
2023-06-05 03:46:15 -05:00
...
```