Clean Up Old Docker Snapshots
Summary
We should periodically clean up old Docker snapshots
Why do we need this?
Because we don't need to keep every snapshot forever
What is already there? What do you see now?
Every merge to a minor branch (such as v3.10) triggers a snapshot build, and pushes an image to lorawan-stack-dev:<git hash>. These tags accumulate over time.
What is missing? What do you want to see?
We should periodically run a script to delete snapshot tags older than a couple of weeks.
How do you propose to implement this?
On Docker Hub:
- List images (https://docs.docker.com/registry/spec/api/#listing-image-tags)
- Delete images (https://docs.docker.com/registry/spec/api/#deleting-an-image)
GitHub Container Registry currently does not support deleting images through the API (https://docs.github.com/en/free-pro-team@latest/packages/managing-container-images-with-github-container-registry/deleting-a-container-image#about-package-deletion), but I assume that will be supported in the future.
Just did another manual cleanup (but this time from Retool): https://thethingsindustries.retool.com/apps/Docker%20Images
Perhaps we can take that as a starting point for the cleanup tool.
In the meantime this has become a bit easier to do on Docker Hub.
First, we have to install hub-tool:
go install github.com/docker/hub-tool@latest
Then we can clean up old open source development images:
hub-tool tag ls thethingsnetwork/lorawan-stack-dev --all --format json --sort updated=asc \
| jq -r '.[] | select(.LastUpdated < "2022-05-01") | .Name' \
| while read -r name
do
hub-tool tag rm -f $name
done
And the same for enterprise development images (excluding AWS and RC images):
hub-tool tag ls thethingsindustries/lorawan-stack-dev --all --format json --sort updated=asc \
| jq -r '.[] | select(.LastUpdated < "2022-05-01") | select(.Name | contains("-aws") | not) | select(.Name | contains("-rc") | not) | .Name' \
| while read -r name
do
hub-tool tag rm -f $name
done
This may be a nice one for @happyRip to pick up, perhaps with help from @KrishnaIyer or @adriansmares.
The workflow seems pretty simple. You see this as a shell or go tool?
Moved to infrastructure;