diff mbox series

[v4] package/gitlab-runner: new package

Message ID 20220106123449.344837-1-romain.naour@smile.fr
State Accepted
Headers show
Series [v4] package/gitlab-runner: new package | expand

Commit Message

Romain Naour Jan. 6, 2022, 12:34 p.m. UTC
From: Marcin Niestroj <m.niestroj@grinn-global.com>

We rely on config.toml to be created manually during first boot as setup stage.
Even with an empty config.toml file, the gitlab-runner needs gitlab
registration token to register to a gitlab server.

Use the 14.5.1 release since 14.5.2 and 14.6.0 triggers a build error [1]
due a patch for GO < 1.17.
(helpers/patches/issue_28732/syscall.go:11:2: undefined: syscall.Issue28732Fix)

Tested:
https://gitlab.com/kubu93/buildroot/-/pipelines/442604876

[1] https://gitlab.com/gitlab-org/gitlab-runner/-/issues/28766

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Jérémy Rosen <jeremy.rosen@smile.fr>
---
Note: We used the gitlab-runner for shell or python jobs.
Jobs using docker images (images: in gitlab-ci.yml) is not tested.

v4: update to 14.5.1
    Remove config.toml handling from .mk.
    We rely on config.toml to be created during first boot as setup stage.
    Even with an empty config.toml file, the gitlab-runner needs gitlab
    registration token to register to a gitlab server. (Marcin Niestroj)
    Remove alias gitlab-ci-multi-runner.service (Marcin Niestroj),
    gitlab-ci-multi-runner.service comme from Debian gitlab-runner systemd
    service file.

v3: Change daemon process to gitlab-runner user.
    see as example: https://git.buildroot.net/buildroot/tree/package/tpm2-abrmd/S80tpm2-abrmd?h=2020.05-rc2#n31

[Romain: Tested only using systemd init on aarch64 target emulated by Qemu]
v2: add service file, config file, gitlab user.
    add bash as runtime dependency.
    Add git, curl, ca-certificate, tar runtime dependencies from on debian control file for gitlab-runner package.
    Use gnu tar since we can expect tar options that are not supported by busybox tar implementation.
    Enable SSL/TLS library with openssl needed at runtime.
    Add me as "developer".

test-pkg config:
BR2_PACKAGE_GITLAB_RUNNER=y
---
 DEVELOPERS                                  |  2 +
 package/Config.in                           |  1 +
 package/gitlab-runner/Config.in             | 31 ++++++++++
 package/gitlab-runner/S95gitlab-runner      | 64 +++++++++++++++++++++
 package/gitlab-runner/gitlab-runner.hash    |  3 +
 package/gitlab-runner/gitlab-runner.mk      | 33 +++++++++++
 package/gitlab-runner/gitlab-runner.service | 18 ++++++
 7 files changed, 152 insertions(+)
 create mode 100644 package/gitlab-runner/Config.in
 create mode 100644 package/gitlab-runner/S95gitlab-runner
 create mode 100644 package/gitlab-runner/gitlab-runner.hash
 create mode 100644 package/gitlab-runner/gitlab-runner.mk
 create mode 100644 package/gitlab-runner/gitlab-runner.service

Comments

Marcin Niestroj Jan. 10, 2022, 10:01 a.m. UTC | #1
Romain Naour <romain.naour@smile.fr> writes:

> From: Marcin Niestroj <m.niestroj@grinn-global.com>
>
> We rely on config.toml to be created manually during first boot as setup stage.
> Even with an empty config.toml file, the gitlab-runner needs gitlab
> registration token to register to a gitlab server.
>
> Use the 14.5.1 release since 14.5.2 and 14.6.0 triggers a build error [1]
> due a patch for GO < 1.17.
> (helpers/patches/issue_28732/syscall.go:11:2: undefined: syscall.Issue28732Fix)
>
> Tested:
> https://gitlab.com/kubu93/buildroot/-/pipelines/442604876
>
> [1] https://gitlab.com/gitlab-org/gitlab-runner/-/issues/28766
>
> Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
> Signed-off-by: Romain Naour <romain.naour@smile.fr>
> Cc: Jérémy Rosen <jeremy.rosen@smile.fr>
> ---
> Note: We used the gitlab-runner for shell or python jobs.
> Jobs using docker images (images: in gitlab-ci.yml) is not tested.
>
> v4: update to 14.5.1
>     Remove config.toml handling from .mk.
>     We rely on config.toml to be created during first boot as setup stage.
>     Even with an empty config.toml file, the gitlab-runner needs gitlab
>     registration token to register to a gitlab server. (Marcin Niestroj)
>     Remove alias gitlab-ci-multi-runner.service (Marcin Niestroj),
>     gitlab-ci-multi-runner.service comme from Debian gitlab-runner systemd
>     service file.
>
> v3: Change daemon process to gitlab-runner user.
>     see as example: https://git.buildroot.net/buildroot/tree/package/tpm2-abrmd/S80tpm2-abrmd?h=2020.05-rc2#n31
>
> [Romain: Tested only using systemd init on aarch64 target emulated by Qemu]
> v2: add service file, config file, gitlab user.
>     add bash as runtime dependency.
>     Add git, curl, ca-certificate, tar runtime dependencies from on debian control file for gitlab-runner package.
>     Use gnu tar since we can expect tar options that are not supported by busybox tar implementation.
>     Enable SSL/TLS library with openssl needed at runtime.
>     Add me as "developer".
>
> test-pkg config:
> BR2_PACKAGE_GITLAB_RUNNER=y
> ---

