From bcb050794c4118633e0578b40345a44550cda04c Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Thu, 6 Mar 2025 17:02:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0act=5Frunner=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- act_runner.dockerfile | 27 +++++++++++++++++++ resources/act_runner.sh | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 act_runner.dockerfile create mode 100644 resources/act_runner.sh diff --git a/act_runner.dockerfile b/act_runner.dockerfile new file mode 100644 index 0000000..51df444 --- /dev/null +++ b/act_runner.dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:24.04 + +LABEL maintainer="amass <168062547@qq.com>" + +ENV DEBIAN_FRONTEND=noninteractive + +ENV ACT_VERSION 0.2.11 + +RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources \ + && apt update \ + && apt install -y ca-certificates curl git gettext jq tini \ + && curl https://gitea.com/gitea/act_runner/releases/download/v${ACT_VERSION}/act_runner-${ACT_VERSION}-linux-amd64 -o /usr/local/bin/act_runner \ + && chmod +x /usr/local/bin/act_runner \ + && install -m 0755 -d /etc/apt/keyrings \ + && curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \ + && chmod a+r /etc/apt/keyrings/docker.asc \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ + && curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \ + && apt update \ + && apt install -y docker-ce-cli nodejs + +COPY resources/act_runner.sh /opt/act/run.sh + +ENTRYPOINT ["tini","--","/opt/act/run.sh"] + +# docker build --progress tty -f act_runner.dockerfile -t registry.cn-shenzhen.aliyuncs.com/amass_toolset/act_runner:0.2.11 . +# docker push registry.cn-shenzhen.aliyuncs.com/amass_toolset/act_runner:0.2.11 \ No newline at end of file diff --git a/resources/act_runner.sh b/resources/act_runner.sh new file mode 100644 index 0000000..ca14dc1 --- /dev/null +++ b/resources/act_runner.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +if [[ ! -d /data ]]; then + mkdir -p /data +fi + +cd /data + +RUNNER_STATE_FILE=${RUNNER_STATE_FILE:-'.runner'} + +CONFIG_ARG="" +if [[ ! -z "${CONFIG_FILE}" ]]; then + CONFIG_ARG="--config ${CONFIG_FILE}" +fi +EXTRA_ARGS="" +if [[ ! -z "${GITEA_RUNNER_LABELS}" ]]; then + EXTRA_ARGS="${EXTRA_ARGS} --labels ${GITEA_RUNNER_LABELS}" +fi + +# In case no token is set, it's possible to read the token from a file, i.e. a Docker Secret +if [[ -z "${GITEA_RUNNER_REGISTRATION_TOKEN}" ]] && [[ -f "${GITEA_RUNNER_REGISTRATION_TOKEN_FILE}" ]]; then + GITEA_RUNNER_REGISTRATION_TOKEN=$(cat "${GITEA_RUNNER_REGISTRATION_TOKEN_FILE}") +fi + +# Use the same ENV variable names as https://github.com/vegardit/docker-gitea-act-runner +test -f "$RUNNER_STATE_FILE" || echo "$RUNNER_STATE_FILE is missing or not a regular file" + +if [[ ! -s "$RUNNER_STATE_FILE" ]]; 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`}" \ + ${CONFIG_ARG} ${EXTRA_ARGS} --no-interactive 2>&1 | tee /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 +unset GITEA_RUNNER_REGISTRATION_TOKEN_FILE + +act_runner daemon ${CONFIG_ARG}