docker-cleanup/.forgejo/workflows/clean.yml
xlionjuan 5948bd86c9
All checks were successful
Clean / fsn-1-hetzner-host (push) Successful in 2s
Clean / hel-1-hetzner-host (push) Successful in 3s
Clean / rog-host (push) Successful in 1s
Update .forgejo/workflows/clean.yml
2026-08-22 23:55:01 +00:00

85 lines
2.1 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Clean
on:
schedule:
- cron: "0 1 * * *"
workflow_dispatch:
push:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
clean:
strategy:
matrix:
job:
- fsn-1-hetzner-host
- hel-1-hetzner-host
- rog-host
runs-on: ${{ matrix.job }}
name: ${{ matrix.job }}
steps:
- name: Show details
run: |
docker ps -a
docker image ls -a --format json | jq
docker network ls
- name: Generic clean
run: |
docker container prune --force
docker volume prune --all --force
docker network prune --force
- name: Clean old Renovate Bot (keep only latest)
run: |
#!/bin/sh
set -eu
REPO="ghcr.io/renovatebot/renovate"
# 取出該 repo 的所有 images
images="$(docker image ls -a --format json | jq -s --arg repo "$REPO" '
map(select(.Repository == $repo))
')"
count="$(printf '%s' "$images" | jq 'length')"
if [ "$count" -eq 0 ]; then
echo "No images found for $REPO. Nothing to do."
exit 0
fi
# 找最新的一張(CreatedAt 最大)
keep_id="$(printf '%s' "$images" | jq -r '
max_by(.CreatedAt) | .ID
')"
echo "Keeping latest $REPO image: $keep_id"
# 找其餘要刪的 IDs
remove_ids="$(printf '%s' "$images" | jq -r '
map(.ID) | unique | map(select(. != "'"$keep_id"'")) | .[]
')"
if [ -z "$remove_ids" ]; then
echo "No older $REPO images to remove."
exit 0
fi
echo "Removing older $REPO images:"
printf ' - %s\n' $remove_ids
docker image rm -f $remove_ids
- name: Show details
run: |
docker ps -a
docker image ls -a --format json | jq
docker network ls