Alberto, 21/10: la pulizia della CI deve eliminare tutto quello che non serve più, non solo ciò che la CI di Febe ha creato. pulizia-docker.sh ha due modi nuovi. «penzolanti»: le immagini senza nome e la cache di costruzione che nessuna immagine condivide, di tutti i progetti; un errore è solo un avviso. «completa»: i resti della CI di Febe come prima, i resti di act_runner (contenitori fermi, volumi e reti GITEA-ACTIONS-TASK-… che nessuno usa), le immagini che nessun contenitore usa e la cache più vecchie di 24 ore, e con REGISTRY_TOKEN le etichette sha- del registro oltre le 10 più recenti. Mai system, container, volume o network prune, mai un contenitore, un volume o una rete che non sia della CI. Con --prova ogni modo elenca che cosa toglierebbe e non tocca nulla. Le etichette del registro le sceglie versioni-registro.js, che si prova con un JSON e senza rete; controlli.sh ne controlla la sintassi. Le prove girano contro un docker e un curl finti, su un demone come quello del runner: applicazioni di Unraid ferme, un Febe vero, il lavoro della pulizia stessa, resti veri e finti di act_runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.4 KiB
Bash
64 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
# A fake curl for PipelineTests: the registry part of .gitea/scripts/pulizia-docker.sh talks to the packages API of
|
|
# Gitea 28 through it. No network. It knows only the options the cleanup uses and answers like Gitea:
|
|
# GET <base>?page=<n>&limit=50 the page $FAKE_CURL_WORLD/page-<n>.json, or [] after the last one (200)
|
|
# DELETE <base>/<version> 204, and the version is written to $FAKE_CURL_WORLD/deleted
|
|
# where <base> is the content of $FAKE_CURL_WORLD/base (…/api/v1/packages/<owner>/container/febe). Without the header
|
|
# «Authorization: token <content of $FAKE_CURL_WORLD/token>» it answers 401; with $FAKE_CURL_WORLD/refuse it answers
|
|
# 403 to every call; any other address is 404. Every call goes to $FAKE_CURL_WORLD/calls as «METHOD URL», never with
|
|
# its headers. Any other option is an error (exit 3).
|
|
set -uo pipefail
|
|
|
|
world="${FAKE_CURL_WORLD:?}"
|
|
token="$(cat "$world/token" 2> /dev/null)"
|
|
method=GET output="" write="" url="" authorized=0
|
|
while (($#)); do
|
|
case "$1" in
|
|
-s | -S | -sS) ;;
|
|
--max-time) shift ;;
|
|
-X) method="$2"; shift ;;
|
|
-H) [[ -n "$token" && "$2" == "Authorization: token $token" ]] && authorized=1; shift ;;
|
|
-o) output="$2"; shift ;;
|
|
-w) write="$2"; shift ;;
|
|
-*) echo "fake curl: unexpected option $1" >&2; exit 3 ;;
|
|
*)
|
|
[[ -z "$url" ]] || { echo "fake curl: a second address $1" >&2; exit 3; }
|
|
url="$1"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
printf '%s %s\n' "$method" "$url" >> "$world/calls"
|
|
[[ -z "$write" || "$write" == '%{http_code}' ]] || { echo "fake curl: unexpected -w $write" >&2; exit 3; }
|
|
|
|
answer() {
|
|
local code="$1" body="${2:-}"
|
|
if [[ -n "$output" ]]; then
|
|
printf '%s' "$body" > "$output"
|
|
else
|
|
printf '%s' "$body"
|
|
fi
|
|
[[ -z "$write" ]] || printf '%s' "$code"
|
|
exit 0
|
|
}
|
|
|
|
[[ -f "$world/refuse" ]] && answer 403 '{"message":"token does not have at least one of required scope(s): [write:package]"}'
|
|
((authorized)) || answer 401 '{"message":"token is required"}'
|
|
|
|
base="$(cat "$world/base")"
|
|
case "$method $url" in
|
|
"GET $base?page="*"&limit=50")
|
|
page="${url#"$base?page="}"
|
|
page="${page%%&*}"
|
|
if [[ -f "$world/page-$page.json" ]]; then
|
|
answer 200 "$(cat "$world/page-$page.json")"
|
|
fi
|
|
answer 200 "[]"
|
|
;;
|
|
"DELETE $base/"*)
|
|
echo "${url#"$base/"}" >> "$world/deleted"
|
|
answer 204
|
|
;;
|
|
*) answer 404 '{"message":"The target couldn'"'"'t be found."}' ;;
|
|
esac
|