fix: do not retire an image that another app uses as its source image

Image retirement removes images by id, so a queued image could be deleted even though another app had since started using it as its git:from-image source image. Skip such images at retire time and drop them from the retire list.

The git_4 test images are also given a per-app label so they no longer share a cached image id, which let a retire entry left by one test delete the next test's source image.
This commit is contained in:
Jose Diaz-Gonzalez
2026-10-14 10:00:51 -04:00
parent 02f0466cac
commit e71dffb1a7
3 changed files with 71 additions and 1 deletions

View File

@@ -187,6 +187,15 @@ fn-scheduler-docker-local-retire-images() {
return
fi
local -A SOURCE_IMAGE_APPS=()
local source_app source_image source_image_id
for source_app in $(dokku_apps "false" 2>/dev/null); do
source_image="$(plugn trigger git-get-property "$source_app" "source-image" 2>/dev/null || true)"
[[ -z "$source_image" ]] && continue
source_image_id="$("$DOCKER_BIN" image inspect --format '{{ .Id }}' "$source_image" 2>/dev/null | cut -d: -f2 || true)"
[[ -n "$source_image_id" ]] && SOURCE_IMAGE_APPS["$source_image_id"]="$source_app"
done
DEAD_IMAGES=()
while read line; do
[[ -z "$line" ]] && continue
@@ -209,6 +218,12 @@ fn-scheduler-docker-local-retire-images() {
continue
fi
if [[ -n "${SOURCE_IMAGE_APPS[$IMAGE_ID]}" ]]; then
dokku_log_warn "Image ${IMAGE_ID} is the source image for ${SOURCE_IMAGE_APPS[$IMAGE_ID]}, removing from retire list"
DEAD_IMAGES+=("$IMAGE_ID")
continue
fi
dokku_log_verbose_quiet "Attempting to retire $RETIRE_APP image $IMAGE_ID"
if RM_OUTPUT="$("$DOCKER_BIN" image remove "$IMAGE_ID" 2>&1)"; then
DEAD_IMAGES+=("$IMAGE_ID")

View File

@@ -26,7 +26,7 @@ build_python_image() {
cp "$TMP_IMAGE_DIR/$PROCFILE" "$TMP_IMAGE_DIR/Procfile"
fi
docker image build -t "dokku-test/$TEST_APP:$TAG" -f "$TMP_IMAGE_DIR/alt.Dockerfile" "$TMP_IMAGE_DIR" || exit_code="$?"
docker image build --label "com.dokku.test-app=$TEST_APP" -t "dokku-test/$TEST_APP:$TAG" -f "$TMP_IMAGE_DIR/alt.Dockerfile" "$TMP_IMAGE_DIR" || exit_code="$?"
rm -rf "$TMP_IMAGE_DIR"
return "$exit_code"
}

View File

@@ -8,6 +8,7 @@ setup() {
teardown() {
global_teardown
docker image rm "dokku-test/$TEST_APP:shared" &>/dev/null || true
}
@test "(scheduler-docker-local:report) --global raw and computed keys" {
@@ -484,6 +485,60 @@ teardown() {
assert_output "running"
}
@test "(scheduler-docker-local) ps:retire keeps an image that is another app's source image" {
local SECOND_APP="$TEST_APP-2" TMP_IMAGE_DIR
TMP_IMAGE_DIR="$(mktemp -d "/tmp/${DOKKU_DOMAIN}.XXXXX")"
cp -r "${BATS_TEST_DIRNAME}/../../tests/apps/python/." "$TMP_IMAGE_DIR"
run /bin/bash -c "docker image build -t dokku-test/$TEST_APP:shared -f $TMP_IMAGE_DIR/alt.Dockerfile $TMP_IMAGE_DIR"
echo "output: $output"
echo "status: $status"
rm -rf "$TMP_IMAGE_DIR"
assert_success
run create_app
echo "output: $output"
echo "status: $status"
assert_success
run create_app "$SECOND_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku checks:set $TEST_APP wait-to-retire 1"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:from-image $TEST_APP dokku-test/$TEST_APP:shared"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:from-image $SECOND_APP dokku-test/$TEST_APP:shared"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app
echo "output: $output"
echo "status: $status"
assert_success
sleep 3
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "is the source image for $SECOND_APP"
run /bin/bash -c "docker image inspect dokku-test/$TEST_APP:shared --format '{{.Id}}'"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(scheduler-docker-local) procfile quoted arguments on deploy" {
run create_app
echo "output: $output"