Files
simple-object-server/clear-cache.sh
Your Name 50160b8d6c
Some checks failed
Build-Test-Publish / build (push) Has been cancelled
'Generic Commit'
2025-06-14 22:31:44 +12:00

59 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
echo "🧹 Clearing build caches for simple-object-server"
# Function to show what we're doing
function title() {
echo "----------------------------------------"
local text="$1"
local line_length=40
local text_length=${#text}
local padding=$(( (line_length - text_length) / 2 ))
printf "%*s%s%*s\n" $padding "" "$text" $padding ""
echo "----------------------------------------"
}
# Remove local output directory
if [ -d "${SCRIPT_DIR}/output" ]; then
title "Removing local output directory"
rm -rf "${SCRIPT_DIR}/output"
echo "✅ Removed ${SCRIPT_DIR}/output"
else
echo " No local output directory to remove"
fi
# Clear Docker build cache for our project
title "Clearing Docker BuildKit cache"
# Remove any existing builder and recreate it (this clears cache)
PROJECT="simple-object-server"
docker buildx rm ${PROJECT}-multiarch 2>/dev/null || true
echo "✅ Removed Docker buildx builder"
# Prune Docker build cache
docker buildx prune -f
echo "✅ Pruned Docker BuildKit cache"
# Clear Docker system cache (more aggressive)
title "Clearing Docker system cache"
docker system prune -f
echo "✅ Pruned Docker system cache"
# Optional: Clear all Docker build cache (very aggressive)
read -p "🚨 Clear ALL Docker build cache? This affects all projects (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker builder prune -af
echo "✅ Cleared ALL Docker build cache"
else
echo " Skipped clearing all Docker build cache"
fi
title "Cache clearing complete"
echo "🎉 All caches have been cleared!"
echo ""
echo "Next build will be from scratch but subsequent builds will be fast again."