From bc5c4f51db7427a03c41988c5b099f6fddca615d Mon Sep 17 00:00:00 2001 From: Louis Guidez Date: Sat, 9 Mar 2024 21:23:55 +0100 Subject: [PATCH] first commit w/ functional install script and forgejo runner container unit --- README.md | 3 +++ forgejo-runner.container | 23 ++++++++++++++++++++ install | 46 ++++++++++++++++++++++++++++++++++++++++ pretty_print | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 README.md create mode 100644 forgejo-runner.container create mode 100755 install create mode 100755 pretty_print diff --git a/README.md b/README.md new file mode 100644 index 0000000..49b1f37 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Container Unit Files for Forgejo-Runner + +To install them in the _rootless_ user directory, just execute `install` then reload systemd and start all the services. diff --git a/forgejo-runner.container b/forgejo-runner.container new file mode 100644 index 0000000..b547961 --- /dev/null +++ b/forgejo-runner.container @@ -0,0 +1,23 @@ +[Unit] +Description=Forgejo Runner +Requires=podman.socket + +[Container] +ContainerName=forgejo-runner + +User=0 +SecurityLabelDisable=true + +Image=code.forgejo.org/forgejo/runner:3.3.0 +Exec=forgejo-runner --config config.yml daemon + +Volume=forgejo-runner_data:/data +Volume=/run/user/987/podman/podman.sock:/var/run/docker.sock:z + +Network=pasta + +[Service] +Restart=on-failure + +[Install] +WantedBy=default.target diff --git a/install b/install new file mode 100755 index 0000000..fc173a6 --- /dev/null +++ b/install @@ -0,0 +1,46 @@ +#!/bin/bash + +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" # Retrieves script directory + +source "${SCRIPT_DIR}/pretty_print" # Includes our nice print function + +CONTAINERS_SYSTEMD_DIR="/var/lib/forgejo-runner/.config/containers/systemd" + +FORGEJO_INSTANCE="https://git.archive.hostux.fr" + +if [ "$1" = "--skip-init" ]; then + pretty_print "Skipping the initial configuration." yellow bold +elif [ -z "$1" ]; then + pretty_print --no-newline "Enter the registration token from the Forgejo instance: " blue bold + read FORGEJO_REGISTRATION_TOKEN + + pretty_print "Generating the configuration..." blue bold + podman run --rm -it \ + -v forgejo-runner_data:/data \ + -e FORGEJO_INSTANCE="$FORGEJO_INSTANCE" \ + -e FORGEJO_REGISTRATION_TOKEN="$FORGEJO_REGISTRATION_TOKEN" \ + code.forgejo.org/forgejo/runner:3.3.0 \ + sh -c ' + forgejo-runner register --no-interactive --token "$FORGEJO_REGISTRATION_TOKEN" --name forgejo-runner-on-norrsken --instance "$FORGEJO_INSTANCE" && + forgejo-runner generate-config > config.yml && + sed -i -e "s|network: .*|network: host|" config.yml && + sed -i -e "s|labels: \[\]|labels: \[\"docker:docker://alpine:3.19\"\]|" config.yml && + chown -R 1000:1000 /data + ' +else + echo "Usage: $0 [--skip-init]" +fi + +if [ ! -d "$CONTAINERS_SYSTEMD_DIR" ]; then + pretty_print "Creating the containers units folder" blue bold + mkdir -p "$CONTAINERS_SYSTEMD_DIR" +fi + +filename="forgejo-runner.container" +destination_filename="$filename" + +pretty_print "\nInstalling $filename..." blue bold +cp -v $cp_do_not_overwrite_option "${SCRIPT_DIR}/$filename" "${CONTAINERS_SYSTEMD_DIR}/$destination_filename" + +systemctl --user daemon-reload +pretty_print "\nReloaded systemctl daemon. Done!" green bold diff --git a/pretty_print b/pretty_print new file mode 100755 index 0000000..7b02ceb --- /dev/null +++ b/pretty_print @@ -0,0 +1,39 @@ +#!/bin/bash + +# Usage: pretty_print [--no-newline] [] +pretty_print() { + local colour="" + local bold="" + local newline="\n" + + if [ "$1" = "--no-newline" ]; then + newline="" + shift + fi + if [ -n "$2" ]; then + colour="$2" + fi + if [ "$3" = "bold" ]; then + bold="\e[1m" + fi + + case "$colour" in + red) + colour="\e[31m" + ;; + green) + colour="\e[32m" + ;; + yellow) + colour="\e[33m" + ;; + blue) + colour="\e[34m" + ;; + *) + colour="\e[0m" # Reset + ;; + esac + echo -ne "${colour}${bold}$1\e[0m$newline" +} +