From ca7c5d435bf1f1edf280b03192f5e43aaa8c7fd4 Mon Sep 17 00:00:00 2001 From: Timothy Allen Date: Thu, 22 Oct 2026 22:04:34 +0200 Subject: [PATCH] Local docker builds were not being skipped correctly --- update_docker_images.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/update_docker_images.sh b/update_docker_images.sh index 2ecddbe..be73e0c 100755 --- a/update_docker_images.sh +++ b/update_docker_images.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Usage: ./update_docker_images.sh [--prune] [--build] [compose-directory] -# By default, pull images and update services without pruning or building. +# By default, pull non-buildable images and update services without pruning or building. +# Continue after project failures; report them and exit nonzero at the end. # WARNING: Pruning removes stopped containers, unused images, build cache, # and unused anonymous volumes. set -euo pipefail @@ -11,7 +12,9 @@ usage() { ' --prune Remove unused Docker resources before updating (including volumes).' \ ' --build Build images with --pull before updating services.' \ ' -h, --help Show this help.' \ - 'Default: pull images and update services; do not prune or build.' + 'Default: pull images for services without build definitions and update services.' \ + 'Services with build definitions keep their local images unless --build is used.' \ + 'Project failures are reported at the end; other projects are still updated.' } prune=false @@ -88,6 +91,7 @@ if "$build"; then docker buildx inspect "$builder" --bootstrap fi +failed_projects=() for directory in "$compose_root"/*; do [[ -d "$directory" ]] || continue [[ -f "$directory/docker-compose.yml" ]] || continue @@ -96,13 +100,27 @@ for directory in "$compose_root"/*; do printf '\nUpdating %s\n' "$directory" # A subshell restores the working directory even when a command fails. - ( - cd -- "$directory" - docker compose pull + # Because it is tested by 'if', explicitly stop on each failed command; + # Bash does not apply 'set -e' inside this conditional subshell. + if ( + cd -- "$directory" || exit "$?" + docker compose pull --ignore-buildable || exit "$?" if "$build"; then - docker compose build --pull + docker compose build --pull || exit "$?" fi # Do not let Compose implicitly build images when starting services. docker compose up -d --no-build - ) + ); then + printf 'Updated %s\n' "$directory" + else + status=$? + printf 'Update failed for %s (exit %s); continuing.\n' "$directory" "$status" >&2 + failed_projects+=("$directory") + fi done + +if (( ${#failed_projects[@]} )); then + printf '\nFailed projects:\n' >&2 + printf ' %s\n' "${failed_projects[@]}" >&2 + exit 1 +fi