Skip to content

Commit

Permalink
Add scheduled workflow to clean untagged images
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartleeks committed Jun 6, 2022
1 parent ee724ac commit b6087b5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/clean_untagged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e


image_names=(
"devcontainer-build-run-devcontainer"
"devcontainer-build-run/tests/run-args"
"devcontainer-build-run/tests/build-args"
"devcontainer-build-run/tests/dockerfile-context"
"devcontainer-build-run/tests/feature-docker-from-docker"
"devcontainer-build-run/tests/docker-from-docker-non-root"
"devcontainer-build-run/tests/docker-from-docker-root"
"devcontainer-build-run/tests/skip-user-update"
)

for image_name in ${image_names[@]};
do
echo "Checking for untagged versions for $image_name"
escaped_image_name=$(echo ${image_name} | sed "s/\//%2f/g")
version_ids=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/users/stuartleeks/packages/container/$escaped_image_name/versions?per_page=100" | jq -r ".[] | select(.metadata.container.tags | length ==0) | .id")
for version_id in ${version_ids[@]};
do
echo -e "\tDeleting version '$version_id' for '$image_name:$tag' ..."
curl -s -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/users/stuartleeks/packages/container/$escaped_image_name/versions/$version_id"
done
done
23 changes: 23 additions & 0 deletions .github/workflows/untagged-image-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: untagged_image_cleanup

on: # yamllint disable-line rule:truthy
schedule:
- cron: "4 18 * * *"
workflow_dispatch:

jobs:

clean_images:
name:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Clean untagged GitHub container images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
./.github/workflows/clean_untagged.sh

0 comments on commit b6087b5

Please sign in to comment.