k8s-deploy/dl-kubevirt-image.sh
2025-11-21 17:55:30 +08:00

51 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
# ------------------------------
# 配置区
# ------------------------------
# KubeVirt 版本(例如 v0.90.1
KUBEVIRT_VERSION="v{{ kubevirt.version }}"
# 下载目录
DOWNLOAD_DIR="/tmp/kubevirt-images"
mkdir -p "$DOWNLOAD_DIR"
# quay.io 登录信息
QUAY_USERNAME="safecorner+safecorner"
QUAY_PASSWORD="9J4BXPCG0FY25P9KL8XYDIAH5V9GXAQKYCUKOE5QI2N5WIFWA0ZB914D0MNZXRCQ"
# ------------------------------
# 自动解析官方 release YAML 获取镜像列表
# ------------------------------
echo "Fetching KubeVirt release YAML..."
RELEASE_YAML_URL="https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-${KUBEVIRT_VERSION}.yaml"
IMAGE_LIST=$(curl -sL "$RELEASE_YAML_URL" | grep "image:" | awk '{print $2}' | sort -u)
if [ -z "$IMAGE_LIST" ]; then
echo "Error: No images found in release YAML."
exit 1
fi
echo "Found $(echo "$IMAGE_LIST" | wc -l) images."
# ------------------------------
# 下载镜像
# ------------------------------
for img in $IMAGE_LIST; do
IMAGE_NAME=$(basename "$img")
# 替换 : / 等特殊字符,保证 tar 文件名合法
SAFE_NAME=$(echo "$IMAGE_NAME" | tr '/:' '_')
TAR_FILE="${DOWNLOAD_DIR}/${SAFE_NAME}.tar"
echo "Downloading $img -> $TAR_FILE"
skopeo copy --src-creds "$QUAY_USERNAME:$QUAY_PASSWORD" \
"docker://$img" "docker-archive:${TAR_FILE}" || {
echo "Failed to download $img, skipping..."
continue
}
done
echo "All images downloaded to $DOWNLOAD_DIR"