diff --git a/gitea-runner/config/.template_info.env b/gitea-runner/config/.template_info.env new file mode 100644 index 0000000..5c59935 --- /dev/null +++ b/gitea-runner/config/.template_info.env @@ -0,0 +1,10 @@ +# DO NOT EDIT THIS FILE FOR YOUR SERVICE! +# This file is replaced from the template whenever there is an update. +# Edit the service.env file to make changes. + + +# Template to use - always required! +TEMPLATE=gitea-runner +REQUIRES_HOST_ROOT=false +REQUIRES_DOCKER=true +REQUIRES_DOCKER_ROOT=true diff --git a/gitea-runner/config/service.env b/gitea-runner/config/service.env new file mode 100644 index 0000000..a51ebf8 --- /dev/null +++ b/gitea-runner/config/service.env @@ -0,0 +1,10 @@ +# Service settings specific to this server +# (can also override anything in the .template_info.env file in the template to make it specific to this server) + +# $HOME etc expanded on remote server by bash. +GITEA_RUNNER_DIRECTORY="${HOME}/.gitea-runner" +ACT_RUNNER_VERSION="0.2.11" +GITEA_URL="https://gitea.jde.nz" +GITEA_TOKEN="GITEA_TOKEN" +GITEA_RUNNER_NAME="${SERVER}-${SERVICE}" +GITEA_RUNNER_LABELS="ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster" diff --git a/gitea-runner/destroy.sh b/gitea-runner/destroy.sh new file mode 100755 index 0000000..461c076 --- /dev/null +++ b/gitea-runner/destroy.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euo pipefail +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "SERVER" "SERVICE" "GITEA_RUNNER_DIRECTORY" + +# Call uninstall script first +./uninstall.sh + +echo "Destroyed ${CONTAINER_NAME}." diff --git a/gitea-runner/install.sh b/gitea-runner/install.sh new file mode 100755 index 0000000..230ffbf --- /dev/null +++ b/gitea-runner/install.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -euo pipefail + +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "SERVER" "SERVICE" "TEMP_DIR" "GITEA_RUNNER_DIRECTORY" "ACT_RUNNER_VERSION" + +echo "Downloading act_runner ${ACT_RUNNER_VERSION}..." +wget https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}/act_runner-${ACT_RUNNER_VERSION}-linux-amd64 -O "${TEMP_DIR}/act_runner" + +chmod +x "${TEMP_DIR}/act_runner" || _die "Failed to download ${TEMP_DIR}/act_runner" + +ACT_RUNNER="${GITEA_RUNNER_DIRECTORY}/act_runner" + +mkdir -p "${GITEA_RUNNER_DIRECTORY}" || _die "Failed to create ${GITEA_RUNNER_DIRECTORY}" +cp "${TEMP_DIR}/act_runner" "$ACT_RUNNER" || _die "Failed to copy ${TEMP_DIR}/act_runner to ${GITEA_RUNNER_DIRECTORY}/act_runner" + +${ACT_RUNNER} --version || _die "Failed to run ${ACT_RUNNER}" +${ACT_RUNNER} generate-config > "${GITEA_RUNNER_DIRECTORY}/config.yaml" || _die "Failed to generate config.yaml" + +${ACT_RUNNER} --config "${GITEA_RUNNER_DIRECTORY}/config.yaml" \ + register --no-interactive \ + --instance GITEA_URL \ + --token "${GITEA_TOKEN}" \ + --name "${GITEA_RUNNER_NAME}" \ + --labels "${GITEA_RUNNER_LABELS}" + + +./start.sh || _die "Failed to start" + +echo "Installation complete for service ${SERVICE}." diff --git a/gitea-runner/start.sh b/gitea-runner/start.sh new file mode 100755 index 0000000..5eda7b8 --- /dev/null +++ b/gitea-runner/start.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -euo pipefail +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "SERVER" "SERVICE" "GITEA_RUNNER_DIRECTORY" + +# START SCRIPT +# The start script is required for all templates. +# It is used to start the service on the server. +# It is called with the path to the server specific env file as an argument. + +CONFIG_FILE="${GITEA_RUNNER_DIRECTORY}/config.yaml" + +"${GITEA_RUNNER_DIRECTORY}/act_runner" daemon --config "${CONFIG_FILE}" || _die "Failed to start act_runner" + +echo "act_runner started" + + diff --git a/gitea-runner/status.sh b/gitea-runner/status.sh new file mode 100755 index 0000000..428ad89 --- /dev/null +++ b/gitea-runner/status.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "SERVER" "SERVICE" "GITEA_RUNNER_DIRECTORY" + + +# check if the act_runner process is running +if ! pgrep -f "${GITEA_RUNNER_DIRECTORY}/act_runner" > /dev/null; then + echo "act_runner is not running" + exit 1 +fi + +echo "act_runner is running" +exit 0 \ No newline at end of file diff --git a/gitea-runner/stop.sh b/gitea-runner/stop.sh new file mode 100755 index 0000000..6f23737 --- /dev/null +++ b/gitea-runner/stop.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -euo pipefail +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "SERVER" "SERVICE" "GITEA_RUNNER_DIRECTORY" + +# kill the act_runner process +pkill -f "${GITEA_RUNNER_DIRECTORY}/act_runner" + +echo "act_runner stopped" + + + + + + diff --git a/gitea-runner/uninstall.sh b/gitea-runner/uninstall.sh new file mode 100755 index 0000000..c9ea511 --- /dev/null +++ b/gitea-runner/uninstall.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "SERVER" "SERVICE" "GITEA_RUNNER_DIRECTORY" + +echo "Uninstalling service ${SERVICE}..." + +./stop.sh || _die "Failed to stop act_runner" + +rm -rf "${GITEA_RUNNER_DIRECTORY}" + + +echo "Service ${SERVICE} uninstalled." +echo "Note: This does NOT remove the local data folder. Use destroy for that."