Files
operating-room-monitor-server/backend/scripts/rebuild-api-image.sh
2026-05-27 16:22:55 +08:00

31 lines
915 B
Bash
Executable File

#!/usr/bin/env bash
# Clear BuildKit cache and rebuild the API image.
# Fixes export errors such as:
# archive/tar: invalid tar header
# unpigz: corrupted -- invalid deflate data
set -euo pipefail
cd "$(dirname "$0")/.."
echo "Pruning BuildKit cache..."
docker builder prune -af
docker buildx prune -af 2>/dev/null || true
docker rmi -f backend-api:latest 2>/dev/null || true
if [[ "${AGGRESSIVE_PRUNE:-0}" == "1" ]]; then
echo "Aggressive prune (dangling images + build cache)..."
docker system prune -af 2>/dev/null || true
fi
if [[ "${RESTART_DOCKER:-0}" == "1" ]]; then
echo "Restarting Docker..."
sudo systemctl restart docker
sleep 2
fi
echo "Building api image (--no-cache, no attestations)..."
export DOCKER_BUILDKIT=1
export COMPOSE_BAKE=false
docker compose build api --no-cache --provenance=false --sbom=false
echo "Done. Recreate container: docker compose up -d --force-recreate api"