#!/bin/bash  
  
# 源 Harbor 配置  
SOURCE_HARBOR="harbor.xxx.com"  
SOURCE_PROJECT="xx-xxx"  
#SOURCE_PROJECT="xxx"  
#SOURCE_USER="username"  
#SOURCE_PASS="password"  
  
# 目标 Harbor 配置  
DEST_HARBOR="192.168.25.8:10443"  
DEST_PROJECT="xxx-xxx"  
DEST_USER="admin"  
DEST_PASS="xxx@xxx"  
DEST_CA_FILE="/etc/docker/certs.d/192.168.25.8:10443/ca.crt"  
  
# 添加源和目标 Harbor 仓库/  
helm repo remove source-repo || true  
helm repo remove dest-repo || true  
helm repo add source-repo https://$SOURCE_HARBOR/chartrepo/$SOURCE_PROJECT #--username $SOURCE_USER --password $SOURCE_PASS  
helm repo add dest-repo https://$DEST_HARBOR/chartrepo/$DEST_PROJECT --username $DEST_USER --password $DEST_PASS --ca-file $DEST_CA_FILE  
  
# 更新 repo  
helm repo update  
  
# 获取所有 charts  
charts=$(helm search repo source-repo/ -o json | jq -r '.[].name')  
  
# 遍历并同步每个 chart  
for chart in $charts  
do  
   echo "sync with [$chart]"  
   # 获取所有版本t  
   versions=$(helm search repo $chart -l -o json | jq -r '.[].version')  
   chart_name=${chart#source-repo/}  
   # 遍历每个版本c  
   for version in $versions  
   do  
       echo "sync with [$chart] [$version]"  
       # 下载特定版本的 chart  
       helm pull $chart --version $version  
  
       # 推送到目标仓库t  
       helm cm-push ${chart_name}-${version}.tgz dest-repo --ca-file $DEST_CA_FILE  
  
       # 清理下载的文件c  
       rm ${chart_name}-${version}.tgz  
   done  
done
最后修改:2024 年 12 月 18 日
如果觉得我的文章对你有用,请随意赞赏