fix(register_gitea_runner): update instance directory handling and token retrieval
treefmt / nix fmt (pull_request) Successful in 3s
test ebook search / test-ebook-search (pull_request) Successful in 1m22s
build_systems / prebuild-common-x86-64-v3 (pull_request) Successful in 39s
build_systems / build-brain (pull_request) Failing after 1m50s
build_systems / build-jeeves (pull_request) Successful in 2m20s
build_systems / build-portal-1 (pull_request) Successful in 41s
build_systems / build-rhapsody-in-green (pull_request) Successful in 1m20s
build_systems / build-bob (pull_request) Failing after 14m17s
treefmt / nix fmt (pull_request) Successful in 3s
test ebook search / test-ebook-search (pull_request) Successful in 1m22s
build_systems / prebuild-common-x86-64-v3 (pull_request) Successful in 39s
build_systems / build-brain (pull_request) Failing after 1m50s
build_systems / build-jeeves (pull_request) Successful in 2m20s
build_systems / build-portal-1 (pull_request) Successful in 41s
build_systems / build-rhapsody-in-green (pull_request) Successful in 1m20s
build_systems / build-bob (pull_request) Failing after 14m17s
This commit is contained in:
1 parent
385bdd9896
commit
06ee507fa7
1 file changed
+23
-6
@@ -1,21 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
legacy_instance_dir="$STATE_DIRECTORY/$(hostname)"
|
||||
instance_dir="$STATE_DIRECTORY/$1"
|
||||
# Newer runner modules export INSTANCE_DIR and multiple colon-separated state paths.
|
||||
instance_dir="${INSTANCE_DIR:-${STATE_DIRECTORY%%:*}/$1}"
|
||||
legacy_instance_dir="$(dirname "$instance_dir")/$(hostname)"
|
||||
runner_url="$2"
|
||||
runner_config_file="$3"
|
||||
shift 3
|
||||
runner_labels="$(IFS=,; printf '%s' "$*")"
|
||||
|
||||
if [ ! -e "$instance_dir" ] && [ -d "$legacy_instance_dir" ]; then
|
||||
mv "$legacy_instance_dir" "$instance_dir"
|
||||
if [ "$legacy_instance_dir" != "$instance_dir" ] && [ -d "$legacy_instance_dir" ]; then
|
||||
# systemd may have already created an empty instance directory.
|
||||
if [ ! -e "$instance_dir" ] || rmdir "$instance_dir" 2>/dev/null; then
|
||||
mv "$legacy_instance_dir" "$instance_dir"
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -vp "$instance_dir"
|
||||
cd "$instance_dir" || exit 1
|
||||
|
||||
# Newer modules use LoadCredential; older ones export TOKEN via EnvironmentFile.
|
||||
runner_token="${TOKEN:-}"
|
||||
if [ -n "${CREDENTIALS_DIRECTORY:-}" ]; then
|
||||
runner_token="$(cat "$CREDENTIALS_DIRECTORY/token")"
|
||||
# Keep accepting the legacy TOKEN= format as well as a raw token.
|
||||
while IFS= read -r token_line; do
|
||||
if [[ "$token_line" =~ ^[[:space:]]*TOKEN= ]]; then
|
||||
runner_token="${token_line#*=}"
|
||||
fi
|
||||
done <<< "$runner_token"
|
||||
fi
|
||||
: "${runner_token:?Runner registration token is missing}"
|
||||
|
||||
token_hash_file="$instance_dir/.token-hash"
|
||||
token_hash_current="$(printf '%s' "$TOKEN" | sha256sum | cut -d' ' -f1)"
|
||||
token_hash_current="$(printf '%s' "$runner_token" | sha256sum | cut -d' ' -f1)"
|
||||
token_hash_stored="$(cat "$token_hash_file" 2>/dev/null || echo "")"
|
||||
labels_file="$instance_dir/.labels"
|
||||
labels_wanted="$(printf '%s\n' "$@" | sort)"
|
||||
@@ -26,7 +43,7 @@ if [ ! -e "$instance_dir/.runner" ] || [ "$labels_wanted" != "$labels_current" ]
|
||||
|
||||
gitea-runner register --no-interactive \
|
||||
--instance "$runner_url" \
|
||||
--token "$TOKEN" \
|
||||
--token "$runner_token" \
|
||||
--name "jeeves-$(hostname)" \
|
||||
--labels "$runner_labels" \
|
||||
--config "$runner_config_file"
|
||||
|
||||
Reference in new issue
Block a user