Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchayan721 committed Aug 29, 2023
1 parent 4fe8e95 commit 96d4c77
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ jobs:
# Calculate Docker cache size in bytes
CACHE_SIZE=$(docker images --filter "dangling=true" -q --no-trunc | xargs -r docker inspect --format='{{.Size}}' | awk '{s+=$1} END {print s}')
# Calculate Docker images size in bytes
IMAGES_SIZE=$(docker images -q --no-trunc | xargs -r docker inspect --format='{{.Size}}' | awk '{s+=$1} END {print s}')
# Convert 40MB to bytes (40 * 1024 * 1024)
CACHE_LIMIT=41943040
# Convert 1GB to bytes (1 * 1024 * 1024 * 1024)
IMAGES_LIMIT=1073741824
# Check if cache size exceeds the limit and prune if necessary
if [ "$CACHE_SIZE" -gt "$CACHE_LIMIT" ]; then
echo "Cache size exceeded 40MB. Cleaning..."
Expand All @@ -48,15 +42,21 @@ jobs:
echo "Cache size is within limit."
fi
# Check if images size exceeds the limit and delete oldest images if necessary
# Calculate Docker images size in bytes
IMAGES_SIZE=$(docker images -q --no-trunc | xargs -r docker inspect --format='{{.Size}}' | awk '{s+=$1} END {print s}')
# Convert 1GB to bytes (1 * 1024 * 1024 * 1024)
IMAGES_LIMIT=1073741824
# Check if image size exceeds the limit and delete oldest images if necessary
if [ "$IMAGES_SIZE" -gt "$IMAGES_LIMIT" ]; then
echo "Images size exceeded 10GB. Deleting oldest images until size is below limit..."
docker images --format '{{.ID}} {{.Created}}' | sort -k2 | awk '{print $1}' | while read -r image_id; do
echo "Images size exceeded 1GB. Deleting oldest images until size is below limit..."
for img in $(docker images --format '{{.ID}} {{.CreatedAt}}' | sort -k2 | awk '{print $1}'); do
docker rmi $img
IMAGES_SIZE=$(docker images -q --no-trunc | xargs -r docker inspect --format='{{.Size}}' | awk '{s+=$1} END {print s}')
if [ "$IMAGES_SIZE" -le "$IMAGES_LIMIT" ]; then
break
fi
docker rmi -f $image_id
IMAGES_SIZE=$(docker images -q --no-trunc | xargs -r docker inspect --format='{{.Size}}' | awk '{s+=$1} END {print s}')
done
else
echo "Images size is within limit."
Expand Down

0 comments on commit 96d4c77

Please sign in to comment.