2
9
Login
合并来自 readme 的合并请求 #25
README
License

CNB Code Import(CNB代码仓库批量导入工具)

badge badge badge

功能介绍

  1. 支持CODING、Github、Gitlab、Gitee、阿里云以及通用第三方代码托管平台的代码仓库批量导入至CNB
  2. 自动跳过迁移成功的仓库(⚠️依赖工作目录下的successful.log文件)

在Docker上使用

注意事项

  1. ⚠️开始导入前,请确保CNB根组织已存在。
  2. xxx为需要用户自行替换的字段,具体含义详见参数介绍。
  3. 云原生开发自带 docker 命令,内网运行更快速

从 Coding 导入

docker run --rm  \
  -e PLUGIN_SOURCE_TOKEN="xxx"  \
  -e PLUGIN_SOURCE_URL="https://coding.example.com" \
  -e PLUGIN_CNB_ROOT_ORGANIZATION="xxx" \
  -e PLUGIN_CNB_TOKEN="xxx"  \
  -e PLUGIN_CNB_URL="https://cnb.example.com" \
  -v $(pwd):$(pwd) -w $(pwd) \
  cnbcool/code-import

从 Github 导入

docker run --rm  \
  -e PLUGIN_SOURCE_TOKEN="xxx"  \
  -e PLUGIN_SOURCE_URL="https://github.com" \
  -e PLUGIN_SOURCE_PLATFORM="github" \
  -e PLUGIN_CNB_ROOT_ORGANIZATION="xxx" \
  -e PLUGIN_CNB_TOKEN="xxx"  \
  -e PLUGIN_CNB_URL="https://cnb.example.com" \
  -v $(pwd):$(pwd) -w $(pwd) \
  cnbcool/code-import

从 Gitlab 导入

docker run --rm  \
  -e PLUGIN_SOURCE_TOKEN="xxx"  \
  -e PLUGIN_SOURCE_URL="https://gitlab.example.com" \
  -e PLUGIN_SOURCE_PLATFORM="gitlab" \
  -e PLUGIN_CNB_ROOT_ORGANIZATION="xxx" \
  -e PLUGIN_CNB_TOKEN="xxx"  \
  -e PLUGIN_CNB_URL="https://cnb.example.com" \
  -v $(pwd):$(pwd) -w $(pwd) \
  cnbcool/code-import

从 Gitee 导入

docker run --rm  \
  -e PLUGIN_SOURCE_TOKEN="xxx"  \
  -e PLUGIN_SOURCE_URL="https://gitlab.com" \
  -e PLUGIN_SOURCE_PLATFORM="gitee" \
  -e PLUGIN_CNB_ROOT_ORGANIZATION="xxx" \
  -e PLUGIN_CNB_TOKEN="xxx"  \
  -e PLUGIN_CNB_URL="https://cnb.example.com" \
  -v $(pwd):$(pwd) -w $(pwd) \
  cnbcool/code-import

从阿里云导入

docker run --rm  \
  -e PLUGIN_SOURCE_USERNAME="xxx"  \
  -e PLUGIN_SOURCE_PASSWORD="xxx"  \
  -e PLUGIN_SOURCE_PLATFORM="aliyun" \
  -e PLUGIN_SOURCE_AK="xxx" \
  -e PLUGIN_SOURCE_AS="xxx" \
  -e PLUGIN_SOURCE_ORGANIZATIONID="xxx" \
  -e PLUGIN_CNB_ROOT_ORGANIZATION="xxx" \
  -e PLUGIN_CNB_TOKEN="xxx"  \
  -e PLUGIN_CNB_URL="https://cnb.example.com" \
  -v $(pwd):$(pwd) -w $(pwd) \
  cnbcool/code-import

从通用第三方代码平台导入

docker run --rm  \
  -e PLUGIN_SOURCE_USERNAME="xxx"  \
  -e PLUGIN_SOURCE_PASSWORD="xxx"  \
  -e PLUGIN_SOURCE_REPO="group1/repo1,group1/repo2,group2/repo3" \
  -e PLUGIN_SOURCE_URL="https://common.example.com" \
  -e PLUGIN_SOURCE_PLATFORM="common" \
  -e PLUGIN_CNB_ROOT_ORGANIZATION="xxx" \
  -e PLUGIN_CNB_TOKEN="xxx"  \
  -e PLUGIN_CNB_URL="https://cnb.example.com" \
  -v $(pwd):$(pwd) -w $(pwd) \
  cnbcool/code-import

