Reputation: 10029
We have an Artifactory server to host our Docker images. I am trying to effectively re-tag one of my Docker images using the JFrog API. I know I could do this with a simple docker tag
and docker push
, but wanted to see how to do this more directly with the Artifactory API. Unfortunately I am running into a snag. Here's the API call I'm trying to make:
curl -X POST --user '[email protected]:MyAPIKey' -H "Content-Type: application/json" --data \
'{"targetRepo": "docker-local", "dockerRepository": "docker-local", "tag": "my/docker/image/original", "targetTag": "my/docker/image/new", "copy": true}' \
https://www.myartifactoryserver.com/api/docker/docker-local/v2/promote
But this call returns the following error:
{
"errors" : [ {
"status" : 400,
"message" : "'targetTag' tag value is invalid."
} ]
}
I'm not sure what I'm doing wrong here, especially since I am able to perform this same copy using the UI. How do I do it with the API?
Upvotes: 1
Views: 2376
Reputation: 2492
Dror Bereznitsky's answer is spot on if you want to do simple re-tagging like
demo-app:1.0.1
🠊 demo-app:latest
However, if your tag is path-like, you can, using Artifactory terminology, promote an Image into a different "Repository Path" within the same "Repository" and keep the same "Tag" (version) in both places:
com.example/stage/demo-app:1.0.1
🠊 com.example/release/demo-app:1.0.1
To promote an Image from stage
to release
like this:
execute POST
request with following body:
POST /api/docker/devops-docker-local/v2/promote
{
"repository" : "devops-docker-local", // Source Repository
"dockerRepository" : "com.example/stage/demo-app", // Source Path
"tag" : "1.0.1", // Source Tag
"targetRepo" : "devops-docker-local", // Target Repository
"targetDockerRepository" : "com.example/release/demo-app", // Target Path
"targetTag" : "1.0.1", // Target Tag
"copy": true
}
The API was tested and screenshot taken on with Artifactory EnterpriseX license 7.33.8 rev 73308900
Upvotes: 2
Reputation: 20386
The problem is with the parameter values you are using for the dockerRepository, tag and targetTag parameters.
Here is an example of how to retag the image hello-world:latest
(stored in the docker-local repository) as hello-world:1.0
:
POST api/docker/docker-local/v2/promote
{
"repository" : "docker-local", // Source Artifactory repository
"dockerRepository" : "hello-world", // Source Docker repository
"targetRepo" : "docker-local", // Target Artifactory repository
"tag" : "latest", // Source tag name
"targetTag" : "1.0" // Target tag name
}
Here is an example of a curl command for sending the above request:
curl -uuser:password -XPOST -H"content-type: application/json" -d "{\"repository\" : \"docker-local\", \"dockerRepository\" : \"hello-world\", \"targetRepo\" : \"docker-local\", \"tag\" : \"latest\", \"targetTag\" : \"1.0\"}" https://myserver.jfrog.io/artifactory/api/docker/docker-local/v2/promote
Please notice both Artifactory and Docker use the term "repository", but each uses it in a different way.
A Docker repository is a hosted collection of tagged images that, together, create the file system for a container
A Docker registry is a host that stores Docker repositories
An Artifactory repository is a hosted collection of Docker repositories, effectively, a Docker registry in every way, and one that you can access transparently with the Docker client.
Upvotes: 2