diff --git a/setup-gitea-runner.sh b/setup-gitea-runner.sh index 43318c8..47fe94b 100755 --- a/setup-gitea-runner.sh +++ b/setup-gitea-runner.sh @@ -4,7 +4,7 @@ set -Eeuo pipefail GITEA_URL="${GITEA_URL:-http://38.76.196.225:10099/}" GITEA_REPOSITORY="${GITEA_REPOSITORY:-awaioi/ERP}" -RUNNER_IMAGE="${RUNNER_IMAGE:-gitea/runner:3.0.2}" +RUNNER_IMAGE="${RUNNER_IMAGE:-}" RUNNER_CONTAINER="${RUNNER_CONTAINER:-gitea-runner}" RUNNER_VOLUME="${RUNNER_VOLUME:-gitea-runner-data}" RUNNER_LABELS="${RUNNER_LABELS:-ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest}" @@ -46,6 +46,32 @@ find_gitea_container() { return 1 } +pull_runner_image() { + local candidate + local -a candidates + + if [[ -n "$RUNNER_IMAGE" ]]; then + candidates=("$RUNNER_IMAGE") + else + candidates=( + "docker.gitea.com/runner:3.0.2" + "docker.gitea.com/act_runner:3.0.2" + "gitea/runner:3.0.2" + ) + fi + + for candidate in "${candidates[@]}"; do + log "Pulling $candidate" + if docker pull "$candidate"; then + RUNNER_IMAGE="$candidate" + return 0 + fi + log "Image source failed; trying the next source" + done + + fail "all official Gitea Runner image sources failed" +} + GITEA_CONTAINER="$(find_gitea_container || true)" [[ -n "$GITEA_CONTAINER" ]] || fail "no running Gitea container was found" @@ -72,8 +98,7 @@ fi [[ -s "$TOKEN_FILE" ]] || fail "Gitea returned an empty runner token" chmod 600 "$TOKEN_FILE" -log "Pulling $RUNNER_IMAGE" -docker pull "$RUNNER_IMAGE" +pull_runner_image docker rm -f "$RUNNER_CONTAINER" >/dev/null 2>&1 || true docker volume create "$RUNNER_VOLUME" >/dev/null docker run --rm --entrypoint /bin/rm \