diff options
| -rwxr-xr-x | test-build | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -861,8 +861,20 @@ print_summary() { # so an up-to-date image costs one manifest request. require_image() { if [[ $PULL_IMAGE -eq 1 ]]; then + local old_id new_id + old_id="$(docker image inspect --format '{{.Id}}' "$ACTIVE_IMAGE" 2>/dev/null || true)" echo "Pulling: $ACTIVE_IMAGE" >&2 - docker pull "$ACTIVE_IMAGE" >&2 && return 0 + if docker pull "$ACTIVE_IMAGE" >&2; then + # A pull that moved the tag leaves the old image untagged (~23G for + # current). Drop that one image, not every dangling one on the host; + # rmi refuses if a container (e.g. a concurrent run) still uses it. + new_id="$(docker image inspect --format '{{.Id}}' "$ACTIVE_IMAGE")" + if [[ -n $old_id && $old_id != "$new_id" ]]; then + docker rmi "$old_id" >&2 \ + || echo "WARN: superseded image $old_id still in use; left in place." >&2 + fi + return 0 + fi if docker image inspect "$ACTIVE_IMAGE" >/dev/null 2>&1; then echo "WARN: pull failed; using the local copy, which may be stale." >&2 return 0 |
