fix(deploy): keep VM103's disk from filling with images and build cache
Every CI build and deploy left a 1.2 GB image of this app on the VM and the build cache kept growing, until the root disk was full and apt in CI failed. After a good deploy update.sh keeps the running image, the previous one and the three newest; the publish job prunes build cache older than two days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b6b179525
commit
7131ca9b12
2 files changed
+19
No files matched your search
@@ -53,3 +53,5 @@ jobs:
|
||||
# Push only these refs: the daemon is the VM's, so `--all-tags` would also push the local :rollback tag from update.sh.
|
||||
for ref in "${refs[@]}"; do docker push "${ref}"; done
|
||||
docker logout "${REGISTRY}"
|
||||
# Builds run on the VM's daemon: without this its build cache grows until the disk is full.
|
||||
docker builder prune -f --filter until=48h >/dev/null 2>&1 || true
|
||||
@@ -15,6 +15,7 @@ cd "${DEPLOY_DIR:-$script_dir}"
|
||||
image_repo=git.mariuszpacek.pl/mariusz.pacek/homelab-upgrade
|
||||
healthy_timeout=${HEALTHY_TIMEOUT:-90}
|
||||
backups_kept=${BACKUPS_KEPT:-5}
|
||||
images_kept=${IMAGES_KEPT:-3}
|
||||
|
||||
tag_arg=""
|
||||
force=0
|
||||
@@ -91,6 +92,21 @@ restore_compose() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Each CI build and each deploy leaves an image of this app on the VM (over a gigabyte each), and a full disk stops
|
||||
# every app on it. Kept: the one running, the previous one (to go back) and the newest $images_kept; a failure here
|
||||
# never fails the deploy.
|
||||
prune_images() {
|
||||
local running id count=0
|
||||
running=$(docker inspect --format '{{.Image}}' "$(service_container server)" 2>/dev/null || true)
|
||||
# `docker images` lists the newest first; an image with several tags appears once per tag.
|
||||
for id in $(docker images --no-trunc --format '{{.ID}}' "$image_repo" | awk '!seen[$0]++'); do
|
||||
count=$((count + 1))
|
||||
[[ "$id" == "$running" || "$id" == "$previous_image" ]] && continue
|
||||
((count <= images_kept)) && continue
|
||||
docker image rm -f "$id" >/dev/null 2>&1 || true
|
||||
done
|
||||
}
|
||||
|
||||
wait_until_up() {
|
||||
local deadline=$((SECONDS + healthy_timeout)) status
|
||||
while ((SECONDS < deadline)); do
|
||||
@@ -149,6 +165,7 @@ if wait_until_up; then
|
||||
{ grep -v '^TAG=' .env || true; printf 'TAG=%s\n' "$tag"; } > .env.new && chmod --reference=.env .env.new && mv .env.new .env
|
||||
fi
|
||||
revision=$(docker inspect --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$(service_container server)")
|
||||
prune_images
|
||||
echo "ok: $image_repo:$tag revision ${revision:-unknown}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user