diff --git a/install.sh b/install.sh index 1e8b540..e6c4051 100644 --- a/install.sh +++ b/install.sh @@ -1331,13 +1331,29 @@ progress '下载 bootstrap runtime' die 'bootstrap runtime 下载失败;请确认能访问 git.keeper.work Container Registry' fi validate_bootstrap_runtime_platform() { - local bootstrap_image_id runtime_metadata runtime_os runtime_arch runtime_platform - bootstrap_image_id=$("${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" images -q app 2>>"$INSTALL_LOG" | tr -d '[:space:]') || die '无法确定 bootstrap runtime 的本地镜像 ID' - [[ -n $bootstrap_image_id ]] || die '无法确定 bootstrap runtime 的本地镜像 ID' - runtime_metadata=$(docker image inspect --format '{{.Os}}\t{{.Architecture}}' "$bootstrap_image_id" 2>>"$INSTALL_LOG") || die '无法读取 bootstrap runtime 的本地镜像平台元数据' - IFS=$'\t' read -r runtime_os runtime_arch <<<"$runtime_metadata" - [[ -n $runtime_os && -n $runtime_arch ]] || die 'bootstrap runtime 的本地镜像平台元数据不完整' - runtime_platform="$runtime_os/$runtime_arch" + local bootstrap_image_expected bootstrap_image_ref bootstrap_image_id runtime_metadata runtime_platform + bootstrap_image_expected=${XYMEDIA_BOOTSTRAP_IMAGE:-} + if [[ -z $bootstrap_image_expected && -f $INSTALL_DIR/.env ]]; then + bootstrap_image_expected=$(awk -F= '$1 == "XYMEDIA_BOOTSTRAP_IMAGE" {sub(/^[^=]*=/, ""); print; exit}' "$INSTALL_DIR/.env") + fi + bootstrap_image_expected=${bootstrap_image_expected:-git.keeper.work/admin/xymediavault-bootstrap:1} + bootstrap_image_ref=$("${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" config --images 2>>"$INSTALL_LOG" | awk -v expected="$bootstrap_image_expected" 'NF && $0 == expected {print; exit}') || true + if [[ -z $bootstrap_image_ref ]]; then + bootstrap_image_id=$("${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" images -q app 2>>"$INSTALL_LOG" | awk 'NF {print; exit}') || true + bootstrap_image_ref=$bootstrap_image_id + fi + [[ -n $bootstrap_image_ref ]] || die '无法确定 bootstrap runtime 的本地镜像引用或 ID' + + runtime_metadata=$(docker image inspect --format '{{.Os}}/{{.Architecture}}' "$bootstrap_image_ref" 2>>"$INSTALL_LOG" || true) + runtime_metadata=${runtime_metadata//$'\r'/} + printf 'bootstrap platform detection: ref=%s image-inspect=%s\n' "$bootstrap_image_ref" "${runtime_metadata:-}" >>"$INSTALL_LOG" + if [[ ! $runtime_metadata =~ ^[^/]+/[^/]+$ ]]; then + runtime_metadata=$(docker inspect --type image --format '{{.Os}}/{{.Architecture}}' "$bootstrap_image_ref" 2>>"$INSTALL_LOG" || true) + runtime_metadata=${runtime_metadata//$'\r'/} + printf 'bootstrap platform detection: ref=%s docker-inspect=%s\n' "$bootstrap_image_ref" "${runtime_metadata:-}" >>"$INSTALL_LOG" + fi + [[ $runtime_metadata =~ ^[^/]+/[^/]+$ ]] || die 'bootstrap runtime 的本地镜像平台元数据不完整;请查看 install.log 中的 docker image inspect 输出' + runtime_platform=$runtime_metadata case "$runtime_platform" in linux/amd64) runtime_platform=linux-amd64;; linux/arm64) runtime_platform=linux-arm64;;