Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peterstolz/containercrop
A simple Github Action to delete unwanted container images.
https://github.com/peterstolz/containercrop
Last synced: 8 days ago
JSON representation
A simple Github Action to delete unwanted container images.
- Host: GitHub
- URL: https://github.com/peterstolz/containercrop
- Owner: PeterStolz
- Created: 2024-03-29T10:10:26.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-03T08:24:43.000Z (7 months ago)
- Last Synced: 2024-10-13T18:42:16.531Z (23 days ago)
- Language: Python
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ContainerCrop Action
The `ContainerCrop` GitHub Action allows you to delete unwanted GitHub Container Registry (GHCR) images directly from your CI workflows. It offers a flexible way to manage your container images by specifying criteria such as cut-off date, and tag filtering.
## Inputs
- `image-name`: **Required** The name of the image you want to delete.
- `cut-off`: **Required** The cut-off date for deleting images older than this date. Must include a timezone, e.g., '2 days ago UTC'.
- `token`: **Required** A personal access token with read and delete scopes.
- `untagged-only`: Restrict deletions to images without tags. Default: `false`.
- `skip-tags`: Restrict deletions to images without specific tags. Supports Unix-shell style wildcards.
- `keep-at-least`: How many matching images to keep, regardless of other conditions. Default: `0`.
- `filter-tags`: Comma-separated list of tags to consider for deletion. Supports Unix-shell style wildcards.
- `dry-run`: If set to `true`, the action will not actually delete images. Instead, it will print out what would have been deleted. Default: `false`.## Example Usage
Here is an example workflow that uses the `ContainerCrop` action to delete images:
```yaml
name: Clean Up Container Registryon:
schedule:
- cron: '0 0 * * *' # Runs every day at midnightjobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete untagged images older than 30 days
uses: peterstolz/[email protected]
with:
image-name: 'your-image-name'
cut-off: '30 days ago UTC'
token: ${{ secrets.GITHUB_TOKEN }}
untagged-only: 'true'
keep-at-least: '5'
dry-run: 'true'
```If you have multiple images you can use the matrix strategy to apply the same policies to them:
```yaml
jobs:
delete-images:
runs-on: ubuntu-latest
strategy:
matrix:
image: [container1, container2, container3, container4]
steps:
- name: Delete old tagged images older than one week keeping 7
uses: peterstolz/[email protected]
with:
image-name: my-repo-name/${{ matrix.image }}
cut-off: 'a week ago UTC'
token: ${{ secrets.YOUR_TOKEN }}
filter-tags: "*.*.*"
keep-at-least: '7'
dry-run: 'true'- name: Delete all untagged images older than 2 days
uses: peterstolz/[email protected]
with:
image-name: my-repo-name/${{ matrix.image }}
cut-off: 'two days ago UTC'
token: ${{ secrets.YOUR_TOKEN }}
untagged-only: 'true'
dry-run: 'true'```
## Notes
- Ensure that the `token` provided has the necessary permissions to read and delete container images.
- The `cut-off` input is crucial for determining which images are considered "old" and eligible for deletion.
- Use the `dry-run` option to safely check what would be deleted before performing actual deletions.For more detailed information, refer to the test cases in `./containercrop/test_retention.py`