如何使用JFrog Rest API将Docker映像从一个存储库提升(复制)到另一个存储库



我有一个存储库与所有Docker映像。我想复制所有的docker镜像从那里到另一个存储库,在过去7天内使用。我必须是一个python脚本,我不能使用curl

除了复制图像的方法之外,我什么都明白了。

URL = "https://repo.url/artifactory"
REPOSITORY = "repo-with-all-images"
IMAGE_NAME = "image-name"
VERSION = "latest"
TARGET_REPOSITORY = "repo-to-paste-images"
url = f"{URL}/api/docker/{REPOSITORY}/{IMAGE_NAME}/{VERSION}/promote"
payload = {
"targetRepo": TARGET_REPOSITORY,
"copy": True,
}
headers = ({"Authorization": token})
status = urllib3.PoolManager().request(method="POST", url=url, body=json.dumps(payload), headers=headers)
logging.error(status.data)
logging.error(status.headers

当运行它时,我得到这样的消息:

错误:根:b { n"errors": [{n "status": 405,n message": "方法不允许"n}]n}'

错误:根:HTTPHeaderDict({"日期":"格林尼治时间2023年1月11日结婚,09:36:13","内容类型":"application/json"、"传输编码":"分块","连接":"维生","X-JFrog-Version":"Artifactory/x.x x。XX XXXXXXXX', 'X-Artifactory-Id': 'xxxxxxxxxxxx:-xxxxxxx:xxxxxxxxxx:-xxxx', 'X-Artifactory-Node-Id': 'xxxx - XXXXXXXX -xxx', 'Allow': 'HEAD,GET,OPTIONS'})

看一下Promote Docker Image REST API的文档,看起来你用错了。

它说:

POST api/docker/<repoKey>/v2/promote
{
"targetRepo" : "<targetRepo>",
"dockerRepository" : "<dockerRepository>",
"targetDockerRepository" : "<targetDockerRepository>",
"tag" : "<tag>",
"targetTag" : "<tag>",
"copy": false
}

这意味着在你的情况下,它应该是(基于问题中的原始代码):

URL = "https://repo.url/artifactory"
REPOSITORY = "repo-with-all-images"
IMAGE_NAME = "image-name"
VERSION = "latest"
TARGET_REPOSITORY = "repo-to-paste-images"
url = f"{URL}/api/docker/{REPOSITORY}/v2/promote"
payload = {
"targetRepo": TARGET_REPOSITORY,
"dockerRepository": IMAGE_NAME,
"tag": VERSION,
"copy": True,
}
headers = ({"Authorization": token, "Content-Type": "application/json"})
status = urllib3.PoolManager().request(method="POST", url=url, body=json.dumps(payload), headers=headers)
logging.error(status.data)
logging.error(status.headers

最新更新