diff --git a/.gitea/scripts/ambiente-prove.sh b/.gitea/scripts/ambiente-prove.sh index ee56ff6..83760dd 100755 --- a/.gitea/scripts/ambiente-prove.sh +++ b/.gitea/scripts/ambiente-prove.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash -# Prepara il contenitore Debian del lavoro «prove» (debian:trixie, Debian 13 senza nient'altro: nessuna azione -# JavaScript, quindi niente Node) perché nessuna prova si salti: Chromium vero della distribuzione (su Ubuntu è uno -# snap, che nei contenitori non va) con le sue lingue, Xvfb, la lingua it_IT.UTF-8, fusi orari e gli stessi caratteri -# dell'immagine di Febe; ICU, OpenSSL, zlib e libstdc++ per l'SDK .NET (dotnet.sh). git, curl e i certificati li -# installa il passo prima dei sorgenti. setpriv, getent e l'utente nobody (65534) vengono con Debian (prove -# dell'avvio del contenitore). +# Prepares the Debian container of the «prove» job (debian:trixie, plain Debian 13: no JavaScript action, hence no +# Node) so that no test is skipped: the distribution's real Chromium (on Ubuntu it is a snap, which does not work in +# containers) with its languages, Xvfb, the it_IT.UTF-8 locale, time zones and the same fonts as the Febe image; ICU, +# OpenSSL, zlib and libstdc++ for the .NET SDK (dotnet.sh). git, curl and the certificates are installed by the step +# before the sources. setpriv, getent and the nobody user (65534) come with Debian (tests of the container start). # # .gitea/scripts/ambiente-prove.sh set -euo pipefail diff --git a/.gitea/scripts/artefatti.sh b/.gitea/scripts/artefatti.sh index c3a2274..bd689e6 100644 --- a/.gitea/scripts/artefatti.sh +++ b/.gitea/scripts/artefatti.sh @@ -1,20 +1,20 @@ #!/usr/bin/env bash -# Artefatti della CI, al posto di actions/upload-artifact (un'azione JavaScript, che vuole Node): i file vanno nel -# registro dei pacchetti di Gitea, pacchetto generico febe-ci, una versione per esecuzione: +# CI artifacts, instead of actions/upload-artifact (a JavaScript action, which needs Node): the files go to the Gitea +# package registry, generic package febe-ci, one version per run: # -# -ci. dal flusso verifica (come Febe-Setup--ci..exe) -# -rilascio. dal flusso rilascio +# -ci. from the verifica workflow (like Febe-Setup--ci..exe) +# -rilascio. from the rilascio workflow # -# con da Directory.Build.props e il numero dell'esecuzione (NUMERO). Si scaricano dalla pagina del -# pacchetto su Gitea (proprietario ▸ Pacchetti ▸ febe-ci). La pulizia del lunedì (pulizia-docker.sh completa) toglie le -# versioni create più di 14 giorni prima, come faceva la scadenza degli artefatti. +# with from Directory.Build.props and the run number (NUMERO). They are downloaded from the package +# page on Gitea (owner ▸ Packages ▸ febe-ci). The Monday cleanup (full pulizia-docker.sh) removes the versions created +# more than 14 days earlier, as the artifact expiry used to do. # # .gitea/scripts/artefatti.sh verifica|rilascio ... # -# Variabili: REGISTRY_TOKEN (token con «package: read and write», solo nell'intestazione di curl, mai stampato), GITEA_URL -# (l'indirizzo del server, gitea.server_url), PROPRIETARIO, NUMERO. Senza REGISTRY_TOKEN un avviso e nessun file -# caricato: il lavoro resta verde, come per l'immagine. Un file che manca o un rifiuto del registro fanno fallire il -# passo. Un file con lo stesso nome già caricato (un nuovo tentativo della stessa esecuzione) si sostituisce. +# Variables: REGISTRY_TOKEN (token with «package: read and write», only in the curl header, never printed), GITEA_URL +# (the server address, gitea.server_url), PROPRIETARIO, NUMERO. Without REGISTRY_TOKEN a warning and no file uploaded: +# the job stays green, as for the image. A missing file or a refusal by the registry fails the step. A file with the +# same name already uploaded (a new attempt of the same run) is replaced. set -euo pipefail flusso="${1:-}" @@ -46,7 +46,7 @@ proprietario="${PROPRIETARIO:?Manca PROPRIETARIO.}" base="${GITEA_URL:?Manca GITEA_URL.}" base="${base%/}/api/packages/$proprietario/generic/febe-ci/$versione" -# Una chiamata al registro: il codice HTTP, 000 se Gitea non risponde. Il token sta solo nell'intestazione di curl. +# One call to the registry: the HTTP code, 000 if Gitea does not answer. The token is only in the curl header. chiedi() { local codice codice=$(curl -sS --max-time 900 -H "Authorization: token $REGISTRY_TOKEN" -o /dev/null -w '%{http_code}' "$@") || true diff --git a/.gitea/scripts/controlli.sh b/.gitea/scripts/controlli.sh index 10de5cd..86af27b 100755 --- a/.gitea/scripts/controlli.sh +++ b/.gitea/scripts/controlli.sh @@ -1,18 +1,18 @@ #!/usr/bin/env bash -# Controlli veloci prima di compilare (lavoro «controlli» della CI): pochi secondi, e fermano subito gli errori che -# altrimenti si scoprirebbero dopo mezz'ora di prove. Si lanciano anche a mano, dalla radice del repository: +# Quick checks before building (the «controlli» job of the CI): a few seconds, and they stop at once the errors that +# would otherwise be found after half an hour of tests. They can also be run by hand, from the repository root: # # bash .gitea/scripts/controlli.sh # -# 1. ogni script di shell del repository è sintassi valida (bash -n; sh -n per quelli in sh) e ha le righe Unix, come -# i programmi awk della CI; -# 2. i flussi della CI si leggono come YAML a blocchi: niente tabulazioni né righe Windows, rientri di due spazi fuori -# dai blocchi di testo, «on:» e «jobs:» presenti; e sono fatti solo di comandi: nessun «uses:», cioè nessuna -# azione (le azioni JavaScript vogliono Node, e la CI di Febe è scritta in casa: decisione del 18 novembre 2026); -# 3. nessun file contiene segni di conflitto rimasti da un'unione; -# 4. la versione di Directory.Build.props è nella forma x.y.z[-qualcosa], quella che installer/costruisci.sh accetta; -# 5. ogni progetto elencato in Febe.slnx esiste; -# 6. ogni file JSON del repository si legge (configurazioni, campioni ripuliti, criteri di Chromium), con json.awk. +# 1. every shell script of the repository is valid syntax (bash -n; sh -n for the sh ones) and has Unix line +# endings, like the awk programs of the CI; +# 2. the CI workflows read as block YAML: no tabs nor Windows line endings, two-space indentation outside text +# blocks, «on:» and «jobs:» present; and they are made of commands only: no «uses:», that is no action +# (JavaScript actions need Node, and the Febe CI is written in house: decision of 18 November 2026); +# 3. no file contains conflict markers left over from a merge; +# 4. the version in Directory.Build.props has the form x.y.z[-something], the one installer/costruisci.sh accepts; +# 5. every project listed in Febe.slnx exists; +# 6. every JSON file of the repository parses (configurations, cleaned samples, Chromium policies), with json.awk. set -uo pipefail radice="$(git rev-parse --show-toplevel)" || exit 2 @@ -51,8 +51,8 @@ while IFS= read -r -d '' flusso; do if grep -n $'\t' "$flusso" > /dev/null; then errore "$flusso contiene tabulazioni: in YAML il rientro si fa con gli spazi." fi - # Un blocco di testo («run: |», «>-») tiene tutte le righe più rientrate della sua chiave; fuori, i rientri sono di - # due spazi in due e nessuna riga chiama un'azione. + # A text block («run: |», «>-») holds all the lines indented more than its key; outside, indentation goes two + # spaces at a time and no line calls an action. if rilievi=$(awk ' FNR == 1 { blocco = -1; on = 0; jobs = 0 } { @@ -104,7 +104,7 @@ done < <(sed -n 's:.* 0)); then if ! guasti=$(awk -f .gitea/scripts/json.awk -f .gitea/scripts/json-valido.awk "${json[@]}"); then diff --git a/.gitea/scripts/costruisci-immagine.sh b/.gitea/scripts/costruisci-immagine.sh index 4c71e0e..d9acc06 100755 --- a/.gitea/scripts/costruisci-immagine.sh +++ b/.gitea/scripts/costruisci-immagine.sh @@ -1,29 +1,29 @@ #!/usr/bin/env bash -# Costruzione dell'immagine Docker di Febe con il builder buildx dell'esecuzione (docker-container), sempre con gli -# stessi argomenti e le stesse etichette: la costruzione che si pubblica esce intera dalla cache di quella che si è -# provata e scansionata, quindi gli strati sono gli stessi. +# Builds the Febe Docker image with the buildx builder of the run (docker-container), always with the same arguments +# and the same labels: the build that is published comes entirely from the cache of the one that was tested and +# scanned, so the layers are the same. # -# costruisci-immagine.sh builder il builder buildx dell'esecuzione (BUILDER), con il -# driver docker-container e la configurazione di -# buildkit che dice che il registro di casa risponde in -# HTTP (al posto di docker/setup-buildx-action, un'azione -# JavaScript); lo toglie pulizia-docker.sh esecuzione -# costruisci-immagine.sh archivio archivio dell'immagine, per docker load e per Trivy -# costruisci-immagine.sh pubblica ... spinta sul registro REGISTRY da buildx, con -# REGISTRO_UTENTE e REGISTRO_TOKEN in una configurazione -# del client solo sua, tolta alla fine; il demone non -# parla mai con il registro (proverebbe HTTPS) +# costruisci-immagine.sh builder the buildx builder of the run (BUILDER), with the +# docker-container driver and the buildkit configuration +# that says the home registry answers in HTTP (instead +# of docker/setup-buildx-action, a JavaScript action); +# pulizia-docker.sh esecuzione removes it +# costruisci-immagine.sh archivio archive of the image, for docker load and for Trivy +# costruisci-immagine.sh pubblica ... push to the REGISTRY registry by buildx, with +# REGISTRO_UTENTE and REGISTRO_TOKEN in a client +# configuration of its own, removed at the end; the +# daemon never talks to the registry (it would try HTTPS) # -# L'immagine è un manifest semplice, senza attestazioni (--provenance=false --sbom=false). Con le attestazioni, che -# buildx aggiunge da sé, sarebbe un indice: Gitea tiene ogni manifest figlio come una versione a sé, sha256:… senza -# etichetta, con la configurazione e gli strati, e togliere dal registro un'etichetta :sha- toglierebbe solo l'indice. -# Con un manifest semplice gli strati stanno nella versione dell'etichetta, e la pulizia del registro li libera davvero. +# The image is a plain manifest, without attestations (--provenance=false --sbom=false). With the attestations, which +# buildx adds by itself, it would be an index: Gitea keeps every child manifest as a version of its own, sha256:… +# without a tag, with the configuration and the layers, and removing a :sha- tag from the registry would remove only +# the index. With a plain manifest the layers belong to the tag's version, and the registry cleanup really frees them. # -# Variabili richieste: BUILDER, VERSIONE, GIT_COMMIT, FLUSSO (verifica o rilascio), ESECUZIONE (gitea.run_id). -# Le etichette febe.ci.* dicono quale flusso, esecuzione, ramo e commit hanno costruito l'immagine. Non servono alla -# pulizia: stanno anche nelle immagini pubblicate e Docker le copia in ogni contenitore creato da quelle, anche in un -# Febe vero. Per questo qui non si mette mai febe.ci.prova, il segno dei soli contenitori di prova (prova-immagine.sh): -# lo controlla PipelineTests. +# Required variables: BUILDER, VERSIONE, GIT_COMMIT, FLUSSO (verifica or rilascio), ESECUZIONE (gitea.run_id). +# The febe.ci.* labels say which workflow, run, branch and commit built the image. They are not used by the cleanup: +# they are also in the published images and Docker copies them into every container created from those, even in a +# real Febe. That is why febe.ci.prova, the mark of test containers only (prova-immagine.sh), is never set here: +# PipelineTests checks it. set -euo pipefail modo="${1:?Indica il modo: builder, archivio o pubblica.}" @@ -32,11 +32,11 @@ cd "$(git rev-parse --show-toplevel)" if [[ "$modo" == builder ]]; then registro="${1:?Indica il registro, per esempio 192.168.30.23:3000.}" - # Solo un nome di host (o un indirizzo) con la porta: il valore finisce in un file TOML. + # Only a host name (or an address) with the port: the value ends up in a TOML file. [[ "$registro" =~ ^[A-Za-z0-9.-]+(:[0-9]+)?$ ]] || { echo "Registro non valido: «$registro»." >&2; exit 2; } configurazione="${RUNNER_TEMP:-/tmp}/buildkitd-${BUILDER:?}.toml" printf '[registry."%s"]\n http = true\n insecure = true\n' "$registro" > "$configurazione" - # --buildkitd-config da buildx 0.13; prima si chiamava --config. + # --buildkitd-config since buildx 0.13; before, it was called --config. opzione=--buildkitd-config aiuto=$(docker buildx create --help 2> /dev/null) || true [[ "$aiuto" == *--buildkitd-config* ]] || opzione=--config @@ -69,11 +69,11 @@ case "$modo" in etichette+=(-t "$nome") done - # Le credenziali in una configurazione del client tutta nostra, solo per questa spinta e poi tolta: quella del - # runner non si tocca mai (niente jq per modificarla, nessuna credenziale che resti nella sua cartella). buildx le - # passa al builder; il demone non c'entra (proverebbe HTTPS). Del client originale restano i plugin, i contesti e - # il contesto corrente; i builder buildx li trova con BUILDX_CONFIG. Il nome è fisso per l'esecuzione, così il passo - # «Pulizia (sempre)» la toglie anche dopo un'interruzione che salta la trap. + # The credentials in a client configuration entirely our own, only for this push and then removed: the runner's + # one is never touched (no jq to modify it, no credential left in its folder). buildx passes them to the builder; + # the daemon is not involved (it would try HTTPS). From the original client we keep the plugins, the contexts and + # the current context; the buildx builders are found through BUILDX_CONFIG. The name is fixed for the run, so the + # «Pulizia (sempre)» step removes it even after an interruption that skips the trap. originale="${DOCKER_CONFIG:-$HOME/.docker}" configurazione="${RUNNER_TEMP:-/tmp}/febe-docker-${ESECUZIONE}" rm -rf "$configurazione" @@ -88,7 +88,7 @@ case "$modo" in [[ "$contesto" =~ ^[A-Za-z0-9][A-Za-z0-9_.+-]*$ ]] || contesto="" fi credenziali=$(printf '%s:%s' "$REGISTRO_UTENTE" "$REGISTRO_TOKEN" | base64 -w0) - # Solo caratteri di base64, e il registro controllato sopra: il JSON si scrive senza bisogno di escape. + # Only base64 characters, and the registry checked above: the JSON is written without any need for escapes. [[ "$credenziali" =~ ^[A-Za-z0-9+/]+=*$ ]] || { echo "Credenziali del registro non codificabili." >&2; exit 2; } ( umask 077 diff --git a/.gitea/scripts/dotnet.sh b/.gitea/scripts/dotnet.sh index 5f46e48..cd75d0d 100644 --- a/.gitea/scripts/dotnet.sh +++ b/.gitea/scripts/dotnet.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash -# Installa l'SDK .NET per un lavoro della CI, al posto di actions/setup-dotnet (un'azione JavaScript, che vuole Node). -# Come quella prende l'ultimo SDK del canale (predefinito 10.0, come «10.0.x»), ma lo verifica: la versione e -# l'impronta SHA-512 dell'archivio vengono dai metadati dei rilasci di Microsoft (letti con json.awk e dotnet-sdk.awk, -# awk POSIX), l'archivio da builds.dotnet.microsoft.com, e si installa solo se l'impronta coincide. Mai uno script di -# installazione scaricato al volo. +# Installs the .NET SDK for a CI job, instead of actions/setup-dotnet (a JavaScript action, which needs Node). Like +# that action it takes the newest SDK of the channel (default 10.0, like «10.0.x»), but it verifies it: the version +# and the SHA-512 hash of the archive come from Microsoft's release metadata (read with json.awk and dotnet-sdk.awk, +# POSIX awk), the archive from builds.dotnet.microsoft.com, and it is installed only if the hash matches. Never an +# install script downloaded on the fly. # # .gitea/scripts/dotnet.sh [canale] # -# Dove: nella cache degli strumenti del runner (RUNNER_TOOL_CACHE, il volume act-toolcache che act_runner monta in ogni -# lavoro, anche nei contenitori), in febe-dotnet/; senza, nella cartella temporanea del lavoro. Una versione -# già installata e verificata non si riscarica; le versioni più vecchie di febe-dotnet si tolgono. Aggiunge dotnet al -# PATH dei passi seguenti (GITHUB_PATH) e scrive DOTNET_ROOT (GITHUB_ENV); fuori dalla CI stampa solo la cartella. -# Serve curl, tar, sha512sum e awk. Nel contenitore Debian delle prove le librerie di sistema dell'SDK (ICU, OpenSSL) -# le installa ambiente-prove.sh; sull'immagine del runner ICU non è garantito, e i lavori che ci girano (installatore, -# windows, release) usano DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true. +# Where: in the runner's tool cache (RUNNER_TOOL_CACHE, the act-toolcache volume that act_runner mounts in every job, +# containers included), in febe-dotnet/; without it, in the job's temporary folder. A version already +# installed and verified is not downloaded again; older versions in febe-dotnet are removed. Adds dotnet to the PATH +# of the following steps (GITHUB_PATH) and writes DOTNET_ROOT (GITHUB_ENV); outside the CI it only prints the folder. +# Needs curl, tar, sha512sum and awk. In the Debian container of the tests the SDK's system libraries (ICU, OpenSSL) +# are installed by ambiente-prove.sh; on the runner image ICU is not guaranteed, and the jobs that run there +# (installatore, windows, release) use DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true. set -euo pipefail canale="${1:-10.0}" @@ -56,7 +56,7 @@ else mv "$temporanea/sdk" "$cartella" fi -# Le versioni precedenti, che nessun lavoro userà più (la CI fa un lavoro alla volta), e gli scarichi interrotti. +# The earlier versions, which no job will use any more (the CI runs one job at a time), and interrupted downloads. for vecchia in "$radice"/* "$radice"/.scarico-*; do [[ -d "$vecchia" && "$vecchia" != "$cartella" && "$vecchia" != "$temporanea" ]] || continue rm -rf "$vecchia" diff --git a/.gitea/scripts/json.sh b/.gitea/scripts/json.sh index 5676018..1609c80 100644 --- a/.gitea/scripts/json.sh +++ b/.gitea/scripts/json.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash -# JSON per i passi della CI, senza programmi di terzi (niente jq, niente Node; decisione di Alberto del 18 novembre -# 2026): legge con json.awk e json-campi.awk, scrive le stringhe con json-stringa.awk. awk POSIX, niente rete. +# JSON for the CI steps, without third-party programs (no jq, no Node; decision of Alberto of 18 November 2026): +# reads with json.awk and json-campi.awk, writes strings with json-stringa.awk. POSIX awk, no network. # -# json.sh campi ... per ogni oggetto a quel posto, una riga con i campi -# separati da un TAB (json-campi.awk): percorso vuoto -# per l'oggetto radice, «*» per ogni elemento di un -# elenco, per esempio «Results/*/Vulnerabilities/*» -# json.sh stringa il testo come stringa JSON, virgolette comprese +# json.sh campi ... for each object at that place, one line with the fields +# separated by a TAB (json-campi.awk): empty path for +# the root object, «*» for every element of a list, +# for example «Results/*/Vulnerabilities/*» +# json.sh stringa the text as a JSON string, quotes included # -# Un file che non è JSON valido: niente in uscita, il motivo su stderr, uscita 2. Lo provano le PipelineTests. +# A file that is not valid JSON: no output, the reason on stderr, exit status 2. PipelineTests tests it. set -euo pipefail qui="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" diff --git a/.gitea/scripts/prova-immagine.sh b/.gitea/scripts/prova-immagine.sh index e6752d3..7e7577a 100755 --- a/.gitea/scripts/prova-immagine.sh +++ b/.gitea/scripts/prova-immagine.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash -# Prova dell'immagine appena costruita, sul demone Docker del runner. Ogni contenitore gira SENZA RETE -# (--network none): Febe non può raggiungere alcun sito, tanto meno Instagram (regola 1), e il controllo di salute -# passa dalla rete interna del contenitore. -# Ogni contenitore porta l'etichetta febe.ci.prova=, messa qui con «docker run --label» e mai in -# un'immagine: è il segno con cui pulizia-docker.sh riconosce un contenitore di prova, insieme al nome -# febe-prova-. Le etichette febe.ci.* dell'immagine non bastano: Docker le copia in ogni contenitore, anche -# in un Febe vero avviato da un'immagine pubblicata. +# Test of the image just built, on the runner's Docker daemon. Every container runs WITHOUT NETWORK (--network none): +# Febe cannot reach any site, let alone Instagram (rule 1), and the health check goes through the container's +# internal network. +# Every container carries the label febe.ci.prova=, set here with «docker run --label» and never in an +# image: it is the mark by which pulizia-docker.sh recognises a test container, together with the name +# febe-prova-. The febe.ci.* labels of the image are not enough: Docker copies them into every container, +# even into a real Febe started from a published image. # # .gitea/scripts/prova-immagine.sh [esecuzione] # -# 1. Chromium della distribuzione risponde e i criteri di Febe (niente password salvate) sono al loro posto; -# 2. la lingua it_IT.UTF-8 è generata; -# 3. il contenitore parte come dice la guida (profilo seccomp di Febe, password dell'interfaccia, PUID/PGID -# predefiniti), il controllo di salute dell'immagine diventa «healthy» e «febe --controllo-salute» risponde; -# 4. il processo 1 è Febe (niente tini) e nel contenitore non restano processi orfani da raccogliere; -# 5. allo stop si ferma da solo, entro i 30 secondi che la guida concede. -# La password è casuale, vive solo nell'ambiente del client Docker e non si stampa mai. +# 1. the distribution's Chromium answers and the Febe policies (no saved passwords) are in place; +# 2. the it_IT.UTF-8 locale is generated; +# 3. the container starts as the guide says (Febe's seccomp profile, interface password, default PUID/PGID), the +# image's health check becomes «healthy» and «febe --controllo-salute» answers; +# 4. process 1 is Febe (no tini) and no orphan processes are left in the container to be reaped; +# 5. on stop it stops by itself, within the 30 seconds the guide allows. +# The password is random, lives only in the Docker client's environment and is never printed. set -euo pipefail immagine="${1:?Indica quale immagine provare.}" @@ -24,8 +24,8 @@ radice="$(git rev-parse --show-toplevel)" etichette=(--label "febe.ci.prova=$esecuzione") nome="febe-prova-$esecuzione" -# Toglie il contenitore di prova di questa esecuzione (anche quello di un tentativo precedente), ma solo se porta il -# segno della prova: un contenitore con lo stesso nome e senza segno resta, e «docker run --name» si ferma. +# Removes the test container of this run (also the one of an earlier attempt), but only if it carries the test mark: +# a container with the same name and without the mark stays, and «docker run --name» stops. togli() { local segno segno=$(docker container inspect -f '{{index .Config.Labels "febe.ci.prova"}}' "$nome" 2> /dev/null) || return 0 @@ -52,7 +52,7 @@ docker run -d --name "$nome" --network none "${etichette[@]}" \ --stop-timeout 30 -e FEBE_PASSWORD "$immagine" > /dev/null unset FEBE_PASSWORD -# Il primo controllo di salute dell'immagine arriva 30 secondi dopo l'avvio (HEALTHCHECK --interval=30s): fino a 3 minuti. +# The image's first health check comes 30 seconds after the start (HEALTHCHECK --interval=30s): up to 3 minutes. stato="" for _ in $(seq 1 36); do if [[ "$(docker inspect -f '{{.State.Running}}' "$nome")" != "true" ]]; then @@ -77,16 +77,16 @@ fi echo "salute: healthy, e febe --controllo-salute risponde" echo "== Processo 1 e processi orfani" -# Senza tini il processo 1 è Febe, e il runtime .NET da processo 1 raccoglie anche i figli di Chromium rimasti orfani. -# Un processo appena finito può restare «zombie» per un istante: conta solo uno che resta tale per 10 secondi. +# Without tini process 1 is Febe, and the .NET runtime as process 1 also reaps the orphaned children of Chromium. +# A process that has just ended may stay a «zombie» for an instant: only one that stays so for 10 seconds counts. primo="$(docker exec "$nome" cat /proc/1/comm)" if [[ "$primo" != "febe" ]]; then echo "Il processo 1 del contenitore è «$primo» invece di febe. Registro:" >&2 docker logs --tail 80 "$nome" >&2 || true exit 1 fi -# I numeri dei processi zombie figli del processo 1, ordinati: quelli che tocca a lui raccogliere (gli orfani finiscono -# lì). Uno sparito durante la lettura non conta. +# The ids of the zombie processes that are children of process 1, sorted: the ones it has to reap (orphans end up +# there). One that vanishes while being read does not count. orfani_zombie='for f in /proc/[0-9]*/status; do awk '\''$1 == "State:" { z = $2 } $1 == "Pid:" { p = $2 } $1 == "PPid:" { q = $2 } END { if (z == "Z" && q == 1) print p }'\'' "$f" 2> /dev/null done' diff --git a/.gitea/scripts/pulizia-docker.sh b/.gitea/scripts/pulizia-docker.sh index 29c8612..04ac43a 100755 --- a/.gitea/scripts/pulizia-docker.sh +++ b/.gitea/scripts/pulizia-docker.sh @@ -1,71 +1,70 @@ #!/usr/bin/env bash -# Pulizia del demone Docker del runner e del registro dei container. Il demone è lo stesso che costruisce Encelado, -# Mimante e gli altri progetti di Alberto (e molto probabilmente quello delle applicazioni di Unraid), e ci può girare -# anche un Febe vero. Dal 21 ottobre 2026 (decisione di Alberto) la pulizia toglie anche ciò che non serve più a -# nessuno, di qualunque progetto: le immagini che nessun contenitore usa, la cache di costruzione, i resti di -# act_runner. Mai un contenitore, un volume o una rete che non sia della CI. +# Cleanup of the runner's Docker daemon and of the container registry. The daemon is the same one that builds +# Encelado, Mimante and Alberto's other projects (and very probably the one of the Unraid applications), and a real +# Febe may run on it too. Since 21 October 2026 (decision of Alberto) the cleanup also removes what nobody needs any +# more, of any project: the images no container uses, the build cache, the leftovers of act_runner. Never a +# container, a volume or a network that does not belong to the CI. # -# Della CI di Febe si toglie ciò che si può provare suo. Le etichette febe.ci.workflow, febe.ci.run, febe.ci.ref e -# febe.ci.commit dicono da dove viene un'immagine, ma NON scelgono che cosa togliere: stanno anche nelle immagini -# pubblicate (:main, :sha-, :X.Y.Z, :latest), e Docker le copia in ogni contenitore creato da quelle, quindi le porta -# anche un Febe vero. Ciò che si toglie si riconosce così: -# - contenitori di prova: l'etichetta febe.ci.prova=, che mette solo prova-immagine.sh con -# «docker run --label» e che nessuna immagine porta (lo controlla PipelineTests), E il nome esatto -# febe-prova- (gli altri contenitori della prova, senza nome, girano con --rm e Docker li -# toglie da sé appena finiscono); -# - immagini provate: il nome locale febe-ci:, tolto per nome, mai per identificativo e mai con -f. Se la -# stessa immagine ha anche un nome del registro, si toglie solo febe-ci:; se un contenitore la usa, resta; -# - builder buildx: il contenitore buildx_buildkit_febe-ci-0, con l'immagine moby/buildkit, e il suo -# volume …_state, che contengono la cache di costruzione di quell'esecuzione; -# - l'immagine febe:ci lasciata dal vecchio flusso di verifica (prima del 20 ottobre 2026), se nessuno la usa. -# Di act_runner si tolgono i resti dei lavori: act_runner chiama tutto ciò che crea per un lavoro -# GITEA-ACTIONS-TASK-… (il contenitore del lavoro, i suoi volumi e -env, la sua rete -# --network). Solo i contenitori fermi e i volumi e le reti che nessun contenitore usa, più vecchi di 90 -# minuti: un lavoro che parte li crea e li usa subito. Il volume act-toolcache (la cache degli strumenti, condivisa fra -# i lavori) resta. +# Of the Febe CI, what can be proven to be its own is removed. The labels febe.ci.workflow, febe.ci.run, febe.ci.ref +# and febe.ci.commit say where an image comes from, but they do NOT choose what to remove: they are also in the +# published images (:main, :sha-, :X.Y.Z, :latest), and Docker copies them into every container created from those, +# so a real Febe carries them too. What is removed is recognised like this: +# - test containers: the label febe.ci.prova=, which only prova-immagine.sh sets with +# «docker run --label» and which no image carries (PipelineTests checks it), AND the exact name +# febe-prova- (the other test containers, without a name, run with --rm and Docker removes them by +# itself as soon as they end); +# - tested images: the local name febe-ci:, removed by name, never by id and never with -f. If the same +# image also has a registry name, only febe-ci: is removed; if a container uses it, it stays; +# - buildx builders: the container buildx_buildkit_febe-ci-0, with the moby/buildkit image, and its +# …_state volume, which hold the build cache of that run; +# - the febe:ci image left by the old verification workflow (before 20 October 2026), if nobody uses it. +# Of act_runner, the leftovers of the jobs are removed: act_runner names everything it creates for a job +# GITEA-ACTIONS-TASK-… (the job container, its volumes and -env, its network +# --network). Only stopped containers, and volumes and networks no container uses, older than 90 +# minutes: a job that starts creates them and uses them at once. The act-toolcache volume (the tool cache, shared +# among the jobs) stays. # -# pulizia-docker.sh esecuzione tutto ciò che ha creato l'esecuzione (all'inizio e alla fine del suo -# lavoro «immagine», sempre) -# pulizia-docker.sh penzolanti le immagini senza nome che nessun contenitore usa e la cache di costruzione -# penzolante del demone (quella che nessuna immagine condivide) non usata da -# 24 ore, di tutti i progetti (alla fine di ogni lavoro «immagine», dopo -# «esecuzione») -# pulizia-docker.sh residui [minuti] i resti di esecuzioni interrotte, più vecchi di N minuti (predefinito 90: un -# lavoro dura al massimo 60 minuti, quindi nessuno di essi è ancora vivo) -# pulizia-docker.sh settimanale residui, febe:ci, immagini senza nome più vecchie di 72 ore: la pulizia -# stretta di prima del 21 ottobre 2026, ora solo a mano -# pulizia-docker.sh completa residui, febe:ci, resti di act_runner, le immagini che nessun contenitore -# usa create più di 24 ore fa, la cache di costruzione non usata da 24 ore e, -# con REGISTRY_TOKEN, le etichette sha- del registro oltre le 10 più recenti e -# gli artefatti della CI (febe-ci) di più di 14 giorni (flusso «pulizia», ogni -# lunedì e a mano) -# pulizia-docker.sh --prova elenca che cosa toglierebbe e non toglie nulla: solo comandi che leggono -# (sul registro solo GET) +# pulizia-docker.sh esecuzione everything the run created (at the start and at the end of its +# «immagine» job, always) +# pulizia-docker.sh penzolanti the unnamed images no container uses and the daemon's dangling build cache +# (the part no image shares) unused for 24 hours, of all projects (at the end +# of every «immagine» job, after «esecuzione») +# pulizia-docker.sh residui [minuti] the leftovers of interrupted runs, older than N minutes (default 90: a job +# lasts at most 60 minutes, so none of them is still alive) +# pulizia-docker.sh settimanale residui, febe:ci, unnamed images older than 72 hours: the narrow cleanup of +# before 21 October 2026, now only by hand +# pulizia-docker.sh completa residui, febe:ci, act_runner leftovers, the images no container uses +# created more than 24 hours ago, the build cache unused for 24 hours and, +# with REGISTRY_TOKEN, the registry's sha- tags beyond the 10 most recent and +# the CI artifacts (febe-ci) older than 14 days («pulizia» workflow, every +# Monday and by hand) +# pulizia-docker.sh --prova lists what it would remove and removes nothing: only commands that read +# (on the registry only GET) # -# Gli argomenti si controllano tutti prima di toccare Docker: un'opzione diversa da --prova (--dry-run, -n, --Prova) o -# un argomento in più (prova senza trattini) fermano tutto con codice 2, invece di far partire la pulizia vera al posto -# della prova. +# All the arguments are checked before touching Docker: an option other than --prova (--dry-run, -n, --Prova) or an +# extra argument (prova without dashes) stops everything with code 2, instead of starting the real cleanup in place +# of the dry run. # -# Mai docker system prune, container prune, volume prune o network prune; mai image prune -a o builder prune -a senza -# il filtro delle 24 ore; mai un contenitore, un volume o una rete che non sia della CI. Le immagini le toglie Docker -# stesso (image prune), che non toglie mai un'immagine usata da un contenitore, nemmeno fermo; con -a, però, le toglie i -# nomi in più, e lo script li scrive (nella prova li stima, secondo lo store). Sul registro mai main, latest o una -# versione X.Y.Z: solo le etichette sha- della verifica e gli artefatti -ci. e -# -rilascio. del pacchetto generico febe-ci. +# Never docker system prune, container prune, volume prune or network prune; never image prune -a or builder prune -a +# without the 24-hour filter; never a container, a volume or a network that does not belong to the CI. The images are +# removed by Docker itself (image prune), which never removes an image used by a container, not even a stopped one; +# with -a, though, it removes their extra names, and the script writes them out (in the dry run it estimates them, +# depending on the store). On the registry never main, latest or an X.Y.Z version: only the sha- tags of +# the verification and the -ci. and -rilascio. artifacts of the generic febe-ci package. # -# Nei modi «residui», «settimanale» e «completa» un contenitore di prova si toglie solo se è fermo. Uno ancora acceso -# dopo 90 minuti (il suo lavoro è stato ucciso proprio durante la prova del contenitore) resta dov'è: lo si segnala, con -# il comando per toglierlo a mano. I builder sono l'eccezione: sono sempre accesi e la loro cache se ne va solo -# togliendo il contenitore; si riconoscono dal nome esatto e dall'immagine di buildkit, mai da un'etichetta. +# In the «residui», «settimanale» and «completa» modes a test container is removed only if it is stopped. One still +# running after 90 minutes (its job was killed right during the container test) stays where it is: it is reported, +# with the command to remove it by hand. The builders are the exception: they are always running and their cache goes +# away only by removing the container; they are recognised by the exact name and the buildkit image, never by a label. # -# Un oggetto già sparito non è un errore: la pulizia si può ripetere. Nei modi «esecuzione», «penzolanti» e «residui» -# un problema diventa un avviso (un lavoro verde non diventa rosso per la pulizia, che il flusso del lunedì ripete); nei -# modi «settimanale» e «completa» fa fallire il lavoro, perché qualcuno lo guardi. Il registro è l'eccezione: un -# rifiuto della sua API è solo un avviso, e il lunedì dopo si riprova. +# An object already gone is not an error: the cleanup can be repeated. In the «esecuzione», «penzolanti» and «residui» +# modes a problem becomes a warning (a green job does not turn red because of the cleanup, which the Monday workflow +# repeats); in the «settimanale» and «completa» modes it fails the job, so that someone looks at it. The registry is +# the exception: a refusal by its API is only a warning, and the following Monday it is tried again. # -# Variabili per il registro (modo «completa»): REGISTRY_TOKEN (token con «package: read and write», mai stampato), -# GITEA_API (l'API del server, per esempio https://gitea.example/api/v1) e PROPRIETARIO (il proprietario del pacchetto -# febe). La scelta delle versioni da togliere sta in versioni-registro.sh, accanto a questo script. +# Variables for the registry («completa» mode): REGISTRY_TOKEN (token with «package: read and write», never printed), +# GITEA_API (the server's API, for example https://gitea.example/api/v1) and PROPRIETARIO (the owner of the febe +# package). The choice of the versions to remove lives in versioni-registro.sh, next to this script. set -uo pipefail uso() { @@ -93,21 +92,21 @@ esac cartella_script="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" problemi=0 -# In prova: i contenitori (identificativo e nome) e i nomi di immagine che la pulizia vera toglierebbe, perché gli -# elenchi che seguono li trattino come già tolti (un volume usato solo da un contenitore che se ne andrebbe, per -# esempio, se ne andrebbe anche lui). +# In a dry run: the containers (id and name) and the image names the real cleanup would remove, so that the lists +# that follow treat them as already removed (a volume used only by a container that would go away, for example, +# would go away too). previsti=() nomi_previsti=() -# Per il riepilogo: quanti oggetti per tipo, nell'ordine in cui compaiono, e lo spazio recuperato da Docker. +# For the summary: how many objects per kind, in the order they appear, and the space reclaimed by Docker. declare -A conteggi=() tipi=() note=() -# La cache di costruzione che si pota è quella del builder del demone, «default». docker builder è un alias di docker -# buildx quando c'è il plugin, e buildx lavora sul builder corrente: se qualcuno avesse reso corrente il builder -# dell'esecuzione (costruisci-immagine.sh builder non lo fa), il modo «esecuzione» l'avrebbe appena tolto. Gli altri -# comandi buildx di questo script indicano il builder per nome. +# The build cache that is pruned is the one of the daemon's builder, «default». docker builder is an alias of docker +# buildx when the plugin is there, and buildx works on the current builder: if someone had made the run's builder +# current (costruisci-immagine.sh builder does not), the «esecuzione» mode would have just removed it. The other +# buildx commands of this script name the builder explicitly. export BUILDX_BUILDER=default avviso() { @@ -115,7 +114,7 @@ avviso() { problemi=$((problemi + 1)) } -# Un avviso che non fa diventare rosso il lavoro: per il registro. +# A warning that does not turn the job red: for the registry. segnala() { echo "::warning::$*" } @@ -125,7 +124,7 @@ conta() { conteggi[$1]=$((${conteggi[$1]:-0} + 1)) } -# Vero se la prima parola è fra quelle che seguono. +# True if the first word is among the ones that follow. fra() { local cercata="$1" voce shift @@ -135,9 +134,9 @@ fra() { return 1 } -# Minuti trascorsi da un istante RFC 3339 come lo scrive Docker (Created di un contenitore o di un'immagine, CreatedAt -# di un volume, {{json .Created}} di una rete, fra virgolette), con o senza frazioni di secondo, con «Z» o con lo scarto -# dall'ora universale (+02:00). Se non si legge, 0: nel dubbio l'oggetto è giovane e resta. +# Minutes elapsed since an RFC 3339 instant as Docker writes it (Created of a container or an image, CreatedAt of a +# volume, {{json .Created}} of a network, in quotes), with or without fractions of a second, with «Z» or with the +# offset from universal time (+02:00). If it cannot be read, 0: when in doubt the object is young and stays. eta_minuti() { local creato="${1:-}" secondi creato="${creato//\"/}" @@ -158,8 +157,8 @@ durata() { fi } -# Fra i contenitori dati (identificativi, uno per riga), quelli che restano dopo questa pulizia: in prova senza quelli -# che la pulizia vera toglierebbe. +# Among the given containers (ids, one per line), those that remain after this cleanup: in a dry run without the ones +# the real cleanup would remove. restanti() { local id while read -r id; do @@ -168,9 +167,9 @@ restanti() { done <<< "${1:-}" } -# I contenitori di prova della CI, uno per riga «id nome»: l'etichetta febe.ci.prova (dell'esecuzione indicata, o di -# qualunque se il primo argomento è vuoto) e il nome esatto febe-prova-. Gli stati che seguono -# restringono la scelta (Docker li unisce in OR). Esce con 1 se Docker non risponde. +# The CI test containers, one per line «id name»: the label febe.ci.prova (of the given run, or of any run if the +# first argument is empty) and the exact name febe-prova-