commit 6ddeea9491b553f299835030e616e86a5a8da749 Author: Zoran Peričić Date: Sat Feb 15 16:59:36 2025 +0100 v0.3.0-1 diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..ce1e0cb --- /dev/null +++ b/config.yaml @@ -0,0 +1,87 @@ +# Example configuration file, it's safe to copy this as the default config file without any modification. + +# You don't have to copy this file to your instance, +# just run `./act_runner generate-config > config.yaml` to generate a config file. + +log: + # The level of logging, can be trace, debug, info, warn, error, fatal + level: info + +runner: + # Where to store the registration result. + file: .runner + # Execute how many tasks concurrently at the same time. + capacity: 1 + # Extra environment variables to run jobs. + envs: {} + # Extra environment variables to run jobs from a file. + # It will be ignored if it's empty or the file doesn't exist. + env_file: .env + # The timeout for a job to be finished. + # Please note that the Gitea instance also has a timeout (3h by default) for the job. + # So the job could be stopped by the Gitea instance if it's timeout is shorter than this. + timeout: 3h + # Whether skip verifying the TLS certificate of the Gitea instance. + insecure: false + # The timeout for fetching the job from the Gitea instance. + fetch_timeout: 5s + # The interval for fetching the job from the Gitea instance. + fetch_interval: 2s + # The labels of a runner are used to determine which jobs the runner can run, and how to run them. + # Like: ["macos-arm64:host", "ubuntu-latest:docker://node:16-bullseye", "ubuntu-22.04:docker://node:16-bullseye"] + # If it's empty when registering, it will ask for inputting labels. + # If it's empty when execute `deamon`, will use labels in `.runner` file. + labels: ["fedora:host"] + +cache: + # Enable cache server to use actions/cache. + enabled: true + # The directory to store the cache data. + # If it's empty, the cache data will be stored in $HOME/.cache/actcache. + dir: "" + # The host of the cache server. + # It's not for the address to listen, but the address to connect from job containers. + # So 0.0.0.0 is a bad choice, leave it empty to detect automatically. + host: "" + # The port of the cache server. + # 0 means to use a random available port. + port: 0 + # The external cache server URL. Valid only when enable is true. + # If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself. + # The URL should generally end with "/". + external_server: "" + +container: + # Specifies the network to which the container will connect. + # Could be host, bridge or the name of a custom network. + # If it's empty, act_runner will create a network automatically. + network: "" + # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker). + privileged: false + # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway). + options: + # The parent directory of a job's working directory. + # If it's empty, /workspace will be used. + workdir_parent: + # Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob + # You can specify multiple volumes. If the sequence is empty, no volumes can be mounted. + # For example, if you only allow containers to mount the `data` volume and all the json files in `/src`, you should change the config to: + # valid_volumes: + # - data + # - /src/*.json + # If you want to allow any volume, please use the following configuration: + # valid_volumes: + # - '**' + valid_volumes: [] + # overrides the docker client host with the specified one. + # If it's empty, act_runner will find an available docker host automatically. + # If it's "-", act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers. + # If it's not empty or "-", the specified docker host will be used. An error will be returned if it doesn't work. + docker_host: "" + # Pull docker image(s) even if already present + force_pull: false + +host: + # The parent directory of a job's working directory. + # If it's empty, $HOME/.cache/act/ will be used. + workdir_parent: diff --git a/gitea-act-runner-setup b/gitea-act-runner-setup new file mode 100755 index 0000000..983281d --- /dev/null +++ b/gitea-act-runner-setup @@ -0,0 +1,31 @@ +#!/bin/bash +set -euo pipefail + +INSTANCE="${1:?Usage: gitea-act-runner-setup }" +RUNNER_DIR="/var/lib/gitea/runners/${INSTANCE}" +CONFIG="/etc/gitea/runners/${INSTANCE}.yaml" + +if [ ! -f "$CONFIG" ]; then + echo "Config not found: $CONFIG" + echo "Copy /etc/gitea/runners/runner1.yaml to $CONFIG first." + exit 1 +fi + +mkdir -p "$RUNNER_DIR" +chown gitea-runner:gitea-runner "$RUNNER_DIR" + +mkdir -p "$RUNNER_DIR" +chown gitea-runner:gitea-runner "$RUNNER_DIR" + +# Enable rootless podman socket (once per user, idempotent) +RUNNER_HOME=$(getent passwd gitea-runner | cut -d: -f6) +SOCKET_WANTS="${RUNNER_HOME}/.config/systemd/user/sockets.target.wants" +PODMAN_SOCKET="/usr/lib/systemd/user/podman.socket" +if [ -f "$PODMAN_SOCKET" ] && [ ! -L "${SOCKET_WANTS}/podman.socket" ]; then + mkdir -p "$SOCKET_WANTS" + ln -s "$PODMAN_SOCKET" "${SOCKET_WANTS}/podman.socket" + chown -R gitea-runner:gitea-runner "${RUNNER_HOME}/.config" +fi + +cd "$RUNNER_DIR" +sudo -u gitea-runner gitea-act-runner register -c "$CONFIG" diff --git a/gitea-act-runner.sysusers b/gitea-act-runner.sysusers new file mode 100644 index 0000000..de2693b --- /dev/null +++ b/gitea-act-runner.sysusers @@ -0,0 +1,2 @@ +# Type Name ID GECOS Home directory Shell +u gitea-runner - "Gitea Act Runner" /var/lib/gitea/runners /sbin/nologin diff --git a/gitea-act_runner.spec b/gitea-act_runner.spec new file mode 100644 index 0000000..421b7a3 --- /dev/null +++ b/gitea-act_runner.spec @@ -0,0 +1,85 @@ +Name: gitea-act_runner +Version: 0.3.0 +Release: 1%{?dist} +Summary: Gitea act runner service. +License: MIT +Group: System Environment/Base +URL: http://gitea.infomaas.com/rpms-fedora-free/gitea-act_runner + +Source0: https://dl.gitea.com/act_runner/%{version}/act_runner-%{version}-linux-amd64 +Source1: https://dl.gitea.com/act_runner/%{version}/act_runner-%{version}-linux-arm64 +Source10: gitea-act_runner@.service +Source11: config.yaml +Source12: gitea-act-runner-setup +Source13: gitea-act-runner.sysusers + +BuildRequires: systemd-rpm-macros +Requires: shadow-utils +%{?systemd_requires} + +ExclusiveArch: x86_64 aarch64 + +%description +Act runner is a runner for Gitea based on Gitea fork of act. + +This package includes official binaries and runs act_runner natively on the host. + +%install +%{__rm} -rf %{buildroot} + +install -d -m 755 %{buildroot}%{_bindir} +%ifarch x86_64 +install -m 755 %{SOURCE0} %{buildroot}%{_bindir}/gitea-act-runner +%endif + +%ifarch aarch64 +install -m 755 %{SOURCE1} %{buildroot}%{_bindir}/gitea-act-runner +%endif + +install -p -D -m 644 %{SOURCE10} %{buildroot}%{_unitdir}/gitea-act_runner@.service +install -p -D -m 644 %{SOURCE13} %{buildroot}%{_sysusersdir}/gitea-act-runner.conf + +install -d -m 750 %{buildroot}%{_sysconfdir}/gitea/runners +install -m 640 %{SOURCE11} %{buildroot}%{_sysconfdir}/gitea/runners/runner1.yaml +install -m 755 %{SOURCE12} %{buildroot}%{_bindir}/gitea-act-runner-setup + +install -d -m 750 %{buildroot}%{_sharedstatedir}/gitea/runners + +%post +%sysusers_create_package gitea-act-runner %{SOURCE13} + +if [ $1 -eq 1 ]; then + loginctl enable-linger gitea-runner || : +fi + +if ! grep -q "gitea-runner" /etc/subuid; then + LAST_ID=$(tail -n 1 /etc/subuid | cut -d: -f2) + [ -z "$LAST_ID" ] && START_ID=100000 || START_ID=$((LAST_ID + 65536)) + + echo "gitea-runner:$START_ID:65536" >> /etc/subuid + echo "gitea-runner:$START_ID:65536" >> /etc/subgid +fi + +%systemd_post gitea-act_runner@.service + +%preun +%systemd_preun gitea-act_runner@.service + +%postun +%systemd_postun gitea-act_runner@.service + +%clean +%{__rm} -rf %{buildroot} + +%files +%defattr(-,root,root,-) + +%{_bindir}/gitea-act-runner +%{_bindir}/gitea-act-runner-setup +%{_unitdir}/gitea-act_runner@.service +%{_sysusersdir}/gitea-act-runner.conf + +%defattr(-,gitea-runner,gitea-runner,750) +%dir %{_sysconfdir}/gitea +%dir %{_sysconfdir}/gitea/runners +%config(noreplace) %{_sysconfdir}/gitea/runners/runner1.yaml diff --git a/gitea-act_runner@.service b/gitea-act_runner@.service new file mode 100644 index 0000000..49a6b5c --- /dev/null +++ b/gitea-act_runner@.service @@ -0,0 +1,23 @@ +[Unit] +Description=Act runner is a runner for Gitea +After=network.target +ConditionPathExists=/var/lib/gitea/runners/%I/.runner +StartLimitIntervalSec=60 +StartLimitBurst=3 + +[Service] +Type=simple +User=gitea-runner + +StateDirectory=gitea/runners/%i +StateDirectoryMode=0750 +WorkingDirectory=/var/lib/gitea/runners/%I +Environment=HOME=/var/lib/gitea/runners/%I + +ExecStart=/usr/bin/gitea-act-runner daemon -c /etc/gitea/runners/%I.yaml + +Restart=on-failure +RestartSec=5s + +[Install] +WantedBy=multi-user.target