-
Notifications
You must be signed in to change notification settings - Fork 40.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reclaim docker disk space on CI during build
Attempt to fix disk space issues by removing large docker images after they have been used. This commit backports commits from `3.4.x` that were applied to test the changes. Closes gh-42776
- Loading branch information
Showing
2 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
echo "Reclaiming Docker Disk Space" | ||
echo | ||
|
||
docker image ls --format "{{.Size}} {{.ID}} {{.Repository}} {{.Tag}}" | 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/GB/000000000/' ) | ||
image=$( echo "$line" | cut -d' ' -f2 ) | ||
repository=$( echo "$line" | cut -d' ' -f3 ) | ||
tag=$( echo "$line" | cut -d' ' -f4 ) | ||
echo "Considering $image $repository:$tag $size" | ||
if [[ "$tag" =~ ^[a-f0-9]{32}$ ]]; then | ||
echo "Ignoring GitHub action image $image $repository:$tag" | ||
elif [[ "$tag" == "<none>" ]]; then | ||
echo "Ignoring untagged image $image $repository:$tag" | ||
elif [[ "$size" -lt 200000000 ]]; then | ||
echo "Ignoring small image $image $repository:$tag" | ||
else | ||
echo "Cleaning $image $repository:$tag" | ||
docker image rm $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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters