Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
tags:
- 'v*'
workflow_dispatch:
schedule:
- cron: '0 3 * * 0' # weekly cleanup on Sundays 03:00 UTC

env:
REGISTRY: ghcr.io
Expand All @@ -32,7 +34,7 @@ jobs:
- name: 🏗️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# -------------------- GHCR --------------------
# ---------- GHCR ----------
- name: 🔑 Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -57,7 +59,7 @@ jobs:
- name: 🧹 Cleanup local images
run: docker image prune -af || true

# -------------------- Docker Hub --------------------
# ---------- Docker Hub ----------
- name: 🐳 Log in to Docker Hub
uses: docker/login-action@v3
with:
Expand All @@ -79,7 +81,7 @@ jobs:
org.opencontainers.image.description=RetroIPTVGuide Flask + SQLite Web App
org.opencontainers.image.licenses=CC-BY-NC-SA-4.0

# -------------------- Post-Build Summary --------------------
# ---------- Summary ----------
- name: 🧾 Post-build summary
run: |
echo ""
Expand All @@ -94,15 +96,15 @@ jobs:
echo "🔗 GHCR: https://github.com/thehack904?tab=packages&repo_name=RetroIPTVGuide"
echo ""

# -------------------- GHCR Cleanup --------------------
# ---------- GHCR Cleanup ----------
cleanup-ghcr:
name: 🧽 Cleanup old GHCR images
runs-on: ubuntu-latest
needs: build-and-push
permissions:
packages: write
steps:
- name: 🧹 Delete old GHCR package versions (keep last 5)
- name: 🧹 Delete old GHCR package versions (keep 5)
uses: actions/delete-package-versions@v5
with:
owner: thehack904
Expand All @@ -113,4 +115,31 @@ jobs:
continue-on-error: true

- name: 🧾 Summary
run: echo "✅ GHCR cleanup complete — kept last 5 image versions (including latest)."
run: echo "✅ GHCR cleanup complete — kept 5 latest versions."

# ---------- Docker Hub Cleanup ----------
cleanup-dockerhub:
name: 🧽 Cleanup old Docker Hub tags
runs-on: ubuntu-latest
needs: build-and-push
env:
USER: thehack904
REPO: retroiptvguide
TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- name: 🧹 Remove old Docker Hub tags (keep 5)
run: |
TAGS=$(curl -s -H "Authorization: Bearer ${TOKEN}" \
"https://hub.docker.com/v2/repositories/${USER}/${REPO}/tags/?page_size=100" \
| jq -r '.results[].name')

COUNT=0
for TAG in $TAGS; do
COUNT=$((COUNT+1))
if [ $COUNT -gt 5 ]; then
echo "🧹 Deleting $TAG ..."
curl -s -X DELETE -H "Authorization: Bearer ${TOKEN}" \
"https://hub.docker.com/v2/repositories/${USER}/${REPO}/tags/${TAG}/" >/dev/null
fi
done
echo "✅ Docker Hub cleanup complete — kept 5 newest tags."