diff --git a/CloudronManifest.json b/CloudronManifest.json index fe9295b..2c5d731 100644 --- a/CloudronManifest.json +++ b/CloudronManifest.json @@ -1,6 +1,6 @@ { - "id": "io.gitea.cloudronapp", - "title": "Gitea", + "id": "io.gitea.actrunner.cloudronapp", + "title": "Gitea + Act Runner", "author": "Gitea developers", "description": "file://DESCRIPTION.md", "tagline": "A painless self-hosted Git Service", @@ -10,6 +10,7 @@ "httpPort": 3000, "memoryLimit": 536870912, "addons": { + "docker": {}, "mysql": {}, "sendmail": { "supportsDisplayName": true diff --git a/Dockerfile b/Dockerfile index 745e7e8..3274612 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,12 @@ RUN mkdir -p /home/git/gitea && \ # setup config paths ADD app.ini.template /home/git/app.ini.template +# renovate: datasource=github-releases depName=gitea/act_runner versioning=semver extractVersion=^v(?.+)$ registryUrl=https://gitea.com +ARG ACT_RUNNER_VERSION=0.2.11 + +RUN curl -L https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}/act_runner-${ACT_RUNNER_VERSION}-linux-amd64.xz | unxz -dc > /usr/local/bin/act_runner && \ + chmod +x /usr/local/bin/act_runner + # setup log paths RUN mkdir -p /run/gitea && chown -R git:git /run/gitea RUN sed -e 's,^logfile=.*$,logfile=/run/gitea/supervisord.log,' -i /etc/supervisor/supervisord.conf diff --git a/POSTINSTALL.md b/POSTINSTALL.md index c5cb1a5..7dcc006 100644 --- a/POSTINSTALL.md +++ b/POSTINSTALL.md @@ -6,3 +6,7 @@ This app is pre-setup with an admin account. The initial credentials are: Use the `Local` authentication source for logging in as admin. + +Gitea is bundled along with `act_runner` runner. It's being registered in Gitea at the first run. +To configure `act_runner` you need to update `/app/data/act_runner/config.yaml`. Please read a config example for a reference. +https://gitea.com/gitea/act_runner/src/branch/main/internal/pkg/config/config.example.yaml diff --git a/start.sh b/start.sh index 420f0bc..d67be75 100755 --- a/start.sh +++ b/start.sh @@ -2,7 +2,9 @@ set -eu -o pipefail -mkdir -p /run/gitea/tmp/uploads /run/sshd /run/gitea/sessions +mkdir -p /run/gitea/tmp/uploads /run/sshd /run/gitea/sessions /app/data/act_runner + +export DOCKER_HOST=${CLOUDRON_DOCKER_HOST} # CLOUDRON_OIDC_PROVIDER_NAME not supported as it will be used in rest route! setup_oidc_source() { @@ -26,14 +28,37 @@ setup_root_user() { fi } -setup_auth() { - set -eu +setup_act_runner() { + wait_for_gitea - # Wait for gitea to finish db setup, before we do any db operations - while ! curl --fail http://localhost:3000/explore; do + if [[ ! -f /app/data/act_runner/.runner ]]; then + echo "==> Setup act_runner" + + RUNNER_TOKEN=$(gosu git /home/git/gitea/gitea --config /run/gitea/app.ini actions generate-runner-token) + + echo "===> act_runner token: ${RUNNER_TOKEN}" + if [[ ! -f /app/data/act_runner/config.yaml ]]; then + gosu git act_runner generate-config > /app/data/act_runner/config.yaml + fi + yq -e -i ".runner.file=\"/app/data/act_runner/.runner\"" /app/data/act_runner/config.yaml + + echo "===> Register act_runner" + gosu git act_runner register --instance http://localhost:3000 --token ${RUNNER_TOKEN} --name 'cloudron-runner' --config /app/data/act_runner/config.yaml --no-interactive + fi +} + +wait_for_gitea() { + while ! curl --fail -s http://localhost:3000/explore > /dev/null; do echo "==> Waiting for gitea to come up" sleep 1 done +} + +setup() { + set -eu + + # Wait for gitea to finish db setup, before we do any db operations + wait_for_gitea echo "==> Gitea is up, setting up auth" @@ -47,6 +72,9 @@ setup_auth() { echo "==> Setting up root user for first run" setup_root_user fi + + # setup act_runner + setup_act_runner } # SSH_PORT can be unset to disable SSH @@ -120,6 +148,6 @@ mkdir -p /app/data/repository /app/data/ssh /app/data/custom /app/data/gnupg chown -R git:git /app/data /run/gitea # this expects app.ini to be available -( setup_auth ) & +( setup ) & exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gitea diff --git a/supervisor/act_runner.conf b/supervisor/act_runner.conf new file mode 100644 index 0000000..84ad2db --- /dev/null +++ b/supervisor/act_runner.conf @@ -0,0 +1,11 @@ +[program:act_runner] +directory=/app/data/act_runner/ +command=bash -c "while true; do [[ -f /app/data/act_runner/.runner ]] && break; echo 'Wait for act_runner config'; sleep 1; done && act_runner daemon --config /app/data/act_runner/config.yaml" +user=git +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +environment=HOME="/home/git",USER="git"