summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorccureau <ccureau@noreply.gitea.com>2023-06-12 08:35:27 +0200
committerJason Song <i@wolfogre.com>2023-06-12 08:35:27 +0200
commit341d49a24d45abe4c7636e46d524f1ca2bf687cc (patch)
treedf0e9a32e9a61e142ea1fc5f084f36e710e56ae0 /scripts
parentExit with Code 1 if registering a runner fails (#228) (diff)
downloadforgejo-runner-341d49a24d45abe4c7636e46d524f1ca2bf687cc.tar.xz
forgejo-runner-341d49a24d45abe4c7636e46d524f1ca2bf687cc.zip
implement act_runner rootless image (#208)
This PR creates a rootless Docker image that runs both `dockerd` and `act_runner` using `supervisord`. It has been tested locally for a few days and seems stable. Co-authored-by: ccureau <ccureau@noreply.gitea.io> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/208 Reviewed-by: Jason Song <i@wolfogre.com> Co-authored-by: ccureau <ccureau@noreply.gitea.com> Co-committed-by: ccureau <ccureau@noreply.gitea.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/rootless.sh9
-rwxr-xr-xscripts/run.sh47
-rw-r--r--scripts/supervisord.conf13
3 files changed, 69 insertions, 0 deletions
diff --git a/scripts/rootless.sh b/scripts/rootless.sh
new file mode 100755
index 0000000..310a03b
--- /dev/null
+++ b/scripts/rootless.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+# wait for docker daemon
+while ! nc -z localhost 2376 </dev/null; do
+ echo 'waiting for docker daemon...'
+ sleep 5
+done
+
+. /opt/act/run.sh
diff --git a/scripts/run.sh b/scripts/run.sh
new file mode 100755
index 0000000..8317b2d
--- /dev/null
+++ b/scripts/run.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+if [[ ! -d /data ]]; then
+ mkdir -p /data
+fi
+
+cd /data
+
+CONFIG_ARG=""
+if [[ ! -z "${CONFIG_FILE}" ]]; then
+ CONFIG_ARG="--config ${CONFIG_FILE}"
+fi
+
+# Use the same ENV variable names as https://github.com/vegardit/docker-gitea-act-runner
+
+if [[ ! -s .runner ]]; then
+ try=$((try + 1))
+ success=0
+
+ # The point of this loop is to make it simple, when running both act_runner and gitea in docker,
+ # for the act_runner to wait a moment for gitea to become available before erroring out. Within
+ # the context of a single docker-compose, something similar could be done via healthchecks, but
+ # this is more flexible.
+ while [[ $success -eq 0 ]] && [[ $try -lt ${GITEA_MAX_REG_ATTEMPTS:-10} ]]; do
+ act_runner register \
+ --instance "${GITEA_INSTANCE_URL}" \
+ --token "${GITEA_RUNNER_REGISTRATION_TOKEN}" \
+ --name "${GITEA_RUNNER_NAME:-`hostname`}" \
+ --labels "${GITEA_RUNNER_LABELS}" \
+ ${CONFIG_ARG} --no-interactive > /tmp/reg.log 2>&1
+
+ cat /tmp/reg.log
+
+ cat /tmp/reg.log | grep 'Runner registered successfully' > /dev/null
+ if [[ $? -eq 0 ]]; then
+ echo "SUCCESS"
+ success=1
+ else
+ echo "Waiting to retry ..."
+ sleep 5
+ fi
+ done
+fi
+# Prevent reading the token from the act_runner process
+unset GITEA_RUNNER_REGISTRATION_TOKEN
+
+act_runner daemon ${CONFIG_ARG}
diff --git a/scripts/supervisord.conf b/scripts/supervisord.conf
new file mode 100644
index 0000000..8c45f5b
--- /dev/null
+++ b/scripts/supervisord.conf
@@ -0,0 +1,13 @@
+[supervisord]
+nodaemon=true
+logfile=/dev/null
+logfile_maxbytes=0
+
+[program:dockerd]
+command=/usr/local/bin/dockerd-entrypoint.sh
+
+[program:act_runner]
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+redirect_stderr=true
+command=/opt/act/rootless.sh