容器镜像迁移

镜像迁移

阿里镜像迁移腾讯云

迁移工具:image-syncer(阿里云开源)

参考地址:https://github.com/AliyunContainerService/image-syncer/blob/master/README-zh_CN.md

说明:

开源工具提供迁移,只能一个一个仓库迁移,不能针对名称空间迁移。所以在迁移时,需要获取到阿里云镜像仓库中所有命名空间下的所有仓库。但好在支持仓库无需指定版本,如腾讯云提供的迁移工具只支持细化到版本的迁移。

获取镜像仓库

根据阿里云文档提供SDK方式,批量获取命名空间下所有仓库。

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys

from typing import List

from alibabacloud_cr20181201.client import Client as cr20181201Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_cr20181201 import models as cr_20181201_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> cr20181201Client:
        """
        使用AK&SK初始化账号Client
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 您的 AccessKey ID,
            access_key_id='XXX',
            # 您的 AccessKey Secret,
            access_key_secret='XXX'
        )
        # 访问的域名
        config.endpoint = f'cr.cn-hangzhou.aliyuncs.com'
        return cr20181201Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        list_repository_request = cr_20181201_models.ListRepositoryRequest(
            instance_id='cri-71m5d5zzyzwn1pw4',
            repo_status='ALL',
            repo_namespace_name='ppio'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            a = client.list_repository_with_options(list_repository_request, runtime)
            for i in a.body.repositories:
                repo_name = i.repo_name
                repo_spacename = i.repo_namespace_name
                domain = '"ppio-registry.cn-hangzhou.cr.aliyuncs.com' + "/" + repo_spacename + '/' + repo_name + '": "' + 'ppio-harbor-registry.tencentcloudcr.com/' + "aliyun" + "/" + repo_name + '",'
                print(domain)


        except Exception as error:
            # 如有需要,请打印 error
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        list_repository_request = cr_20181201_models.ListRepositoryRequest(
            instance_id='cri-71m5d5zzyzwn1pw4',
            repo_status='ALL',
            repo_namespace_name='ppio'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.list_repository_with_options_async(list_repository_request, runtime)
        except Exception as error:
            # 如有需要,请打印 error
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

镜像迁移

# auth配置文件用于认证拉取与镜像推送
root@ppio-ubt20:/tmp/ali-ttt# cat auth.json 
{  
    "ppio-registry.cn-hangzhou.cr.aliyuncs.com": {
        "username": "XXX",
        "password": "XXX"
    },
    "ppio-harbor-registry.tencentcloudcr.com": {
        "username": "XXX",
}

# images为源镜像仓库地址与目标镜像仓库地址,源镜像仓库可以不细化到具体版本号,迁移会自动将仓库下所有版本同步到目标仓库。
root@ppio-ubt20:/tmp/ali-ttt# cat images.json 
{
	"ppio-registry.cn-hangzhou.cr.aliyuncs.com/cloud/tdengine-adapter": "ppio-harbor-registry.tencentcloudcr.com/aliyun/tdengine-adapter",
	"ppio-registry.cn-hangzhou.cr.aliyuncs.com/cloud/envoy": "ppio-harbor-registry.tencentcloudcr.com/aliyun/envoy",
	"ppio-registry.cn-hangzhou.cr.aliyuncs.com/cloud/pushgateway": "ppio-harbor-registry.tencentcloudcr.com/aliyun/pushgateway",
	"ppio-registry.cn-hangzhou.cr.aliyuncs.com/cloud/gin-demo": "ppio-harbor-registry.tencentcloudcr.com/aliyun/gin-demo",
	"ppio-registry.cn-hangzhou.cr.aliyuncs.com/cloud/vote-e2e": "ppio-harbor-registry.tencentcloudcr.com/aliyun/vote-e2e",
	"ppio-registry.cn-hangzhou.cr.aliyuncs.com/cloud/worker-e2e": "ppio-harbor-registry.tencentcloudcr.com/aliyun/worker-e2e"
}

# 镜像同步方式
# namespace和registry为默认目标仓库与名称空间地址。
root@ppio-ubt20:/tmp/ali-ttt# ./image-syncer --proc=6 --auth=./auth.json --images=./images.json --namespace=aliyun --registry=ppio-harbor-registry.tencentcloudcr.com --retries=3
posted @ 2022-08-04 15:05  元气少女郭德纲!!  阅读(52)  评论(0编辑  收藏  举报