logo
0
0
Login
去掉.idea目录

TCR 镜像迁移工具

📌 项目概览

tcr-migrate 是专为腾讯云容器镜像仓库(TCR)设计的跨平台镜像迁移工具,支持将镜像批量同步至 Docker Hub、私有仓库(如 Harbor)或其他兼容 OCI 标准的镜像仓库。核心特性包括:

  • 多架构支持:兼容 Linux amd64/arm64、Windows 等系统架构
  • 并发控制:可配置 1-10 级并发迁移
  • 安全传输:支持 TLS 验证与配置文件加密
  • 日志追踪:提供 Debug 级别详细日志

📂项目结构

. ├── cmd/ # 主程序入口 ├── pkg/ │ ├── api/ # TCR镜像仓库API │ └── images/ # 镜像获取模块 │ └── sync/ # 镜像传输逻辑 ├── config/ # 配置解析 ├── logger/ # 日志模块

🛠️快速开始

环境要求:

  • Go 1.20+ 环境(开发环境)
  • Docker 20.10+(容器化运行)
  • 网络访问目标仓库权限

安装方式:

本地编译运行

git clone https://cnb.cool/cnb/plugins/cnbcool/tcr-migrate.git go build -o tcr-migrate ./cmd

容器化运行(推荐)

docker pull docker.cnb.cool/cnb/plugins/cnbcool/tcr-migrate:latest

🔧 配置说明

配置文件结构

创建 config.yaml 文件(示例模板可通过 coding.yaml-example 生成):

concurrency: 5 # 并发数 [1-10] log_level: info # 日志级别 (debug/info/warn/error) source: domain: "ccr.ccs.tencentyun.com" # 个人版域名 enterprise_domain: "tencentcloudcr.com" # 企业版域名 registry: "your-registry" # 企业版必填, 应用名称 namespace: "dev-ns" # 可选,命名空间 repository: "" # 可选,仓库名称 region: "ap-guangzhou" # 必填 secret_id: "$TENCENT_SECRET_ID" secret_key: "$TENCENT_SECRET_KEY" credentials: username: "$TCR_USERNAME" password: "<PASSWORD>" target: domain: docker.cnb.cool namespace: cnb # 可选命名空间,image路径namesapce/repository repository: tcr-migrate # 可选仓库名称 credentials: username: cnb password: <PASSWORD> tls_verify: true # 可选,默认true

配置文件说明

concurrency 设置同步并发,最小1,最大10。

log_level log级别,debug, info, warn, error

source 设置源镜像仓库信息,

  • domain tcr仓库个人版域名:ccr.ccs.tencentyun.com,(不需要修改)
  • enterprise_domain tcr仓库企业版域名:tencentcloudcr.com,(不需要修改)
  • registry tcr应用名称,(企业版必填)
  • namespace tcr命名空间,(选填,可以迁移指定ns下的镜像)
  • repository tcr仓库名称,(选填,可以迁移指定repository下的镜像)
  • region tcr所在云区域,(必填,如:ap-guangzhou,地域列表
  • secret_id tcr所在云账号的访问密钥,(必填,需有tcr查看权限)
  • secret_key tcr所在云账号的访问密钥,(必填)
  • credentials
    • username tcr仓库用户名,(必填,如:100011945374)
    • password tcr仓库密码,(必填,如:

target 设置目标镜像仓库信息,

  • domain 目标镜像仓库域名,(必填,如:docker.cnb.cool)
  • namespace 目标镜像仓库命名空间,(选填,镜像路径组成部分)
  • repository 目标镜像仓库名称,(选填,镜像路径组成部分)
  • tls_verify 目标镜像仓库是否开启 TLS 验证,(选填,如:true,false)
  • credentials
    • username 目标仓库用户名,(必填)
    • password 目标仓库密码,(必填)

📝 使用指南

基础命令

# 查看镜像列表(显示总数及前100条) tcr-migrate get-images # 执行迁移(默认读取 config.yaml) tcr-migrate sync-images

Docker 运行示例

docker run -v ./config.yaml:/app/config.yaml docker.cnb.cool/cnb/plugins/cnbcool/tcr-migrate:latest

镜像仓库权限说明

  • 源镜像仓库:需要有查看权限
  • 目标镜像仓库:需要有写权限