git: 01be9f77279f - main - devel/gitea-act_runner: Refactor

From: Muhammad Moinur Rahman <bofh_at_FreeBSD.org>
Date: Tue, 04 Mar 2025 08:34:36 UTC
The branch main has been updated by bofh:

URL: https://cgit.FreeBSD.org/ports/commit/?id=01be9f77279fef9ebc7190a2a2f9f9626ef251d1

commit 01be9f77279fef9ebc7190a2a2f9f9626ef251d1
Author:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
AuthorDate: 2025-03-04 08:31:34 +0000
Commit:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2025-03-04 08:34:08 +0000

    devel/gitea-act_runner: Refactor
    
    - Add act_runner user and group
    - Install sample config
    - Add rc script
    
    Thanks to Anish for the pointers.
    
    Sponsored by:   The FreeBSD Foundation
---
 GIDs                                       |  2 +-
 UIDs                                       |  2 +-
 devel/gitea-act_runner/Makefile            | 16 +++++++--
 devel/gitea-act_runner/files/act_runner.in | 52 ++++++++++++++++++++++++++++++
 devel/gitea-act_runner/pkg-message         |  9 ++++++
 devel/gitea-act_runner/pkg-plist           |  3 ++
 6 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/GIDs b/GIDs
index 78fcf9d4be0d..db0429c94754 100644
--- a/GIDs
+++ b/GIDs
@@ -747,7 +747,7 @@ clickhouse:*:800:
 # free: 803
 # free: 804
 # free: 805
-# free: 806
+act_runner:*:806:
 bosun:*:807:
 clixon:*:808:
 # free: 809
diff --git a/UIDs b/UIDs
index a4dbaa399ef7..d29867210962 100644
--- a/UIDs
+++ b/UIDs
@@ -753,7 +753,7 @@ clickhouse:*:800:800::0:0:ClickHouse Daemon:/var/db/clickhouse:/usr/sbin/nologin
 # free: 803
 # free: 804
 # free: 805
-# free: 806
+act_runner:*:806:806::0:0:Act Runner User:/var/db/act_runner:/usr/sbin/nologin
 bosun:*:807:807::0:0:Bosun Daemon:/nonexistent:/usr/sbin/nologin
 clixon:*:808:808::0:0:Clixon Daemon:/nonexistent:/usr/sbin/nologin
 # free: 809
diff --git a/devel/gitea-act_runner/Makefile b/devel/gitea-act_runner/Makefile
index 1d6b77cbe475..9d4fb25950f4 100644
--- a/devel/gitea-act_runner/Makefile
+++ b/devel/gitea-act_runner/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	act_runner
 DISTVERSIONPREFIX=	v
 DISTVERSION=	0.2.11
-PORTREVISION=	4
+PORTREVISION=	5
 CATEGORIES=	devel
 PKGNAMEPREFIX=	gitea-
 
@@ -13,8 +13,20 @@ LICENSE=	MIT
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
 USES=	go:1.23,modules
+USE_RC_SUBR=	${PORTNAME}
+
 GO_MODULE=	gitea.com/gitea/act_runner
 
-PLIST_FILES=	bin/${PORTNAME}
+DATADIR=	/var/db/${PORTNAME}
+
+USERS=	${ACT_RUNNER_USER}
+GROUPS=	${ACT_RUNNER_GROUP}
+
+ACT_RUNNER_USER?=	${PORTNAME}
+ACT_RUNNER_GROUP?=	${PORTNAME}
+
+post-install:
+	${MKDIR} ${STAGEDIR}${DATADIR} ${STAGEDIR}${ETCDIR}
+	${INSTALL_DATA} ${BUILD_WRKSRC}/internal/pkg/config/config.example.yaml ${STAGEDIR}${ETCDIR}/act_runner.conf.sample
 
 .include <bsd.port.mk>
diff --git a/devel/gitea-act_runner/files/act_runner.in b/devel/gitea-act_runner/files/act_runner.in
new file mode 100644
index 000000000000..fa243278cc7e
--- /dev/null
+++ b/devel/gitea-act_runner/files/act_runner.in
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# PROVIDE: act_runner
+# REQUIRE: NETWORKING SYSLOG
+# KEYWORD: shutdown
+#
+# Add the following lines to /etc/rc.conf to enable act_runner:
+#
+# act_runner_enable (bool):   Set to "NO" by default.
+#                       Set it to "YES" to enable act_runner.
+
+. /etc/rc.subr
+
+name="act_runner"
+rcvar="act_runner_enable"
+
+load_rc_config "${name}"
+
+: ${act_runner_user:="act_runner"}
+: ${act_runner_enable:="NO"}
+: ${act_runner_facility:="daemon"}
+: ${act_runner_priority:="debug"}
+: ${act_runner_config:="%%ETCDIR%%/act_runner.conf"}
+: ${act_runner_cache_dir:="%%DATADIR%%"}
+: ${act_runner_log_dir:="/var/log/act_runner"}
+: ${act_runner_log_file:="${act_runner_log_dir}/act_runner.log"}
+: ${act_runner_flags:="-c ${act_runner_config} daemon"}
+
+procname="%%PREFIX%%/bin/act_runner"
+command="${procname} ${act_runner_flags}"
+
+pidfile="/var/run/${name}.pid"
+
+start_cmd="${name}_start"
+sig_stop=KILL
+
+act_runner_start() {
+  #  ensure the log directories are owned by the unprivileged user
+  for d in "${act_runner_log_dir}"; do
+    if [ ! -e "$d" ]; then
+      mkdir "$d"
+      chown "${act_runner_user}" "$d"
+    fi
+  done
+  /usr/sbin/daemon -S -l "${act_runner_facility}" -s "${act_runner_priority}" \
+    -T "${name}" \
+    -u "${act_runner_user}" -p "${pidfile}" \
+    -o "${act_runner_log_file}" \
+    $command
+}
+
+run_rc_command "$1"
diff --git a/devel/gitea-act_runner/pkg-message b/devel/gitea-act_runner/pkg-message
new file mode 100644
index 000000000000..7f6b6e6d8c9f
--- /dev/null
+++ b/devel/gitea-act_runner/pkg-message
@@ -0,0 +1,9 @@
+[
+{ type: install
+  message: <<EOM
+FreeBSD does not support Docker.
+When configuring the runner, use 'host' as the label. e.g.
+act-runner register --labels FreeBSD:host,FreeBSD-14.2:host
+EOM
+}
+]
diff --git a/devel/gitea-act_runner/pkg-plist b/devel/gitea-act_runner/pkg-plist
new file mode 100644
index 000000000000..a56480528e5e
--- /dev/null
+++ b/devel/gitea-act_runner/pkg-plist
@@ -0,0 +1,3 @@
+bin/act_runner
+@sample %%ETCDIR%%/act_runner.conf.sample
+@dir(%%ACT_RUNNER_USER%%,%%ACT_RUNNER_GROUP%%,750) %%DATADIR%%