fix installer image retag

This commit is contained in:
yuyr 2026-06-30 17:24:36 +08:00
parent 6c45cc94f3
commit d5270308d6

View File

@ -342,21 +342,54 @@ install_docker_if_missing() {
load_installer_images() { load_installer_images() {
require_cmd docker require_cmd docker
shopt -s nullglob shopt -s nullglob
local image local image load_output desired_tag
local found=0 local found=0
for image in "$INSTALLER_ROOT"/images/*.tar "$INSTALLER_ROOT"/images/*.tar.gz; do for image in "$INSTALLER_ROOT"/images/*.tar "$INSTALLER_ROOT"/images/*.tar.gz; do
found=1 found=1
log "loading docker image: $image" log "loading docker image: $image"
if [[ "$image" == *.gz ]]; then if [[ "$image" == *.gz ]]; then
gzip -dc "$image" | docker load load_output="$(gzip -dc "$image" | docker load)"
else else
docker load -i "$image" load_output="$(docker load -i "$image")"
fi
printf '%s\n' "$load_output"
desired_tag=""
case "$(basename "$image")" in
"${image_tar:-}")
desired_tag="${image_tag:-$RPKI_IMAGE}"
;;
"${prometheus_image_tar:-}")
desired_tag="${prometheus_image:-$PROMETHEUS_IMAGE}"
;;
"${grafana_image_tar:-}")
desired_tag="${grafana_image:-$GRAFANA_IMAGE}"
;;
esac
if [[ -n "$desired_tag" ]]; then
ensure_loaded_image_tag "$desired_tag" "$load_output" "$image"
fi fi
done done
shopt -u nullglob shopt -u nullglob
(( found == 1 )) || warn "no image tar found under $INSTALLER_ROOT/images" (( found == 1 )) || warn "no image tar found under $INSTALLER_ROOT/images"
} }
ensure_loaded_image_tag() {
local desired_tag="$1"
local load_output="$2"
local image_path="$3"
if docker image inspect "$desired_tag" >/dev/null 2>&1; then
return 0
fi
local loaded_ref=""
loaded_ref="$(printf '%s\n' "$load_output" | awk -F'Loaded image: ' '/Loaded image: / {print $2; exit}')"
if [[ -z "$loaded_ref" ]]; then
loaded_ref="$(printf '%s\n' "$load_output" | awk -F'Loaded image ID: ' '/Loaded image ID: / {print $2; exit}')"
fi
[[ -n "$loaded_ref" ]] || die "unable to determine loaded image reference for $image_path"
log "tagging loaded image for package use: source=$loaded_ref target=$desired_tag"
docker tag "$loaded_ref" "$desired_tag"
}
ensure_binfmt_if_needed() { ensure_binfmt_if_needed() {
require_cmd docker require_cmd docker
load_env load_env