Thanks Romain for updating and resending this patch! Looks fine to me as it is!

--
Regards,
Marcin Niestrój
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 4b04f90ccb..3b3c207495 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1722,6 +1722,7 @@  F:	configs/orangepi_zero_plus_defconfig
 F:	package/argparse/
 F:	package/dt-utils/
 F:	package/easydbus/
+F:	package/gitlab-runner/
 F:	package/lua-flu/
 F:	package/lua-stdlib/
 F:	package/luaossl/
@@ -2407,6 +2408,7 @@  F:	package/enlightenment/
 F:	package/flare-engine/
 F:	package/flare-game/
 F:	package/gcc/
+F:	package/gitlab-runner/
 F:	package/glibc/
 F:	package/irrlicht/
 F:	package/liblinear/
diff --git a/package/Config.in b/package/Config.in
index 9f4ab72a80..f43db927d7 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -2098,6 +2098,7 @@  menu "Miscellaneous"
 	source "package/collectl/Config.in"
 	source "package/domoticz/Config.in"
 	source "package/empty/Config.in"
+	source "package/gitlab-runner/Config.in"
 	source "package/gnuradio/Config.in"
 	source "package/googlefontdirectory/Config.in"
 	source "package/gqrx/Config.in"
diff --git a/package/gitlab-runner/Config.in b/package/gitlab-runner/Config.in
new file mode 100644
index 0000000000..72c2742562
--- /dev/null
+++ b/package/gitlab-runner/Config.in
@@ -0,0 +1,31 @@ 
+config BR2_PACKAGE_GITLAB_RUNNER
+	bool "gitlab-runner"
+	depends on BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
+	depends on BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on BR2_USE_MMU # git
+	depends on BR2_USE_WCHAR # tar
+	select BR2_PACKAGE_BASH # runtime, shells/bash.go probably want to support bashism.
+	select BR2_PACKAGE_BUSYBOX_SHOW_OTHERS # bash
+	select BR2_PACKAGE_CA_CERTIFICATES # runtime
+	select BR2_PACKAGE_GIT # runtime
+	select BR2_PACKAGE_LIBCURL # runtime
+	select BR2_PACKAGE_LIBCURL_CURL # runtime
+	select BR2_PACKAGE_LIBCURL_OPENSSL # runtime, for ca-certificates.
+	select BR2_PACKAGE_OPENSSL # runtime
+	select BR2_PACKAGE_LIBOPENSSL # runtime
+	select BR2_PACKAGE_LIBOPENSSL_BIN # runtime
+	select BR2_PACKAGE_TAR # runtime
+	help
+	  GitLab Runner is the open source project that is used to run
+	  your jobs and send the results back to GitLab. It is used in
+	  conjunction with GitLab CI/CD, the open-source continuous
+	  integration service included with GitLab that coordinates the
+	  jobs.
+
+	  https://docs.gitlab.com/runner/
+
+comment "gitlab-runner needs a toolchain w/ threads"
+	depends on BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS
+	depends on BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS
+	depends on !BR2_TOOLCHAIN_HAS_THREADS
diff --git a/package/gitlab-runner/S95gitlab-runner b/package/gitlab-runner/S95gitlab-runner
new file mode 100644
index 0000000000..69dcb28cce
--- /dev/null
+++ b/package/gitlab-runner/S95gitlab-runner
@@ -0,0 +1,64 @@ 
+#!/bin/sh
+
+DAEMON="gitlab-runner"
+PIDFILE="/var/run/$DAEMON.pid"
+
+GITLAB_RUNNER_ARGS="run"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
+
+start() {
+	printf 'Starting %s: ' "$DAEMON"
+	# shellcheck disable=SC2086 # we need the word splitting
+	start-stop-daemon -S -q -m -b -p "$PIDFILE" -c "$DAEMON:$DAEMON" -x "/usr/bin/$DAEMON" \
+		-- $GITLAB_RUNNER_ARGS
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+stop() {
+	printf 'Stopping %s: ' "$DAEMON"
+	start-stop-daemon -K -q -p "$PIDFILE" -u "$DAEMON"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+reload() {
+	printf 'Reloading %s: ' "$DAEMON"
+	start-stop-daemon -K -s HUP -q -p "$PIDFILE" -u "$DAEMON"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+case "$1" in
+	start|stop|restart|reload)
+		"$1";;
+	reload)
+		# Restart, since there is no true "reload" feature.
+		restart;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
diff --git a/package/gitlab-runner/gitlab-runner.hash b/package/gitlab-runner/gitlab-runner.hash
new file mode 100644
index 0000000000..f4fab595b5
--- /dev/null
+++ b/package/gitlab-runner/gitlab-runner.hash
@@ -0,0 +1,3 @@ 
+# Locally computed
+sha256  63a7963f750ec45a7cb34a660b7247a0aa6def98706b7bd80efc95053e66822d  gitlab-runner-14.5.1.tar.gz
+sha256  0ae968b7ddd25da0209c3c6594aac1ac74ddf90385940b02b420463e2e0734de  LICENSE
diff --git a/package/gitlab-runner/gitlab-runner.mk b/package/gitlab-runner/gitlab-runner.mk
new file mode 100644
index 0000000000..fde776e631
--- /dev/null
+++ b/package/gitlab-runner/gitlab-runner.mk
@@ -0,0 +1,33 @@ 
+################################################################################
+#
+# gitlab-runner
+#
+################################################################################
+
+GITLAB_RUNNER_VERSION = 14.5.1
+GITLAB_RUNNER_SITE = https://gitlab.com/gitlab-org/gitlab-runner/-/archive/v$(GITLAB_RUNNER_VERSION)
+GITLAB_RUNNER_LICENSE = MIT
+GITLAB_RUNNER_LICENSE_FILES = LICENSE
+
+GITLAB_RUNNER_LDFLAGS = \
+	-X gitlab.com/gitlab-org/gitlab-runner/common.VERSION=$(GITLAB_RUNNER_VERSION)
+
+# Don't run gitlab runner as root.
+define GITLAB_RUNNER_USERS
+	gitlab-runner -1 gitlab-runner -1 * /var/run/dbus /bin/false - Gitlab Runner
+endef
+
+define GITLAB_RUNNER_INSTALL_INIT_SYSV
+	$(INSTALL) -m 0755 -D package/gitlab-runner/S95gitlab-runner \
+		$(TARGET_DIR)/etc/init.d/S95gitlab-runner
+endef
+
+define GITLAB_RUNNER_INSTALL_INIT_SYSTEMD
+	mkdir -p $(TARGET_DIR)/var/lib/gitlab-runner
+	$(INSTALL) -D -m 0644 package/gitlab-runner/gitlab-runner.service \
+		$(TARGET_DIR)/usr/lib/systemd/system/gitlab-runner.service
+endef
+
+GITLAB_RUNNER_POST_INSTALL_TARGET_HOOKS += GITLAB_RUNNER_INSTALL_CONFIG
+
+$(eval $(golang-package))
diff --git a/package/gitlab-runner/gitlab-runner.service b/package/gitlab-runner/gitlab-runner.service
new file mode 100644
index 0000000000..cba751a3d6
--- /dev/null
+++ b/package/gitlab-runner/gitlab-runner.service
@@ -0,0 +1,18 @@ 
+[Unit]
+Description=GitLab Runner
+After=network.target
+ConditionFileIsExecutable=/usr/bin/gitlab-runner
+
+[Service]
+Environment="DAEMON_ARGS=run --working-directory /var/lib/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"
+EnvironmentFile=-/etc/default/%p
+StartLimitInterval=5
+StartLimitBurst=10
+ExecStart=/usr/bin/gitlab-runner $DAEMON_ARGS
+ExecReload=/bin/kill -HUP $MAINPID
+
+Restart=always
+RestartSec=120
+
+[Install]
+WantedBy=multi-user.target