Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker credentials and docker push #11

Closed
savishy opened this issue Aug 5, 2016 · 3 comments
Closed

docker credentials and docker push #11

savishy opened this issue Aug 5, 2016 · 3 comments

Comments

@savishy
Copy link
Owner

savishy commented Aug 5, 2016

While working on #10 I am encountering the following issue

  • to be able to docker push, a credentials is needed to be pre-stored in the jenkins container.
  • I created a set of credentials (for docker hub) in Jenkins in the credentials module.
  • this output a credentials.xml in JENKINS_HOME, which I then extracted.
  • I am pushing this credentials XML into JENKINS_HOME while building the Jenkins image
  • However, it seems the same encoding is not used everytime so the credentials.xml is not valid across Jenkins installations.
  • i.e pulling this from one running Jenkins instance, then pushing it into a different instance does not seem to work.

As a result, docker push does not work unless you manually edit the credentials through UI before docker-pushing .

Notes:

  • have tried using jenkins-cli. Could not figure out (despite trying for hours) how to use create-credentials-by-xml.
  • have tried using the docker remote API call as well (curl -X POST /images/name/push). Encountering weird login issue."
    [attempt-2 053aca1] Jenkins Job should create and push a tomcat + web-app Docker Image #10 encountering issue docker credentials and docker push  #11 - to be able to docker push, a credentials is needed to be pre-stored in the jenkins container. - I created a set of credentials (for docker hub) in Jenkins in the credentials module. - this output a credentials.xml in JENKINS_HOME, which I then extracted. - I am pushing this credentials XML into JENKINS_HOME while building the Jenkins image - However, it seems the same encoding is not used everytime so the credentials.xml is not valid across Jenkins installations. - i.e pulling this from one running Jenkins instance, then pushing it into a different instance does not seem to work.
@savishy savishy added this to the v0.2 milestone Aug 5, 2016
savishy added a commit that referenced this issue Aug 6, 2016
- maven step will pull directly from spring-projects/spring-petclinic github.
- after building and testing, petclinic WAR is the artifact of this job.
- downstream job is docker build. This uses copy artifact plugin to copy upstream artifact WAR into its workspace.
- then it takes care of building and pushing image (this part is still WIP, waiting on #11)

The advantage of this approach is I dont need to fork petclinic github and add a dockerfile to that project.
@savishy
Copy link
Owner Author

savishy commented Aug 6, 2016

To push image using Docker, I have several options:

Option 1

docker login [-u -p]
docker push savishy/tomcat-petclinic

This would work but not in an automated Jenkins container scenario. In a Jenkins container I don't have the docker command.

Option 2

The second option: Use the Docker Build Steps plugin.
The issue here is that I need to pre-load the credentials (in the form of credentials.xml) which does not seem to work across multiple Jenkins instances.

Option 3

The third option:

  • Jenkins container has API access to the Docker daemon running on the host machine.
  • To push via API I do
root@09fd175fdff4:/usr/share/jenkins/ref/plugins# curl -X POST http://172.17.0.1:2375/images/savishy/tomcat-petclinic/push

Where 172.17.0.1 is the IP of the Docker Host. 2375 is the port where Docker daemon is listening.

In this approach I need to feed in additional --header parameters:
{"message":"Bad parameters and missing X-Registry-Auth: EOF"}

XRA=`echo "{\"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\", \"email\": \"${EMAIL_ADDRESS}\", \"serveraddress\" : \"${SERVER_ADDRESS}\"}" | base64 --wrap=0`
curl  -v --request POST --header "X-Registry-Auth: $XRA" 

Special characters such as ! and @ in the password have to be escaped obviously.

Option 4

Trying another plugin, Cloudbees Docker Publish.
Any plugin will ultimately come back to the problem of autoloading credentials mentioned in Option 2.

Update

The curl approach works (at least it starts pushing). However it is finicky and depends on internet.

I frequently get any of the following errors:

{"errorDetail":{"message":"net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"},"error":"net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"}
{"errorDetail":{"message":"dial tcp: lookup auth.docker.io on 127.0.1.1:53: read udp 127.0.0.1:42997-\u003e127.0.1.1:53: i/o timeout"},"error":"dial tcp: lookup auth.docker.io on 127.0.1.1:53: read udp 127.0.0.1:42997-\u003e127.0.1.1:53: i/o timeout"}

@savishy
Copy link
Owner Author

savishy commented Aug 8, 2016

It is possible that all these problems are because I use the official Jenkins docker image for building my Jenkins docker container.

I ran a quick experiment on Saturday and it shows I need to explore building the Jenkins image from scratch. (Issue #12 )

savishy added a commit that referenced this issue Aug 8, 2016
- instead of official jenkins image.
- hopefully this might affect #11
@savishy
Copy link
Owner Author

savishy commented Aug 11, 2016

The curl -X POST of the docker image works properly when Jenkins container is in AWS. Considering this issue fixed.

@savishy savishy closed this as completed Aug 11, 2016
savishy added a commit that referenced this issue Aug 11, 2016
- working implementation of using curl -X POST and connecting to docker daemon on the host
- the daemon is contacted to push the docker image to hub
savishy added a commit that referenced this issue Aug 11, 2016
docker daemon running on the host needs the correct commandline options; so a modifed /etc/sysconfig/docker is needed
savishy added a commit that referenced this issue Aug 11, 2016
savishy added a commit that referenced this issue Aug 12, 2016
- the latest built image should be tagged with latest as well as the build number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant