Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Delete untagged Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Mar 25, 2024
1 parent 081780d commit 162f20c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/remove-untagged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Remove untagged container images

on:
workflow_dispatch:

jobs:
remove-untagged:
runs-on: ubuntu-latest
env:
PER_PAGE: 100
steps:
- name: Delete untagged images
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.request("GET /orgs/${{ github.repository_owner }}/packages/container/${{ vars.DOCKER_IMAGE_NAME }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
for(version of response.data) {
if (version.metadata.container.tags.length == 0 && version.name !== "latest" && version.name !== "preview") {
console.log("Delete " + version.id)
const deleteResponse = await github.request("DELETE /orgs/${{ github.repository_owner }}/packages/container/${{ vars.DOCKER_IMAGE_NAME }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}

0 comments on commit 162f20c

Please sign in to comment.