参数介绍

参数名类型必填默认值说明
PLUGIN_SOURCE_URL字符串-代码托管平台URL
PLUGIN_SOURCE_TOKEN字符串-调用源代码托管平台 API 的 token (当 source_platform 不为 common 时必填)
- CODING权限:用户信息-只读、项目信息-只读、代码仓库-只读
- Github权限:repo:all、read:org
- Gitlab权限:read_api
- Gitee权限:user_info、projects
PLUGIN_SOURCE_PLATFORM字符串coding导入的平台名称,支持 coding/gitlab/github/gitee,其他通用平台填写 common
PLUGIN_SOURCE_PROJECT字符串-要迁移的 CODING 项目名称 (当 source_platform 为 coding 且 migrate_type 为 project 时必填)
多个项目以英文逗号隔开
PLUGIN_SOURCE_REPO字符串-当source_platform 为 common 或者 source_platform 为 coding 且 migrate_type 为 repo 时必填
多个代码仓库以英文逗号隔开
PLUGIN_SOURCE_USERNAME字符串-当 source_platform 为 aliyun或common 时必填,clone 代码仓库时要用到的用户名,需要确保能够clone所有仓库。
阿里云帮助文档
PLUGIN_SOURCE_PASSWORD字符串-当 source_platform 为 aliyun或common 时必填,clone 代码仓库时要用到的密码
PLUGIN_SOURCE_AK字符串-AccessKey ID,当 source_platform 为 aliyun时必填,需要有AliyunRDCReadOnlyAccess权限,如果是RAM用户,需要关联至云效账号,并授权管理员角色。
阿里云帮助文档
PLUGIN_SOURCE_AS字符串-AccessKey Secret,当 source_platform 为 aliyun时必填。
PLUGIN_SOURCE_ENDPOINT字符串devops.cn-hangzhou.aliyuncs.comAccessKey 请求的地址。
PLUGIN_SOURCE_ORGANIZATIONID字符串-阿里云云效代码仓库企业ID,可在云效访问链接中获取,如https://devops.aliyun.com/organization/【OrganizationId】
PLUGIN_CNB_URL字符串-CNB访问URL
PLUGIN_CNB_TOKEN字符串-CNB 授权令牌,权限要求:
- repo-code 读写
- repo-basic-info 只读
- account-profile 只读
- account-engage 只读
- group-resource 读写
- group-manage 读写
- repo-content 读写
PLUGIN_CNB_ROOT_ORGANIZATION字符串-迁移后,CNB对应的根组织名称,请确保根组织已提前创建
PLUGIN_MIGRATE_TYPE字符串team要迁移的类型,支持项目(project)、仓库(repo)、团队(team)多维度迁移,只支持 coding 平台
PLUGIN_MIGRATE_CONCURRENCY数值10仓库迁移并发数,最大10
PLUGIN_MIGRATE_FORCE_PUSH布尔值false强制push到CNB仓库
PLUGIN_MIGRATE_SKIP_EXISTS_REPO布尔值true跳过CNB已存在的仓库
PLUGIN_MIGRATE_USE_LFS_MIGRATE字符串false是否使用lfs migrate处理历史提交中超过CNB单文件最大限制错误
⚠️如开启该配置,迁移后commit ID会与源仓库不一致
PLUGIN_MIGRATE_ORGANIZATION_MAPPING_LEVEL字符串1CODING与CNB组织映射关系,仅支持 Coding 平台
1: CODING项目映射为CNB子组织,仓库在子组织下面
2: CODING项目不会映射为CNB子组织,仓库直接在CNB根组织下面
PLUGIN_MIGRATE_ALLOW_INCOMPLETE_PUSH字符串false针对LFS源文件丢失的仓库,忽略LFS文件下载报错,LFS推送时忽略丢失的对象报错,继续推送
PLUGIN_MIGRATE_LOG_LEVEL字符串info日志级别(debug/info/warn/error)
PLUGIN_MIGRATE_RELEASE布尔值false迁移release(暂时只支持 gitlab release迁移)
PLUGIN_MIGRATE_FILE_LIMIT_SIZE数值100CNB最大文件大小限制,单位Mib
PLUGIN_MIGRATE_CODE布尔值true迁移代码

About

批量迁移代码托管平台代码仓库到 CNB

贡献者
2

1
Language
Go95.7%
Assembly1.5%
Markdown1.3%
Shell0.3%
Others1.2%