diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 7f36e3e..9e519bc 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -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 @@ -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: @@ -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: @@ -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 "" @@ -94,7 +96,7 @@ 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 @@ -102,7 +104,7 @@ jobs: 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 @@ -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."