summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorEarl Warren <contact@earl-warren.org>2023-08-24 12:28:17 +0200
committerEarl Warren <contact@earl-warren.org>2023-08-26 11:52:19 +0200
commitdeefb19f21f544504d4b4af9d22165c80d81ec74 (patch)
tree3bc26dca54ce61768de6eda88972a55dc35cbb38 /examples
parentthe binaries are published in the runner repository (diff)
downloadforgejo-runner-deefb19f21f544504d4b4af9d22165c80d81ec74.tar.xz
forgejo-runner-deefb19f21f544504d4b4af9d22165c80d81ec74.zip
example docker compose file and test
Diffstat (limited to 'examples')
-rw-r--r--examples/docker-compose/README.md87
-rw-r--r--examples/docker-compose/compose-demo-workflow.yml38
-rw-r--r--examples/docker-compose/compose-forgejo-and-runner.yml68
3 files changed, 176 insertions, 17 deletions
diff --git a/examples/docker-compose/README.md b/examples/docker-compose/README.md
index c3b714c..166fc41 100644
--- a/examples/docker-compose/README.md
+++ b/examples/docker-compose/README.md
@@ -1,20 +1,73 @@
-### Running `act_runner` using `docker-compose`
+## Docker compose with docker-in-docker
-```yml
+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.
+
+### Running
+
+```sh
+docker-compose -f compose-forgejo-and-runner.yml up
+Creating docker-compose_docker-in-docker_1 ... done
+Creating docker-compose_forgejo_1 ... done
+Creating docker-compose_runner-register_1 ... done
+...
+docker-in-docker_1 | time="2023-08-24T10:22:15.023338461Z" level=warning msg="WARNING: API is accessible on http://0.0.0.0:2375
+...
+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
+* user: root
+* password: admin1234
+
+`Forgejo Actions` is enabled by default when creating a repository.
+
+### Security
+
+This is a demo and **must not be used in production** because:
+
+* the runner secret is hardcoded
+* the admin password is hardcoded to admin1234
+
+## Tests workflow
+
+The `compose-demo-workflow.yml` compose file runs a demo workflow to
+verify the `Forgejo runner` can pick up a task from the Forgejo instance
+and run it to completion.
+
+A new repository is created in root/test with the following workflow
+in `.forgejo/workflows/demo.yml`:
+
+```yaml
+on: [push]
+jobs:
+ test:
+ runs-on: docker
+ steps:
+ - run: echo All Good
+```
+
+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
...
- gitea:
- image: gitea/gitea
- ...
-
- runner:
- image: gitea/act_runner
- restart: always
- depends_on:
- - gitea
- volumes:
- - ./data/act_runner:/data
- - /var/run/docker.sock:/var/run/docker.sock
- environment:
- - GITEA_INSTANCE_URL=<instance url>
- - GITEA_RUNNER_REGISTRATION_TOKEN=<registration token>
```
diff --git a/examples/docker-compose/compose-demo-workflow.yml b/examples/docker-compose/compose-demo-workflow.yml
new file mode 100644
index 0000000..2f61d4a
--- /dev/null
+++ b/examples/docker-compose/compose-demo-workflow.yml
@@ -0,0 +1,38 @@
+# Copyright 2023 The Forgejo Authors.
+# SPDX-License-Identifier: MIT
+
+version: "3"
+
+services:
+
+ demo-workflow:
+ image: alpine:3.18
+ links:
+ - forgejo
+ depends_on:
+ runner-register:
+ condition: service_completed_successfully
+ command: >-
+ sh -xc '
+ apk add --quiet git curl jq ;
+ mkdir -p /srv/demo ;
+ cd /srv/demo ;
+ git init --initial-branch=main ;
+ mkdir -p .forgejo/workflows ;
+ echo "{ on: [push], jobs: { test: { runs-on: docker, steps: [ { run: echo All Good } ] } } }" > .forgejo/workflows/demo.yml ;
+ git add . ;
+ git config user.email root@example.com ;
+ git config user.name username ;
+ git commit -m 'demo' ;
+ while : ; do
+ git push --set-upstream --force http://root:admin1234@forgejo:3000/root/test main && break ;
+ sleep 5 ;
+ done ;
+ sha=`git rev-parse HEAD` ;
+ while : ; do
+ curl -sS -f http://forgejo:3000/api/v1/repos/root/test/commits/$$sha/status | jq --raw-output .state | tee status ;
+ grep success status && break ;
+ sleep 5 ;
+ done ;
+ echo DEMO WORKFLOW SUCCESS
+ '
diff --git a/examples/docker-compose/compose-forgejo-and-runner.yml b/examples/docker-compose/compose-forgejo-and-runner.yml
new file mode 100644
index 0000000..75ca5c1
--- /dev/null
+++ b/examples/docker-compose/compose-forgejo-and-runner.yml
@@ -0,0 +1,68 @@
+# Copyright 2023 The Forgejo Authors.
+# SPDX-License-Identifier: MIT
+
+version: "3"
+
+services:
+
+ docker-in-docker:
+ image: docker:dind
+ privileged: true
+ command: [ "dockerd", "-H", "tcp://0.0.0.0:2375", "--tls=false" ]
+
+ forgejo:
+ image: codeberg.org/forgejo/forgejo:1.20.3-0
+ command: >-
+ bash -c '
+ /bin/s6-svscan /etc/s6 &
+ sleep 10 ;
+ su -c "forgejo forgejo-cli actions register --secret e3359786173a7aeb3818c19637479c5dbd7c5abb --labels docker --version 3.0.0" git ;
+ su -c "forgejo admin user create --admin --username root --password admin1234 --email root@example.com" git ;
+ sleep infinity
+ '
+ environment:
+ FORGEJO__security__INSTALL_LOCK: "true"
+ FORGEJO__log__LEVEL: "debug"
+ FORGEJO__actions__ENABLED: "true"
+ FORGEJO__repository__ENABLE_PUSH_CREATE_USER: "true"
+ FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE: "false"
+ FORGEJO__repository__DEFAULT_REPO_UNITS: "repo.code,repo.actions"
+ volumes:
+ - /srv/forgejo-data:/data
+ ports:
+ - 8080:3000
+
+ runner-register:
+ image: code.forgejo.org/forgejo/runner:3.0.0
+ links:
+ - docker-in-docker
+ - forgejo
+ environment:
+ DOCKER_HOST: tcp://docker-in-docker:2375
+ volumes:
+ - /srv/runner-data:/data
+ user: 0:0
+ command: >-
+ bash -c '
+ while : ; do
+ forgejo-runner create-runner-file --instance http://forgejo:3000 --name runner --secret e3359786173a7aeb3818c19637479c5dbd7c5abb && break ;
+ sleep 1 ;
+ done ;
+ forgejo-runner generate-config > config.yml ;
+ sed -i -e "s|labels: \[\]|labels: \[\"docker:docker://alpine:3.18\"\]|" config.yml ;
+ chown -R 1000:1000 /data
+ '
+
+ runner-daemon:
+ image: code.forgejo.org/forgejo/runner:3.0.0
+ links:
+ - docker-in-docker
+ - forgejo
+ environment:
+ DOCKER_HOST: tcp://docker-in-docker:2375
+ depends_on:
+ runner-register:
+ condition: service_completed_successfully
+ volumes:
+ - /srv/runner-data:/data
+ command: "forgejo-runner --config config.yml daemon"