mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-10 19:32:04 +00:00
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [code.forgejo.org/forgejo/runner](https://forgejo.org) ([source](https://code.forgejo.org/forgejo/runner)) | minor | `11.0.0` -> `11.1.1` | | [forgejo/runner](https://code.forgejo.org/forgejo/runner) | minor | `11.0.0` -> `11.1.1` | --- ### Release Notes <details> <summary>forgejo/runner (code.forgejo.org/forgejo/runner)</summary> ### [`v11.1.1`](https://code.forgejo.org/forgejo/runner/releases/tag/v11.1.1) [Compare Source](https://code.forgejo.org/forgejo/runner/compare/v11.1.0...v11.1.1) - [User guide](https://forgejo.org/docs/next/user/actions/overview/) - [Administrator guide](https://forgejo.org/docs/next/admin/actions/) - [Container images](https://code.forgejo.org/forgejo/-/packages/container/runner/versions) Release Notes *** <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1017): <!--number 1017 --><!--line 0 --><!--description Zml4OiBvdXRwdXRzIGFyZSBvbmx5IHNldCB3aGVuIHRoZSBqb2IgaXMgc3VjY2Vzc2Z1bA==-->fix: outputs are only set when the job is successful<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/1015): <!--number 1015 --><!--line 0 --><!--description Zml4KHByZS1jb21taXQpOiBkb27igJl0IGRlZmF1bHQgYHZlcmJvc2VgIHRvIG9u-->fix(pre-commit): don’t default `verbose` to on<!--description--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/1013): <!--number 1013 --><!--line 0 --><!--description Y2hvcmU6IGRvY3VtZW50IHRoYXQgRE9DS0VSX0hPU1Qgc2hvdWxkIGJlIHVzZWQgaW5zdGVhZCBvZiAtLWNvbnRhaW5lci1kYWVtb24tc29ja2V0-->chore: document that DOCKER\_HOST should be used instead of --container-daemon-socket<!--description--> <!--end release-notes-assistant--> ### [`v11.1.0`](https://code.forgejo.org/forgejo/runner/releases/tag/v11.1.0) [Compare Source](https://code.forgejo.org/forgejo/runner/compare/v11.0.0...v11.1.0) > **Warning** Upgrade to v11.1.1 instead. A [regression was found](https://code.forgejo.org/forgejo/runner/issues/1016) that crashed the runner on skipped or failed jobs. - [User guide](https://forgejo.org/docs/next/user/actions/overview/) - [Administrator guide](https://forgejo.org/docs/next/admin/actions/) - [Container images](https://code.forgejo.org/forgejo/-/packages/container/runner/versions) Release Notes *** <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/1002): <!--number 1002 --><!--line 0 --><!--description ZmVhdDogYWRkIHByZS1jb21taXQgaG9vayBmb3IgdmFsaWRhdG9y-->feat: add pre-commit hook for validator<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/1008): <!--number 1008 --><!--line 0 --><!--description ZmVhdDogdmFsaWRhdGUgLS1kaXJlY3RvcnkgYWx0ZXJuYXRpdmUgdG8gLS1yZXBvc2l0b3J5IHRvIG5vdCBjbG9uZQ==-->feat: validate --directory alternative to --repository to not clone<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/999): <!--number 999 --><!--line 0 --><!--description ZmVhdDogdGhlIGZvcmdlam8gY29udGV4dCBpcyBlcXVpdmFsZW50IHRvIHRoZSBnaXRodWIgY29udGV4dA==-->feat: the forgejo context is equivalent to the github context<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/997): <!--number 997 --><!--line 0 --><!--description ZmVhdDogYWRkIHN1cHBvcnQgZm9yIGEgRGViaWFuIEdOVS9MaW51eCBMWEMgYmFja2VuZCBiYXNlZCBvbiB0cml4aWUgKGUuZy4gdHJpeGllLWx4YzpseGM6Ly9kZWJpYW46dHJpeGllKQ==-->feat: add support for a Debian GNU/Linux LXC backend based on trixie (e.g. trixie-lxc:lxc://debian:trixie)<!--description--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1012): <!--number 1012 --><!--line 0 --><!--description Zml4OiBzY2hlbWEgdmFsaWRhdGlvbiBtdXN0IGFjY2VwdCBhbGlhc2VzIGFuZCBtZXJnZXM=-->fix: schema validation must accept aliases and merges<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/1009): <!--number 1009 --><!--line 0 --><!--description Zml4OiBmb3JnZWpvLXJ1bm5lciB2YWxpZGF0ZSBleGl0IHdpdGggZXJyb3Igd2hlbiB2YWxpZGF0aW9uIGZhaWxz-->fix: forgejo-runner validate exit with error when validation fails<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/1006): <!--number 1006 --><!--line 0 --><!--description Zml4OiBkbyBub3Qgc2F2ZSAucnVubmVyIHVubGVzcyBpdCBpcyBtb2RpZmllZA==-->fix: do not save .runner unless it is modified<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/1003): <!--number 1003 --><!--line 0 --><!--description Zml4OiByZW1vdmUgTFhDIHdvcmtpbmcgZGlyZWN0b3J5IHdoZW4gaXQgY29tcGxldGVz-->fix: remove LXC working directory when it completes<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/995): <!--number 995 --><!--line 0 --><!--description Zml4OiBzZW5kIGpvYiBvdXRwdXRzICYgam9iIHJlc3VsdCB0byBGb3JnZWpvIGluIHN5bmMgd2l0aCBlYWNoIG90aGVy-->fix: send job outputs & job result to Forgejo in sync with each other<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/986): <!--number 986 --><!--line 0 --><!--description Zml4OiBpZiB0aGUgRm9yZ2VqbyBpbnN0YW5jZSBmYWlsZWQgYSBqb2IsIGNhbmNlbCBpdA==-->fix: if the Forgejo instance failed a job, cancel it<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/982): <!--number 982 --><!--line 0 --><!--description Zml4OiBlbmZvcmNlIGpvYi48am9iLWlkPi50aW1lb3V0LW1pbnV0ZXM=-->fix: enforce job.<job-id>.timeout-minutes<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/972): <!--number 972 --><!--line 0 --><!--description Zml4OiB1c2UgYSBmaXhlZCBydW5uZXIgbmFtZSBmb3Igb2xkICg8PSB2MS4yMCkgRm9yZ2VqbyBpbnN0YW5jZXM=-->fix: use a fixed runner name for old (<= v1.20) Forgejo instances<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/965): <!--number 965 --><!--line 0 --><!--description Zml4OiBkb2NrZXItY29tcG9zZSBleGFtcGxlOiBhbGxvdyB0aGUgcnVubmVyIHRvIGtlZXAgaXRzIGxhYmVscw==-->fix: docker-compose example: allow the runner to keep its labels<!--description--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/1001): <!--number 1001 --><!--line 0 --><!--description VXBkYXRlIGRlcGVuZGVuY3kgZm9yZ2Vqby9seGMtaGVscGVycyB0byB2MS4xLjA=-->Update dependency forgejo/lxc-helpers to v1.1.0<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/1000): <!--number 1000 --><!--line 0 --><!--description Y2hvcmU6IG1pbmltYWwgaW50ZWdyYXRpb24gdGVzdCBmb3IgdGhlIExYQyBiYWNrZW5k-->chore: minimal integration test for the LXC backend<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/993): <!--number 993 --><!--line 0 --><!--description Y2hvcmU6IHVuaWZ5IGFjdGlvbnMgVVJMcyBpbiAuZm9yZ2Vqby93b3JrZmxvd3M=-->chore: unify actions URLs in .forgejo/workflows<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/992): <!--number 992 --><!--line 0 --><!--description VXBkYXRlIGh0dHBzOi8vZGF0YS5mb3JnZWpvLm9yZy9hY3Rpb25zL2Nhc2NhZGluZy1wciBhY3Rpb24gdG8gdjIuMy4w-->Update <https://data.forgejo.org/actions/cascading-pr> action to v2.3.0<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/990): <!--number 990 --><!--line 0 --><!--description Y2hvcmU6IGRhdGEuZm9yZ2Vqby5vcmcvYWN0aW9ucy9jYXNjYWRpbmctcHIgaXMgdGhlIGNhbm9uaWNhbCBsb2NhdGlvbg==-->chore: data.forgejo.org/actions/cascading-pr is the canonical location<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/989): <!--number 989 --><!--line 0 --><!--description VXBkYXRlIGRlcGVuZGVuY3kgZm9yZ2Vqby9yZWxlYXNlLW5vdGVzLWFzc2lzdGFudCB0byB2MS40LjE=-->Update dependency forgejo/release-notes-assistant to v1.4.1<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/988): <!--number 988 --><!--line 0 --><!--description Y2hvcmU6IHdhaXQgNCB0aW1lcyBsb25nZXIgZm9yIHRoZSBmb3JnZWpvIGNhc2NhZGUgcHVsbCByZXF1ZXN0IHRvIGNvbXBsZXRl-->chore: wait 4 times longer for the forgejo cascade pull request to complete<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/985): <!--number 985 --><!--line 0 --><!--description UmVtb3ZlIHdpbmRvd3MgYnVpbGQvdGVzdCBwaXBlbGluZSBmb3IgR2l0SHVi-->Remove windows build/test pipeline for GitHub<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/981): <!--number 981 --><!--line 0 --><!--description VXBkYXRlIG1vZHVsZSBjb2RlLmZvcmdlam8ub3JnL2Zvcmdlam8vYWN0aW9ucy1wcm90byB0byB2MC41LjI=-->Update module code.forgejo.org/forgejo/actions-proto to v0.5.2<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/969): <!--number 969 --><!--line 0 --><!--description VXBkYXRlIGh0dHBzOi8vZGF0YS5mb3JnZWpvLm9yZy9hY3Rpb25zL3NldHVwLWZvcmdlam8gYWN0aW9uIHRvIHYzLjAuMw==-->Update <https://data.forgejo.org/actions/setup-forgejo> action to v3.0.3<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/975): <!--number 975 --><!--line 0 --><!--description VXBkYXRlIGZvcmdlam8tcnVubmVyIHRvIHYxMSAobWFqb3Ip-->Update forgejo-runner to v11 (major)<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/973): <!--number 973 --><!--line 0 --><!--description Y2k6IHVwZGF0ZSBmb3JnZWpvIHZlcnNpb24gZm9yIHJlbGVhc2UgaW50ZWdyYXRpb24=-->ci: update forgejo version for release integration<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/970): <!--number 970 --><!--line 0 --><!--description Y2hvcmU6IGx4Yy1zeXN0ZW1kIG1heSBuZWVkIG1vcmUgdGltZSB0byBzdGFydCBvbiBzbG93IG1hY2hpbmVz-->chore: lxc-systemd may need more time to start on slow machines<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/966): <!--number 966 --><!--line 0 --><!--description VXBkYXRlIG1vZHVsZSBnb2xhbmcub3JnL3gvdGVybSB0byB2MC4zNS4w-->Update module golang.org/x/term to v0.35.0<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/964): <!--number 964 --><!--line 0 --><!--description Y2hvcmU6IGNhbGwgdGhlIHJlbGVhc2Ugbm90ZXMgYXNzaXN0YW50IHdoZW4gb3BlbmluZyBhIG5ldyBwdWxsIHJlcXVlc3Q=-->chore: call the release notes assistant when opening a new pull request<!--description--> - [PR](https://code.forgejo.org/forgejo/runner/pulls/954): <!--number 954 --><!--line 0 --><!--description Y2hvcmU6IHNraXAgcmVsZWFzZS1ub3Rlcy1hc3Npc3RhbnQgZm9yIGRlcGVuZGVuY3kgdXBkYXRlcw==-->chore: skip release-notes-assistant for dependency updates<!--description--> <!--end release-notes-assistant--> </details> --- ### Configuration 📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTMuMyIsInVwZGF0ZWRJblZlciI6IjQxLjExMy4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJLaW5kL0RlcGVuZGVuY3lVcGRhdGUiLCJydW4tZW5kLXRvLWVuZC10ZXN0cyJdfQ==--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1018 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Renovate Bot <bot@kriese.eu> Co-committed-by: Renovate Bot <bot@kriese.eu>
394 lines
10 KiB
Bash
Executable file
394 lines
10 KiB
Bash
Executable file
#!/bin/bash
|
|
# Copyright Forgejo Authors.
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
set -o pipefail
|
|
|
|
: ${TMPDIR:=$(mktemp -d)}
|
|
|
|
export -n TMPDIR
|
|
|
|
if ! test -d "$TMPDIR"; then
|
|
echo "TMPDIR=$TMPDIR is expected to be a directory"
|
|
exit 1
|
|
fi
|
|
|
|
trap "rm -fr $TMPDIR" EXIT
|
|
|
|
: ${INPUTS_LXC_CONFIG:=docker libvirt lxc}
|
|
: ${INPUTS_SERIAL:=}
|
|
: ${INPUTS_TOKEN:=}
|
|
: ${INPUTS_FORGEJO:=https://code.forgejo.org}
|
|
: ${INPUTS_LIFETIME:=7d}
|
|
DEFAULT_LXC_HELPERS_VERSION=1.1.0 # renovate: datasource=forgejo-tags depName=forgejo/lxc-helpers
|
|
: ${INPUTS_LXC_HELPERS_VERSION:=$DEFAULT_LXC_HELPERS_VERSION}
|
|
DEFAULT_RUNNER_VERSION=11.1.1 # renovate: datasource=forgejo-releases depName=forgejo/runner
|
|
: ${INPUTS_RUNNER_VERSION:=$DEFAULT_RUNNER_VERSION}
|
|
|
|
: ${KILL_AFTER:=21600} # 6h == 21600
|
|
NODEJS_VERSION=20
|
|
DEBIAN_RELEASE=bookworm
|
|
YQ_VERSION=v4.45.1
|
|
SELF=${BASH_SOURCE[0]}
|
|
SELF_FILENAME=$(basename "$SELF")
|
|
SELF_INSTALLED=/usr/local/bin/$SELF_FILENAME
|
|
ETC=/etc/forgejo-runner
|
|
LIB=/var/lib/forgejo-runner
|
|
LOG=/var/log/forgejo-runner
|
|
LOCK=/var/lock/forgejo-runner
|
|
: ${HOST:=$(hostname)}
|
|
|
|
LXC_IPV4_PREFIX="10.105.7"
|
|
LXC_IPV6_PREFIX="fd91"
|
|
LXC_USER_NAME=debian
|
|
LXC_USER_ID=1000
|
|
|
|
if ${VERBOSE:-false}; then
|
|
set -ex
|
|
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
|
# export LXC_VERBOSE=true # use with caution, it will block .forgejo/workflows/example-lxc-systemd.yml
|
|
else
|
|
set -e
|
|
fi
|
|
|
|
if test $(id -u) != 0; then
|
|
SUDO=sudo
|
|
fi
|
|
|
|
function config_inotify() {
|
|
if grep --quiet fs.inotify.max_user_instances=8192 /etc/sysctl.conf; then
|
|
return
|
|
fi
|
|
echo fs.inotify.max_user_instances=8192 | $SUDO tee -a /etc/sysctl.conf
|
|
$SUDO sysctl -p
|
|
}
|
|
|
|
function install_or_update_lxc_helpers() {
|
|
for lxc_helper in lxc-helpers.sh lxc-helpers-lib.sh; do
|
|
local new=$TMPDIR/$lxc_helper
|
|
local existing=/usr/local/bin/$lxc_helper
|
|
curl --fail -sS -o $new https://code.forgejo.org/forgejo/lxc-helpers/raw/tag/v${INPUTS_LXC_HELPERS_VERSION}/$lxc_helper
|
|
if ! test -f $existing || ! cmp --quiet $existing $new; then
|
|
if test -f $existing; then
|
|
$SUDO mv $existing $existing.backup
|
|
fi
|
|
$SUDO mv $new $existing
|
|
$SUDO chmod +x $existing
|
|
fi
|
|
done
|
|
}
|
|
|
|
function install_or_update_self() {
|
|
if ! cmp --quiet $SELF $SELF_INSTALLED; then
|
|
if test -f $SELF_INSTALLED; then
|
|
$SUDO mv $SELF_INSTALLED $SELF_INSTALLED.backup
|
|
fi
|
|
$SUDO cp -a $SELF $SELF_INSTALLED
|
|
fi
|
|
}
|
|
|
|
function install_self() {
|
|
install_or_update_self
|
|
}
|
|
|
|
function dependencies() {
|
|
if ! which curl jq retry >/dev/null; then
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
$SUDO apt-get update -qq
|
|
$SUDO apt-get install -y -qq curl jq retry
|
|
fi
|
|
if ! which yq >/dev/null; then
|
|
$SUDO curl -L --fail -sS -o /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm64
|
|
$SUDO chmod +x /usr/local/bin/yq
|
|
fi
|
|
install_self
|
|
install_or_update_lxc_helpers
|
|
if ! which lxc-ls >/dev/null; then
|
|
$SUDO lxc-helpers.sh lxc_install_lxc_inside $LXC_IPV4_PREFIX $LXC_IPV6_PREFIX
|
|
fi
|
|
}
|
|
|
|
function lxc_name() {
|
|
echo runner-${INPUTS_SERIAL}-lxc
|
|
}
|
|
|
|
function lxc_destroy() {
|
|
$SUDO lxc-destroy -f $(lxc_name) >/dev/null || true
|
|
}
|
|
|
|
function lxc_create() {
|
|
local name=$(lxc_name)
|
|
local lib=$LIB/$name
|
|
local etc=$ETC/$INPUTS_SERIAL
|
|
|
|
lxc-helpers.sh --config "$INPUTS_LXC_CONFIG" lxc_container_create $name
|
|
echo "lxc.start.auto = 1" | sudo tee -a /var/lib/lxc/$name/config
|
|
|
|
local bin=/var/lib/lxc/$name/rootfs/usr/local/bin
|
|
$SUDO cp -a $SELF $bin/$SELF_FILENAME
|
|
$SUDO cp -a /usr/local/bin/forgejo-runner-$INPUTS_RUNNER_VERSION $bin/forgejo-runner
|
|
$SUDO cp -a /usr/local/bin/yq $bin/yq
|
|
$SUDO cp -a $(which jq) $bin/jq
|
|
|
|
$SUDO mkdir -p $lib/.cache/actcache
|
|
$SUDO chown -R $LXC_USER_ID $lib
|
|
lxc-helpers.sh lxc_container_mount $name $lib/.cache/actcache
|
|
|
|
$SUDO mkdir -p $etc
|
|
$SUDO chown -R $LXC_USER_ID $etc
|
|
lxc-helpers.sh lxc_container_mount $name $etc
|
|
|
|
lxc-helpers.sh lxc_container_start $name
|
|
if echo $INPUTS_LXC_CONFIG | grep --quiet 'docker'; then
|
|
lxc-helpers.sh lxc_install_docker $name
|
|
fi
|
|
if echo $INPUTS_LXC_CONFIG | grep --quiet 'lxc'; then
|
|
local ipv4="10.48.$INPUTS_SERIAL"
|
|
local ipv6="fd$INPUTS_SERIAL"
|
|
lxc-helpers.sh lxc_install_lxc $name $ipv4 $ipv6
|
|
fi
|
|
lxc-helpers.sh lxc_container_user_install $name $LXC_USER_ID $LXC_USER_NAME
|
|
}
|
|
|
|
function service_create() {
|
|
cat >$TMPDIR/forgejo-runner@.service <<EOF
|
|
[Unit]
|
|
Description=Forgejo runner %i
|
|
After=syslog.target
|
|
After=network.target
|
|
|
|
[Service]
|
|
Restart=on-success
|
|
ExecStart=/usr/local/bin/${SELF_FILENAME} run_in_copy start
|
|
ExecStop=/usr/local/bin/${SELF_FILENAME} stop
|
|
TimeoutStopSec=10800
|
|
EnvironmentFile=/etc/forgejo-runner/%i/env
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
local service=/etc/systemd/system/forgejo-runner@.service
|
|
if test -f $service && cmp $TMPDIR/forgejo-runner@.service $service; then
|
|
return
|
|
fi
|
|
|
|
$SUDO mkdir -p $ETC
|
|
$SUDO chown -R $LXC_USER_ID $ETC
|
|
|
|
$SUDO mkdir -p $LOG
|
|
$SUDO chown -R $LXC_USER_ID $LOG
|
|
|
|
$SUDO cp $TMPDIR/forgejo-runner@.service $service
|
|
$SUDO systemctl daemon-reload
|
|
}
|
|
|
|
function inside() {
|
|
local name=$(lxc_name)
|
|
|
|
# all exported variables must be --unset before running the daemon
|
|
lxc-helpers.sh lxc_container_run $name -- sudo --user $LXC_USER_NAME \
|
|
INPUTS_SERIAL="$INPUTS_SERIAL" \
|
|
INPUTS_LXC_CONFIG="$INPUTS_LXC_CONFIG" \
|
|
INPUTS_TOKEN="$INPUTS_TOKEN" \
|
|
INPUTS_FORGEJO="$INPUTS_FORGEJO" \
|
|
INPUTS_LIFETIME="$INPUTS_LIFETIME" \
|
|
KILL_AFTER="$KILL_AFTER" \
|
|
VERBOSE="$VERBOSE" \
|
|
HOST="$HOST" \
|
|
$SELF_FILENAME "$@"
|
|
}
|
|
|
|
function display_default_runner_version() {
|
|
echo "Forgejo runner $INPUTS_RUNNER_VERSION"
|
|
}
|
|
|
|
function install_runner() {
|
|
local runner=/usr/local/bin/forgejo-runner-$INPUTS_RUNNER_VERSION
|
|
if test -f $runner; then
|
|
return
|
|
fi
|
|
|
|
$SUDO curl --fail -sS -o $runner https://code.forgejo.org/forgejo/runner/releases/download/v$INPUTS_RUNNER_VERSION/forgejo-runner-$INPUTS_RUNNER_VERSION-linux-amd64
|
|
$SUDO chmod +x $runner
|
|
}
|
|
|
|
function ensure_configuration() {
|
|
if test -z "$INPUTS_SERIAL"; then
|
|
echo "the INPUTS_SERIAL environment variable is not set"
|
|
return 1
|
|
fi
|
|
|
|
local etc=$ETC/$INPUTS_SERIAL
|
|
$SUDO mkdir -p $etc
|
|
|
|
if test -f $etc/config; then
|
|
INPUTS_LXC_CONFIG=$(cat $etc/config)
|
|
else
|
|
echo $INPUTS_LXC_CONFIG >$etc/config
|
|
fi
|
|
|
|
$SUDO mkdir -p $LIB/$(lxc_name)/.cache/actcache
|
|
}
|
|
|
|
function ensure_configuration_and_registration() {
|
|
local etc=$ETC/$INPUTS_SERIAL
|
|
|
|
if ! test -f $etc/config.yml; then
|
|
forgejo-runner generate-config >$etc/config.yml
|
|
cat >$TMPDIR/edit-config <<EOF
|
|
.runner.labels = ["docker:docker://data.forgejo.org/oci/node:${NODEJS_VERSION}-${DEBIAN_RELEASE}","lxc:lxc://debian:${DEBIAN_RELEASE}"]
|
|
EOF
|
|
yq --inplace --from-file $TMPDIR/edit-config $etc/config.yml
|
|
cat >$TMPDIR/edit-config <<EOF
|
|
.cache.dir = "/var/lib/forgejo-runner/runner-${INPUTS_SERIAL}-lxc/.cache/actcache"
|
|
EOF
|
|
yq --inplace --from-file $TMPDIR/edit-config $etc/config.yml
|
|
|
|
fi
|
|
|
|
if ! test -f $etc/env; then
|
|
cat >$etc/env <<EOF
|
|
INPUTS_LXC_CONFIG=$INPUTS_LXC_CONFIG
|
|
INPUTS_SERIAL=$INPUTS_SERIAL
|
|
INPUTS_LIFETIME=$INPUTS_LIFETIME
|
|
INPUTS_FORGEJO=$INPUTS_FORGEJO
|
|
EOF
|
|
fi
|
|
|
|
if test -f $etc/.runner; then
|
|
return
|
|
fi
|
|
if test -z "$INPUTS_TOKEN"; then
|
|
echo "the INPUTS_TOKEN environment variable is not set"
|
|
return 1
|
|
fi
|
|
(
|
|
cd $etc
|
|
forgejo-runner register --config config.yml --no-interactive \
|
|
--token "$INPUTS_TOKEN" \
|
|
--name "$HOST-$INPUTS_SERIAL" \
|
|
--instance $INPUTS_FORGEJO
|
|
)
|
|
}
|
|
|
|
function daemon() {
|
|
cd $ETC/$INPUTS_SERIAL
|
|
rm -f stopped-* killed-*
|
|
touch started-running
|
|
set +e
|
|
timeout --signal=SIGINT --kill-after=$KILL_AFTER $INPUTS_LIFETIME env \
|
|
--unset INPUTS_SERIAL \
|
|
--unset INPUTS_LXC_CONFIG \
|
|
--unset INPUTS_TOKEN \
|
|
--unset INPUTS_FORGEJO \
|
|
--unset INPUTS_LIFETIME \
|
|
--unset KILL_AFTER \
|
|
--unset VERBOSE \
|
|
--unset HOST \
|
|
/usr/local/bin/forgejo-runner --config config.yml daemon
|
|
case $? in
|
|
0) touch stopped-gracefully ;;
|
|
124) touch stopped-timeout ;;
|
|
137) touch stopped-forcefully ;;
|
|
esac
|
|
set -e
|
|
}
|
|
|
|
function destroy_and_create() {
|
|
stop || true
|
|
lxc-helpers.sh lxc_container_destroy $(lxc_name)
|
|
lxc_create
|
|
}
|
|
|
|
function start() {
|
|
# it should be more than
|
|
# (time it takes for one runner to be recreated) * (number of runners)
|
|
# because they will all start at the same time on boot
|
|
local timeout=3600
|
|
|
|
flock --timeout $timeout $LOCK $SELF destroy_and_create
|
|
|
|
local log=$LOG/$INPUTS_SERIAL.log
|
|
if test -f $log; then
|
|
mv $log $log.backup
|
|
fi
|
|
inside daemon >&$log
|
|
}
|
|
|
|
function kill_runner() {
|
|
cd $ETC/$INPUTS_SERIAL
|
|
rm -f killed-* started-running
|
|
|
|
set +e
|
|
pkill --exact forgejo-runner
|
|
if test $? = 1; then
|
|
touch killed-already
|
|
return
|
|
fi
|
|
|
|
timeout $KILL_AFTER pidwait --exact forgejo-runner
|
|
status=$?
|
|
set -e
|
|
|
|
# pidwait will exit 1 if the process is already gone
|
|
# pidwait will exit 0 if the process terminated gracefully before the timeout
|
|
if test $status = 0 || test $status = 1; then
|
|
touch killed-gracefully
|
|
echo "forgejo-runner stopped gracefully"
|
|
else
|
|
pkill --exact --signal=KILL forgejo-runner
|
|
touch killed-forcefully
|
|
echo "forgejo-runner stopped forcefully"
|
|
fi
|
|
}
|
|
|
|
function stop() {
|
|
inside kill_runner
|
|
}
|
|
|
|
function main() {
|
|
config_inotify
|
|
dependencies
|
|
install_runner
|
|
service_create
|
|
lxc_create
|
|
inside ensure_configuration_and_registration
|
|
}
|
|
|
|
function upgrade() {
|
|
run_in_copy upgrade_safely "$@"
|
|
}
|
|
|
|
function upgrade_safely() {
|
|
local url="$1"
|
|
|
|
local upgrade_dir=$TMPDIR/upgrades
|
|
mkdir -p $TMPDIR/upgrades
|
|
local upgrade="$upgrade_dir/$SELF_FILENAME"
|
|
|
|
curl --fail -sS -o $upgrade $url
|
|
chmod +x $upgrade
|
|
$upgrade install_runner
|
|
$upgrade display_default_runner_version
|
|
$upgrade install_or_update_lxc_helpers
|
|
$upgrade install_or_update_self
|
|
}
|
|
|
|
#
|
|
# ensure an update of the current script does not break a long
|
|
# running function (such as `start`) by running from a copy instead
|
|
# of the script itself
|
|
#
|
|
function run_in_copy() {
|
|
if test "$#" = 0; then
|
|
echo "run_in_copy needs an argument"
|
|
return 1
|
|
fi
|
|
|
|
export TMPDIR # otherwise it will not be removed by trap
|
|
cp $SELF $TMPDIR/$SELF_FILENAME
|
|
exec $TMPDIR/$SELF_FILENAME "$@"
|
|
}
|
|
|
|
"${@:-main}"
|