Skip to content

Commit

Permalink
Create a simple GHA that cleanup untagged devx-container daily
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka authored Mar 29, 2024
1 parent 6049c0f commit f173ba6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Delete Untagged GHCR Containers

on:
schedule:
# Runs at 00:00 UTC every day
- cron: '0 0 * * *'

jobs:
cleanup-untagged-containers:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up GitHub CLI
uses: actions/setup-cli@v2

- name: Authenticate with GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token

- name: List and Delete Untagged Containers
env:
GHCR_PACKAGE_NAME: devx-devcontainer
OWNER: input-output-hk
run: |
untagged_images=$(gh api -X GET /user/packages/container/$GHCR_PACKAGE_NAME/versions --paginate --jq '.[] | select(.metadata.container.tags | length == 0) | .id')
for image_id in $untagged_images; do
echo "Deleting untagged container image with ID: $image_id"
gh api -X DELETE /user/packages/container/$GHCR_PACKAGE_NAME/versions/$image_id
done

0 comments on commit f173ba6

Please sign in to comment.