Reclaim docker disk space on CI during build

Attempt to fix disk space issues by removing large docker images
after they have been used.

See gh-42776
This commit is contained in:
Phillip Webb
2024-10-17 13:40:57 -07:00
parent 71380e0233
commit f269a19448
2 changed files with 47 additions and 3 deletions

17
.github/scripts/reclaim-docker-diskspace.sh vendored Executable file
View File

@@ -0,0 +1,17 @@
echo "Reclaiming Docker Disk Space"
echo
docker image ls --format "{{.Size}} {{.ID}}" | LANG=en_US sort -rh | while read line; do
size=$( echo "$line" | cut -d' ' -f1 | sed -e 's/\.[0-9]*//' | sed -e 's/MB/000000/' | sed -e 's/MB/000000000/' )
if [ $size -gt 200000000 ]; then
image=$( echo "$line" | cut -d' ' -f2 )
docker image rm -f $image
fi
done
echo "Finished cleanup, leaving the following containers:"
echo
docker image ls --format "{{.Size}} {{.ID}} {{.Repository}}:{{.Tag}}" | LANG=en_US sort -rh
echo
df -h
echo