From 3201e0b9e67ba5858e75765a391f48a5a622ab79 Mon Sep 17 00:00:00 2001 From: ai-dev Date: Fri, 1 Nov 2024 21:29:05 +0100 Subject: [PATCH] update --- gitea_act_runner/Dockerfile | 31 +++++++++++-------- gitea_act_runner/config.yaml | 9 +++--- .../etc/s6-overlay/s6-rc.d/actrunner/run | 16 +--------- .../etc/s6-overlay/s6-rc.d/init-actrunner/run | 16 ++++++++++ .../s6-overlay/s6-rc.d/init-actrunner/type | 1 + .../etc/s6-overlay/s6-rc.d/init-actrunner/up | 1 + 6 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/run create mode 100644 gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/type create mode 100644 gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/up diff --git a/gitea_act_runner/Dockerfile b/gitea_act_runner/Dockerfile index a125044..0dcb77d 100644 --- a/gitea_act_runner/Dockerfile +++ b/gitea_act_runner/Dockerfile @@ -4,19 +4,6 @@ FROM ${BUILD_FROM} ENV LANG C.UTF-8 -# Copy root filesystem -COPY rootfs / - -# Install necessary dependencies -RUN apk add --no-cache git docker-cli python3 py3-pip && \ - curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | bash -RUN adduser -s /bin/false -D -H actrunner -# Create a directory for the virtual environment and install Ansible inside it -RUN python3 -m venv /opt/ansible-venv && \ - /opt/ansible-venv/bin/pip install --no-cache-dir ansible - -RUN chmod +x /etc/s6-overlay/s6-rc.d/actrunner/* - # Build arguments ARG BUILD_ARCH ARG BUILD_DATE @@ -25,6 +12,24 @@ ARG BUILD_NAME ARG BUILD_REF ARG BUILD_REPOSITORY ARG BUILD_VERSION +ARG ACT_RUNNER_VERSION="0.2.11" + +# Copy root filesystem +COPY rootfs / + +# Install necessary dependencies +RUN apk add --no-cache git docker-cli python3 py3-pip + +# Download and rename the act_runner binary +RUN curl -L -o /usr/local/bin/act_runner https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}/act_runner-${ACT_RUNNER_VERSION}-linux-${BUILD_ARCH} && \ + chmod +x /usr/local/bin/act_runner + +# Create a directory for the virtual environment and install Ansible inside it +RUN python3 -m venv /opt/ansible-venv && \ + /opt/ansible-venv/bin/pip install --no-cache-dir ansible + +RUN chmod +x /etc/s6-overlay/s6-rc.d/actrunner/* +RUN chmod +x /etc/s6-overlay/s6-rc.d/init-actrunner/* # Labels LABEL \ diff --git a/gitea_act_runner/config.yaml b/gitea_act_runner/config.yaml index 46ac6df..6a732fc 100644 --- a/gitea_act_runner/config.yaml +++ b/gitea_act_runner/config.yaml @@ -4,7 +4,6 @@ version: "1.0.0" slug: "act_runner_ansible" description: "Home Assistant add-on that runs Act runner with Gitea integration." url: https://mezgit.duckdns.org/mezned/HAddons/gitea_act_runner -codenotary: codenotary@feres.dev init: false arch: - aarch64 @@ -13,12 +12,12 @@ arch: options: gitea_url: "https://your-gitea-instance.com" gitea_token: "your_token" - repository: "user/repository" - act_runner_options: none + runner_name: "name" + runner_label: "label" log_level: "info" schema: gitea_url: str gitea_token: str - repository: str - act_runner_options: str? + runner_name: str + runner_label: str log_level: list(trace|debug|info|notice|warning|error|fatal)? diff --git a/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/actrunner/run b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/actrunner/run index 1295519..5c9d2cb 100644 --- a/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/actrunner/run +++ b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/actrunner/run @@ -32,19 +32,5 @@ export "LOG_LEVEL=${log_level}" # Activate the Ansible virtual environment source /opt/ansible-venv/bin/activate -# Load configuration from Home Assistant -GITEA_URL=$(bashio::config 'gitea_url') -GITEA_TOKEN=$(bashio::config 'gitea_token') -REPOSITORY=$(bashio::config 'repository') -ACT_OPTIONS=$(bashio::config 'act_runner_options') - -# Activate the Ansible virtual environment -source /opt/ansible-venv/bin/activate - -# Register Act runner with Gitea (if needed) -curl -X POST "$GITEA_URL/api/v1/repos/$REPOSITORY/actions/runners" \ - -H "Authorization: token $GITEA_TOKEN" \ - -d '{ "name": "Act Runner", "labels": ["self-hosted"] }' - bashio::log.info "Handing over control to actrunner..." -exec /usr/local/bin/act $ACT_OPTIONS \ No newline at end of file +exec exec /usr/local/bin/act_runner daemon \ No newline at end of file diff --git a/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/run b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/run new file mode 100644 index 0000000..f7bd9b1 --- /dev/null +++ b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/run @@ -0,0 +1,16 @@ +#!/command/with-contenv bashio +# shellcheck shell=bash +# ============================================================================== +# Home Assistant Community Add-on: Example +# Example init script, runs before any other service +# ============================================================================== + +bashio::log.info "register act_runner !" + +# Load configuration from Home Assistant +GITEA_URL=$(bashio::config 'gitea_url') +GITEA_TOKEN=$(bashio::config 'gitea_token') +RUNNER_NAME=$(bashio::config 'runner_name') +RUNNER_LABEL=$(bashio::config 'runner_label') + +exec /usr/local/bin/act_runner register --no-interactive --instance ${GITEA_URL} --token ${GITEA_TOKEN} --name ${RUNNER_NAME} --labels ${RUNNER_LABEL} \ No newline at end of file diff --git a/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/type b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/type @@ -0,0 +1 @@ +oneshot diff --git a/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/up b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/up new file mode 100644 index 0000000..d4a2c00 --- /dev/null +++ b/gitea_act_runner/rootfs/etc/s6-overlay/s6-rc.d/init-actrunner/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-example/run