Local docker builds were not being skipped correctly
This commit is contained in:
1 parent
1f6a602555
commit
ca7c5d435b
1 file changed
+25
-7
+25
-7
@@ -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
|
||||
Reference in new issue
Block a user