## 新增功能 ### 代理缓存管理 - harbor-proxy-cache.sh: Harbor 代理缓存配置和管理脚本 - harbor-docker-config.sh: Docker 客户端配置脚本 - setup-proxy-quick.sh: 快速配置代理缓存 ### 镜像配置 - configure-containerd-mirrors.sh: Containerd 镜像加速配置 - configure-k3s-mirrors.sh: K3s 集群镜像配置 - configure-registry-domains.sh: 注册表域名配置 - harbor-image-precache.sh: 镜像预缓存脚本 - harbor-k3s-config.sh: K3s Harbor 集成配置 ### 部署工具 - deploy-to-ops.sh: 从代码仓库同步到运行环境的部署脚本 ### 文档 - HARBOR_PROXY_CACHE_GUIDE.md: 代理缓存配置指南 - SMART_MIRROR_SETUP.md: 智能镜像加速配置 ### 配置 - .gitignore: 排除运行时文件和敏感数据 ## 架构优化 建立了清晰的开发-部署分离模式: - ~/work/codes/tools/macos/harbor - 代码仓库(版本控制) - ~/ops/harbor - 运行环境(实际部署) 通过 deploy-to-ops.sh 实现一键同步部署 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
89 lines
3.8 KiB
Bash
Executable File
89 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 快速配置 Harbor proxy cache
|
|
|
|
set -euo pipefail
|
|
|
|
HARBOR_URL="https://192.168.1.83:8443"
|
|
HARBOR_USER="admin"
|
|
HARBOR_PASSWORD="admin123"
|
|
CURL_OPTS="-k"
|
|
|
|
echo "=== 创建 Registry Endpoints ==="
|
|
|
|
# GCR
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"name": "gcr", "type": "google-gcr", "url": "https://gcr.io", "description": "GCR Proxy", "insecure": false}' \
|
|
"${HARBOR_URL}/api/v2.0/registries" && echo "✓ GCR endpoint created"
|
|
|
|
# K8s Registry
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"name": "k8s-registry", "type": "docker-registry", "url": "https://registry.k8s.io", "description": "K8s Registry Proxy", "insecure": false}' \
|
|
"${HARBOR_URL}/api/v2.0/registries" && echo "✓ K8s Registry endpoint created"
|
|
|
|
# Quay.io
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"name": "quay", "type": "quay", "url": "https://quay.io", "description": "Quay.io Proxy", "insecure": false}' \
|
|
"${HARBOR_URL}/api/v2.0/registries" && echo "✓ Quay.io endpoint created"
|
|
|
|
# GitHub CR
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"name": "ghcr", "type": "github-ghcr", "url": "https://ghcr.io", "description": "GHCR Proxy", "insecure": false}' \
|
|
"${HARBOR_URL}/api/v2.0/registries" && echo "✓ GHCR endpoint created"
|
|
|
|
echo ""
|
|
echo "=== 获取 Registry IDs ==="
|
|
ENDPOINTS=$(curl ${CURL_OPTS} -s -u "${HARBOR_USER}:${HARBOR_PASSWORD}" "${HARBOR_URL}/api/v2.0/registries")
|
|
echo "$ENDPOINTS" | jq -r '.[] | "\(.id)\t\(.name)\t\(.url)"'
|
|
|
|
echo ""
|
|
echo "=== 创建 Proxy Cache Projects ==="
|
|
|
|
# 获取每个 endpoint 的 ID 并创建对应的 project
|
|
GCR_ID=$(echo "$ENDPOINTS" | jq -r '.[] | select(.name=="gcr") | .id')
|
|
K8S_ID=$(echo "$ENDPOINTS" | jq -r '.[] | select(.name=="k8s-registry") | .id')
|
|
QUAY_ID=$(echo "$ENDPOINTS" | jq -r '.[] | select(.name=="quay") | .id')
|
|
GHCR_ID=$(echo "$ENDPOINTS" | jq -r '.[] | select(.name=="ghcr") | .id')
|
|
|
|
# GCR Project
|
|
if [[ -n "$GCR_ID" ]]; then
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"project_name\": \"gcr\", \"public\": true, \"metadata\": {\"public\": \"true\"}, \"registry_id\": $GCR_ID}" \
|
|
"${HARBOR_URL}/api/v2.0/projects" && echo "✓ GCR project created"
|
|
fi
|
|
|
|
# K8s Registry Project
|
|
if [[ -n "$K8S_ID" ]]; then
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"project_name\": \"k8s-registry\", \"public\": true, \"metadata\": {\"public\": \"true\"}, \"registry_id\": $K8S_ID}" \
|
|
"${HARBOR_URL}/api/v2.0/projects" && echo "✓ K8s Registry project created"
|
|
fi
|
|
|
|
# Quay Project
|
|
if [[ -n "$QUAY_ID" ]]; then
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"project_name\": \"quay\", \"public\": true, \"metadata\": {\"public\": \"true\"}, \"registry_id\": $QUAY_ID}" \
|
|
"${HARBOR_URL}/api/v2.0/projects" && echo "✓ Quay project created"
|
|
fi
|
|
|
|
# GHCR Project
|
|
if [[ -n "$GHCR_ID" ]]; then
|
|
curl ${CURL_OPTS} -s -X POST -u "${HARBOR_USER}:${HARBOR_PASSWORD}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"project_name\": \"ghcr\", \"public\": true, \"metadata\": {\"public\": \"true\"}, \"registry_id\": $GHCR_ID}" \
|
|
"${HARBOR_URL}/api/v2.0/projects" && echo "✓ GHCR project created"
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== 配置完成 ==="
|
|
echo "已配置的 Proxy Cache Projects:"
|
|
curl ${CURL_OPTS} -s -u "${HARBOR_USER}:${HARBOR_PASSWORD}" "${HARBOR_URL}/api/v2.0/projects" | \
|
|
jq -r '.[] | select(.registry_id != null) | "\(.project_id)\t\(.name)\t\(.registry_id)"'
|