Files
Febe/.gitea/scripts/versioni-registro.js
T
Alby96andClaude Opus 5.5 086b603801 Immagine: un manifest semplice, così togliere una :sha- libera gli strati
Con il builder docker-container buildx aggiunge da sé l'attestazione di
provenienza, e l'immagine spinta sul registro è un indice. Gitea tiene
ogni manifest figlio come una versione a sé, sha256:… senza etichetta,
con la configurazione e gli strati: la pulizia del lunedì toglieva solo
l'indice delle :sha- vecchie e gli strati restavano per sempre, mentre i
documenti dicevano che il registro si alleggeriva (rilievo della
revisione, controllato sul codice di Gitea release/v28).

costruisci-immagine.sh costruisce con --provenance=false --sbom=false,
sia l'archivio provato sia l'immagine spinta: ogni etichetta è un
manifest semplice che tiene i suoi strati, e quando nessuna versione li
usa più li cancella la pulizia notturna dei pacchetti di Gitea. Le
versioni sha256:… lo script non le tocca mai, perché l'API non dice se
un indice le rimanda, ma ne scrive il numero, anche nella prova
(versioni-registro.js senza-etichetta); docs/processo.md dice quale
regola di pulizia di Gitea le toglie se compaiono. La CI non ha ancora
pubblicato nulla, perché manca REGISTRY_TOKEN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:38:53 +02:00

83 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
// Chooses the tags to remove from Gitea's container registry (pulizia-docker.sh, mode «completa»). It only reads the
// files it is given: no network, no writes, so it is tested with a JSON file.
//
// node versioni-registro.js <how many to keep> <page.json>...
// node versioni-registro.js senza-etichetta <page.json>...
//
// Each file is a page of the answer of GET /api/v1/packages/{owner}/container/febe of Gitea 28: a list of versions with
// «type», «name», «version» and «created_at» (an empty page may be «[]» or «null»). Only the versions of the container
// package «febe» count, and a version found in two pages counts once. Both forms print, oldest first and one per line,
// «version<TAB>created».
//
// With a number N: the sha-<7 to 40 hex digits> tags beyond the N newest by creation date. Everything else always
// stays: main, latest, the X.Y.Z releases (X.Y.Z-rc.N too), the digests (sha256:…), any other tag and a sha- tag
// without a date that can be read.
//
// With «senza-etichetta»: the untagged versions, sha256:<64 hex digits>. They are the manifests of an image index,
// which Gitea keeps as versions of their own with the configuration and the layers; nothing here removes them (Gitea
// cannot be asked through this API whether a tag still uses one), the cleanup only says how many there are.
//
// If a file is not a JSON list it exits with 2 and prints nothing: when in doubt nothing is removed.
// Messages are in Italian, like every message of the CI.
const fs = require("fs");
const [mode, ...pages] = process.argv.slice(2);
const untagged = mode === "senza-etichetta";
if (!(untagged || /^[0-9]+$/.test(mode || "")) || pages.length === 0) {
console.error("Uso: node versioni-registro.js <quante tenere> | senza-etichetta <pagina.json>...");
process.exit(2);
}
const shaTag = /^sha-[0-9a-f]{7,40}$/;
const digest = /^sha256:[0-9a-f]{64}$/;
const versions = new Map();
for (const file of pages) {
let page;
try {
page = JSON.parse(fs.readFileSync(file, "utf8").replace(/^/, ""));
} catch (error) {
console.error(`${file}: ${error.message}`);
process.exit(2);
}
if (page === null) {
continue;
}
if (!Array.isArray(page)) {
console.error(`${file}: non è un elenco di versioni`);
process.exit(2);
}
for (const version of page) {
if (version && version.type === "container" && version.name === "febe" && typeof version.version === "string") {
versions.set(version.version, version);
}
}
}
const dated = (version) => ({
name: version.version,
created: String(version.created_at),
time: Date.parse(version.created_at),
id: Number(version.id) || 0,
});
let chosen;
if (untagged) {
chosen = [...versions.values()]
.filter((version) => digest.test(version.version))
.map(dated)
.sort((a, b) => (Number.isFinite(a.time) ? a.time : 0) - (Number.isFinite(b.time) ? b.time : 0) || a.id - b.id);
} else {
chosen = [...versions.values()]
.filter((version) => shaTag.test(version.version))
.map(dated)
.filter((version) => Number.isFinite(version.time))
.sort((a, b) => b.time - a.time || b.id - a.id)
.slice(Number(mode))
.reverse();
}
for (const version of chosen) {
process.stdout.write(`${version.name}\t${version.created}\n`);
}