This document explains how our GitHub Actions workflows manage Docker images to prevent GHCR from getting cluttered with development images.
- Main branch:
latest+ version tag (e.g.,0.1.0) - Develop branch:
developtag - Pull Requests:
pr-{number}tag (e.g.,pr-123) - Feature branches:
{branch-name}tag (e.g.,feature-awesome-feature)
Optimization: Skips building images for draft PRs to reduce unnecessary builds.
- Trigger: When a PR is closed (merged or rejected)
- Action: Automatically deletes the
pr-{number}image - Benefit: No manual intervention needed
- Trigger: When a branch is deleted
- Action: Automatically deletes the corresponding branch image
- Benefit: Keeps registry clean when feature work is complete
- Trigger: Every Sunday at 2 AM UTC
- Action: Deletes development images older than 7 days
- Protected: Never deletes
latestor version-tagged images - Configurable: Can be adjusted via workflow dispatch
- Trigger: Manual workflow dispatch
- Options:
days_old: How old images should be before deletion (default: 7)tag_pattern: Which tag pattern to clean (default:pr-*)
The cleanup workflows will NEVER delete:
latesttag- Version tags (e.g.,
1.0.0,2.1.3) - Images newer than the specified age threshold
# Images that WILL be cleaned up (after 7 days):
ghcr.io/imaging-plaza/git-metadata-extractor:pr-123
ghcr.io/imaging-plaza/git-metadata-extractor:feature-new-api
ghcr.io/imaging-plaza/git-metadata-extractor:develop # if older than 7 days
# Images that will NEVER be cleaned up:
ghcr.io/imaging-plaza/git-metadata-extractor:latest
ghcr.io/imaging-plaza/git-metadata-extractor:0.1.0
ghcr.io/imaging-plaza/git-metadata-extractor:1.2.3- Go to Actions tab in GitHub
- Select "Cleanup Development Images"
- Click "Run workflow"
- Set
days_oldto3andtag_patterntopr-*
- Same as above
- Set
tag_patterntofeature-*
- Same as above
- Set
tag_patterntodevelop
- 🚀 Automatic: No manual intervention required for normal workflow
- 💾 Space-efficient: Prevents GHCR storage from growing indefinitely
- 🔒 Safe: Protected images are never accidentally deleted
- ⚙️ Configurable: Can adjust retention policies as needed
- 🎯 Targeted: Can clean specific types of images when needed
You can monitor the cleanup by:
- Checking the Actions tab for cleanup workflow runs
- Looking at your GHCR package page to see active images
- The cleanup logs show exactly what was deleted
To adjust the cleanup behavior:
Edit cleanup_images.yaml line with default: '7' to your preferred number of days.
Edit the cron expression in cleanup_images.yaml:
schedule:
- cron: '0 2 * * 0' # Weekly on Sunday at 2 AMModify the hasProtectedTag logic in the cleanup script to protect additional tag patterns.