fix/node-modules-named-volumes (#94)
Co-authored-by: openhands <openhands@all-hands.dev> Reviewed-on: https://codeberg.org/johba/harb/pulls/94
This commit is contained in:
parent
19bac420d0
commit
1c6f118f6b
9 changed files with 182 additions and 87 deletions
|
|
@ -11,6 +11,7 @@ readonly PONDER_TIMEOUT=120 # Must index bootstrap events
|
|||
readonly WEBAPP_TIMEOUT=120 # npm install + Vite startup
|
||||
readonly CADDY_TIMEOUT=20 # Proxy starts instantly
|
||||
readonly POLL_INTERVAL=2 # Check health every N seconds
|
||||
readonly MAX_DOCKER_DISK_GB=20 # Maximum Docker disk usage in GB
|
||||
|
||||
PID_FILE=/tmp/kraiken-watcher.pid
|
||||
PROJECT_NAME=${COMPOSE_PROJECT_NAME:-$(basename "$PWD")}
|
||||
|
|
@ -36,6 +37,58 @@ container_name() {
|
|||
echo "${PROJECT_NAME}_${service}_1"
|
||||
}
|
||||
|
||||
# Check Docker disk usage and warn if approaching limits
|
||||
check_docker_disk_usage() {
|
||||
if ! command -v docker &> /dev/null; then
|
||||
return 0 # Skip if Docker not available
|
||||
fi
|
||||
|
||||
# Get total Docker disk usage in GB (works on Linux and macOS)
|
||||
local total_size_bytes
|
||||
total_size_bytes=$(docker system df --format '{{.Size}}' 2>/dev/null | \
|
||||
sed 's/[^0-9.]//g' | awk '{sum+=$1} END {print sum}' || echo "0")
|
||||
|
||||
# Parse the actual usage more accurately
|
||||
local docker_df_output
|
||||
docker_df_output=$(docker system df 2>/dev/null || echo "")
|
||||
|
||||
if [[ -z "$docker_df_output" ]]; then
|
||||
return 0 # Docker not running
|
||||
fi
|
||||
|
||||
# Extract total reclaimable space (more accurate than parsing Size)
|
||||
local total_gb
|
||||
total_gb=$(echo "$docker_df_output" | tail -n 1 | awk '{print $NF}' | sed 's/GB//; s/MB/\/1024/; s/KB/\/1048576/' | bc -l 2>/dev/null || echo "0")
|
||||
|
||||
# Alternative: sum up all TYPE sizes (column 3 has the SIZE)
|
||||
local images_size containers_size volumes_size build_cache_size
|
||||
images_size=$(echo "$docker_df_output" | grep "Images" | awk '{print $3}' | sed 's/GB$//; s/MB$/\/1024/; s/KB$/\/1048576/; s/B$/\/1073741824/' | sed 's/^$/0/' | bc -l 2>/dev/null || echo "0")
|
||||
containers_size=$(echo "$docker_df_output" | grep "Containers" | awk '{print $3}' | sed 's/GB$//; s/MB$/\/1024/; s/KB$/\/1048576/; s/B$/\/1073741824/' | sed 's/^$/0/' | bc -l 2>/dev/null || echo "0")
|
||||
volumes_size=$(echo "$docker_df_output" | grep "Local Volumes" | awk '{print $3}' | sed 's/GB$//; s/MB$/\/1024/; s/KB$/\/1048576/; s/B$/\/1073741824/' | sed 's/^$/0/' | bc -l 2>/dev/null || echo "0")
|
||||
build_cache_size=$(echo "$docker_df_output" | grep "Build Cache" | awk '{print $3}' | sed 's/GB$//; s/MB$/\/1024/; s/KB$/\/1048576/; s/B$/\/1073741824/' | sed 's/^$/0/' | bc -l 2>/dev/null || echo "0")
|
||||
|
||||
total_gb=$(echo "$images_size + $containers_size + $volumes_size + $build_cache_size" | bc -l 2>/dev/null || echo "0")
|
||||
|
||||
# Round to 1 decimal place
|
||||
total_gb=$(printf "%.1f" "$total_gb" 2>/dev/null || echo "0")
|
||||
|
||||
echo " Docker disk usage: ${total_gb}GB / ${MAX_DOCKER_DISK_GB}GB limit"
|
||||
|
||||
# Warn if approaching 80% of limit (16GB)
|
||||
if (( $(echo "$total_gb > 16" | bc -l 2>/dev/null || echo "0") )); then
|
||||
echo " [!!] WARNING: Docker disk usage is high!"
|
||||
echo " [!!] Run './scripts/cleanup-disk.sh' to free up space"
|
||||
fi
|
||||
|
||||
# Hard stop if over limit
|
||||
if (( $(echo "$total_gb > $MAX_DOCKER_DISK_GB" | bc -l 2>/dev/null || echo "0") )); then
|
||||
echo ""
|
||||
echo "ERROR: Docker disk usage exceeds ${MAX_DOCKER_DISK_GB}GB limit!"
|
||||
echo "Run './scripts/cleanup-disk.sh' to free up space, then try again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup_existing() {
|
||||
# Kill any existing watch scripts
|
||||
pkill -f "watch-kraiken-lib.sh" 2>/dev/null || true
|
||||
|
|
@ -101,6 +154,9 @@ wait_for_exited() {
|
|||
start_stack() {
|
||||
local stack_start_time=$(date +%s)
|
||||
|
||||
# Check Docker disk usage before starting
|
||||
check_docker_disk_usage
|
||||
|
||||
# Clean up any existing processes first
|
||||
cleanup_existing
|
||||
|
||||
|
|
@ -163,9 +219,14 @@ stop_stack() {
|
|||
cleanup_existing
|
||||
${COMPOSE_CMD} down
|
||||
|
||||
# Prune Docker resources to prevent disk bloat
|
||||
echo " Pruning Docker resources..."
|
||||
${RUNTIME_CMD} system prune -f --volumes 2>&1 | grep -E "Total reclaimed|deleted" || true
|
||||
# Aggressive pruning to prevent disk bloat
|
||||
echo " Pruning Docker resources (images, containers, volumes, build cache)..."
|
||||
|
||||
# Prune build cache aggressively (this is usually the biggest culprit)
|
||||
${RUNTIME_CMD} builder prune -af 2>&1 | grep -E "Total|deleted" || true
|
||||
|
||||
# Prune all unused data (containers, networks, images, volumes)
|
||||
${RUNTIME_CMD} system prune -af --volumes 2>&1 | grep -E "Total reclaimed|deleted" || true
|
||||
|
||||
echo "[ok] Stack stopped and cleaned"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue