Skip to content

Commit 62bde7d

Browse files
Copilotbytestream
andauthored
Remove old Docker image after successful upgrade (#315)
* Initial plan * Add prompt to remove old Docker image after successful upgrade After a successful upgrade, the script now captures the previously installed version and prompts the user to remove the old supportpal/helpdesk image to free disk space. If removal fails, a manual removal command is printed. Closes #314 Co-authored-by: bytestream <1788397+bytestream@users.noreply.github.com> * wip --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bytestream <1788397+bytestream@users.noreply.github.com> Co-authored-by: bytestream <kieran@supportpal.com>
1 parent 420dcf8 commit 62bde7d

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

templates/docker-monolithic/upgrade.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,38 @@ meili_requires_upgrade() {
306306
fi
307307
}
308308

309+
# Removes stale helpdesk images left on disk by previous upgrades.
310+
remove_old_images() {
311+
local cid current_image repo stale image
312+
313+
if ! cid="$(docker compose ps -q supportpal 2>>"$LOG_FILE")" || [ -z "$cid" ]; then
314+
log_debug "Skipping image clean up, unable to determine the supportpal container ID."
315+
return
316+
fi
317+
318+
if ! current_image="$(docker inspect --format '{{.Config.Image}}' "$cid" 2>>"$LOG_FILE")" || [ -z "$current_image" ]; then
319+
log_debug "Skipping image clean up, unable to determine the image of container ${cid}."
320+
return
321+
fi
322+
323+
repo="${current_image%:*}"
324+
log_debug "Current image: ${current_image}"
325+
326+
if ! stale="$(docker images --format '{{.Repository}}:{{.Tag}}' "$repo" 2>>"$LOG_FILE" | grep -vxF -e "$current_image" -e "${repo}:<none>")" || [ -z "$stale" ]; then
327+
log_debug "No stale ${repo} images to remove."
328+
return
329+
fi
330+
331+
echo "Removing old images to free up disk space..."
332+
while IFS= read -r image; do
333+
if docker rmi "$image" >>"$LOG_FILE" 2>&1; then
334+
echo "✓ Removed old image ${image}"
335+
else
336+
echo "Could not remove old image ${image}. Check ${LOG_FILE} for details, or remove it manually with: docker rmi ${image}"
337+
fi
338+
done <<< "$stale"
339+
}
340+
309341
upgrade() {
310342
echo "Starting upgrade process..."
311343

@@ -394,6 +426,8 @@ upgrade() {
394426

395427
echo
396428
echo "✓ Upgrade complete!"
429+
430+
remove_old_images
397431
}
398432

399433
check_docker_compose

0 commit comments

Comments
 (0)