Closed jphelion closed 7 years ago
Hmm. It looks a touch broken. I suspect that when we ported over to docker-java, the different API wasn't converted correctly.
As an aside, docker has a very confus(ed,ing) terminology around labelling, tags and namespaces, which doesn't help.
Looking at it, I think it's also broken just below where
if (getJobProperty().pushOnSuccess) {
client.pushImageCmd(tagToken).exec();
}
became changed to
if (getJobProperty().pushOnSuccess) {
client.pullImageCmd(tagToken).exec(new PullImageResultCallback()).awaitSuccess();
}
Which looks completely wrong to me.
If you're near a compiler, you could replace the entire block with something like
if (!Strings.isNullOrEmpty(tagToken)) {
final NameParser.ReposTag reposTag = NameParser.parseRepositoryTag(tagToken);
final String commitTag = isEmpty(reposTag.tag) ? "latest" : reposTag.tag;
getClient().tagImageCmd(tag_image, reposTag.repos, commitTag).withForce().exec();
addJenkinsAction(tagToken);
if (getJobProperty().pushOnSuccess) {
client.pushImageCmd(tagToken).exec(new PushImageResultCallback()).awaitSuccess();
}
}
Which ought to do what is needed.
Thanks, I'll try that.
Ok now tagging seems to be working but push fails to this error:
Oct 21, 2015 3:32:09 PM SEVERE com.nirima.jenkins.plugins.docker.DockerSlave slaveShutdown
Could not add additional tags: com.github.dockerjava.api.DockerClientException: Could not push image
I traced it back to the awaitSuccess method in PushImageResultCallback.java in docker-java.
Ok. Nearly there then, I probably got the wrong intem in tagToken as I'm flying without a compiler
Try
if (getJobProperty().pushOnSuccess) {
Identifier identifier = Identifier.fromCompoundString(tagToken);
PushImageResultCallback resultCallback = new PushImageResultCallback() {
public void onNext(PushResponseItem item) {
if( item == null ) {
LOGGER.log(Level.SEVERE, "NULL?");
return;
}
printResponseItemToListener(listener, item);
super.onNext(item);
}
};
try {
getClient().pushImageCmd(identifier).exec(resultCallback).awaitSuccess();
} catch(DockerClientException ex) {
LOGGER.log(Level.SEVERE, "Exception pushing docker image. Check that the destination registry is running.");
throw ex;
}
}
Which may then give you some hints if it's actually failing due to the remote registry, or it's just the wrong name.
Thanks again, I don't have my setup with me right now as I'm out of office but tomorrow I'll try that.
I tested it with the new code snippet and it worked, but only when my image/repository name had only one /
in it. When i tried with localhost:5000/evarga/jenkins-slave:testTag
it would give the following error (I added the identifier there to see):
Oct 23, 2015 4:00:50 PM SEVERE com.nirima.jenkins.plugins.docker.DockerSlave slaveShutdown
Exception pushing docker image. Check that the destination registry is running. Identifier was: Identifier{repository=Repository{name=localhost:5000/evarga/jenkins-slave:testTag}, tag=Optional.absent()}
Oct 23, 2015 4:00:50 PM SEVERE com.nirima.jenkins.plugins.docker.DockerSlave slaveShutdown
Could not add additional tag: scom.github.dockerjava.api.DockerClientException: Could not push image
But if the image name was localhost:5000/jenkins-slave:testTag
it worked. I don't know if having multiple /
is bad naming convention or to be avoided completely in docker.
I also tried with the older version of the code (the one that fixed tagging) but that could not push an image with valid name (only one /
in it) to the registry.
Also is it intended that I give the full name of the repository/image in the "Additional tags to add" field? In order to add a tag successfully and push to my registry I now had to give something similar as this:
EDIT: forgot to mention, I could push localhost:5000/evarga/jenkins-slave:testTag
manually to the registry.
IIRC (and I have not looked at the spec recently), the tag format is specified as "repository" : "tag", where repository is specified as 'docker hub account name' / 'image name' or 'registry server:port'/'image name'
So if you are using a local registry, you cannot have a / in your image name. (I think this sucks, but it is what it is, and the terminology is very confusing).
I don't know your setup, but I would think you need a real DNS name or IP address rather than just 'localhost' in the tagging setting.
On Fri, Oct 23, 2015 at 2:29 PM, jphelion notifications@github.com wrote:
I tested it with the new code snippet and it worked, but only when my image/repository name had only one / in it. When i tried with localhost:5000/evarga/jenkins-slave:testTag it would give the following error (I added the identifier there to see):
Oct 23, 2015 4:00:50 PM SEVERE com.nirima.jenkins.plugins.docker.DockerSlave slaveShutdown
Exception pushing docker image. Check that the destination registry is running. Identifier was: Identifier{repository=Repository{name=localhost:5000/evarga/jenkins-slave:testTag}, tag=Optional.absent()}
Oct 23, 2015 4:00:50 PM SEVERE com.nirima.jenkins.plugins.docker.DockerSlave slaveShutdown
Could not add additional tag: scom.github.dockerjava.api.DockerClientException: Could not push image
But if the image name was localhost:5000/jenkins-slave:testTag it worked. I don't know if having multiple / is bad naming convention or to be avoided completely in docker.
I also tried with the older version of the code (the one that fixed tagging) but that could not push an image with valid name (only one / in it) to the registry.
Also is it intended that I give the full name of the repository/image in the "Additional tags to add" field? In order to add a tag successfully and push to my registry I now had to give something similar as this: [image: additionaltagsv2] https://cloud.githubusercontent.com/assets/14053290/10693350/2c9d7ca4-7987-11e5-8d91-fcaa67e8883d.png
— Reply to this email directly or view it on GitHub https://github.com/jenkinsci/docker-plugin/issues/341#issuecomment-150571605 .
IIRC (and I have not looked at the spec recently), the tag format is specified as "repository" : "tag", where repository is specified as 'docker hub account name' / 'image name' or 'registry server:port'/'image name' So if you are using a local registry, you cannot have a / in your image name. (I think this sucks, but it is what it is, and the terminology is very confusing).
Ah, I see. With only one /
pushing and tagging seems to work well with the changes that were made in this issue.
I don't know your setup, but I would think you need a real DNS name or IP address rather than just 'localhost' in the tagging setting.
Yes, I agree. Localhost was only so that i could get a more controlled env to test everything out. I tested the changes just now with another computer serving as the docker host with real DNS name and everything worked fine. I'll test these changes with our real servers when they are free.
Ok, sorry about the long delay, I have now finally had the time to test the changes on our servers and they are working fine. I think this issue can be closed now.
Hi, We are having a problem with adding additional tags. We try to commit, add additional tags and then push. Commit works fine but when additional tags are added a NPE is thrown instead.
I did a slight modification in DockerSlave.java to this logger:
I made the logger to also print the exception:
This gave more insight to what was going on:
No other changes were made to the code.
Possible cause:
After going through the code at the point where the error was caught, i found this:
DockerSlave.java:
Is the null intentional? If so how can we get tagging to work again on our project?
This method call takes the null all the way to docker-javas TagImageCmdImpl.java and to this part of the code:
and that goes to here in the same file:
Then the checkNotNull method throws a NPE, because null was given as the repository parameter.
This was tested on a localhost jenkins, docker and with evarga/jenkins-slave image.
Full logs
with modified "Could not add additional tags" line:
Installed Plugins:
Cloud configuration block:
Docker:
Manage Old Data:
Nothing
To reproduce:
Install plugin and start own jenkins on localhost, then pull everga/jenkins and push it to own registry that is set up on localhost. Configure the plugin to use http://localhost:4243 as docker registry url and pushed evarga/jenkins image as the base image. Create freestyle job and use the "Additional tag to add" field, check the "Push on successful build" and build. We are behind a company proxy, if that affects the behavior of the plugin somehow.