From 14bba3f94b66a17d6b362bc818b01433e2751334 Mon Sep 17 00:00:00 2001 From: Mikhail Yevchenko Date: Mon, 24 Aug 2026 12:24:07 +0300 Subject: [PATCH] Preserve referenced image manifests during cleanup --- .gitea/workflows/publish.yml | 13 ++++++++++++- README.md | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml index 6536128..9d0053a 100644 --- a/.gitea/workflows/publish.yml +++ b/.gitea/workflows/publish.yml @@ -52,11 +52,13 @@ jobs: - name: Remove old image versions env: + BUILD_DIGEST: ${{ needs.build.outputs.digest }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} run: | set -eu command -v jq >/dev/null api='https://gt.uo1.net/api/v1/packages/1movmedia/container/ollama-with-model' + current_manifest=$(docker buildx imagetools inspect "${IMAGE_NAME}:latest" --raw) while :; do response=$(curl --fail --silent --show-error \ --header "Authorization: token ${REGISTRY_TOKEN}" \ @@ -64,9 +66,18 @@ jobs: versions=$(printf '%s\n' "$response" \ | jq --raw-output '.[] | select(.version != "latest") | .version') [ -n "$versions" ] || break - printf '%s\n' "$versions" | while IFS= read -r version; do + deleted=false + for version in $versions; do + if [ "$version" = "$BUILD_DIGEST" ] \ + || printf '%s\n' "$current_manifest" | jq --exit-status \ + --arg version "$version" \ + 'any(.manifests[]?; .digest == $version)' >/dev/null; then + continue + fi curl --fail --silent --show-error --request DELETE \ --header "Authorization: token ${REGISTRY_TOKEN}" \ "${api}/${version}" + deleted=true done + "$deleted" || break done diff --git a/README.md b/README.md index 7a33dd2..2dec3ee 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Building downloads the complete model, so the runner needs enough disk space for ## Publish from Gitea Actions -The workflow in `.gitea/workflows/publish.yml` builds the image by digest, then publishes the `latest` tag in a separate job. After a successful publication, it removes every other version of the image from the Gitea registry. It runs on pushes to `main` and can also be started manually with `workflow_dispatch`. +The workflow in `.gitea/workflows/publish.yml` builds the image by digest, then publishes the `latest` tag in a separate job. After a successful publication, it removes old versions while preserving every manifest referenced by the current image. It runs on pushes to `main` and can also be started manually with `workflow_dispatch`. Configure the following repository Actions variable and secret before running it: