Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-40037

Docker builds fail with "Build info capturing failed for docker image..." exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • artifactory-plugin
    • RHEL 7.2, Docker version 1.12.3, Jenkins 2.19.1(running in Docker, no agents, only master), Artifactory 4.14.1, Artifactory Plugin 2.8.1

      Description: I followed Jenkins Artifactory Plugin - Setting Up Docker Build Info and got

      java.lang.IllegalStateException: Build info capturing failed for docker image: artifactory.mycompany.com/mycompany/myproject/myservice:0.0.1.c62f0c8.72 check build info proxy configuration.
        at org.jfrog.hudson.pipeline.steps.DockerPushStep$Execution.run(DockerPushStep.java:104)
        at org.jfrog.hudson.pipeline.steps.DockerPushStep$Execution.run(DockerPushStep.java:61)
        at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution.start(AbstractSynchronousStepExecution.java:40)
        ...
      

      Docker/Server Setup:

      • Instead of using only HTTP_PROXY in /etc/systemd/system/docker.service.d/http-proxy.conf, I also added NO_PROXY to be able to access to Artifactory artifactory.mycompany.com. Please note that adding or removing HTTPS_PROXY does not change anyting. None of the following configurations worked:
        /etc/systemd/system/docker.service.d/http-proxy.conf
        Environment="HTTP_PROXY=http://localhost:9765" "NO_PROXY=.mycompany.com"
        #Environment="HTTP_PROXY=http://localhost:9765" "HTTPS_PROXY=http://localhost:9765" "NO_PROXY=.mycompany.com"
        #Environment="HTTP_PROXY=http://10.74.200.52:9765" "NO_PROXY=localhost,127.0.0.0/8,.mycompany.com"
        #Environment="HTTP_PROXY=http://10.74.200.52:9765" "HTTPS_PROXY=http://10.74.200.52:9765" "NO_PROXY=localhost,127.0.0.0/8,.mycompany.com"
        
      • Although Jenkins Artifactory Plugin - Setting Up Docker Build Info does not mention, I needed to execute sudo chmod 777 /var/run/docker.sock command to prevent following error:
        javax.ws.rs.ProcessingException: org.newsclub.net.unix.AFUNIXSocketException: Permission denied (socket: /run/docker.sock)
          at com.github.dockerjava.jaxrs.connector.ApacheConnector.apply(ApacheConnector.java:484)
          at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
          at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:683)
          ...
          at com.github.dockerjava.core.command.InspectImageCmdImpl.exec(InspectImageCmdImpl.java:40)
          at org.jfrog.hudson.pipeline.docker.utils.DockerUtils.getImageIdFromTag(DockerUtils.java:33)
          at org.jfrog.hudson.pipeline.docker.utils.DockerAgentUtils$2.call(DockerAgentUtils.java:67)
          at org.jfrog.hudson.pipeline.docker.utils.DockerAgentUtils$2.call(DockerAgentUtils.java:65)
          at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
          at org.jfrog.hudson.pipeline.docker.utils.DockerAgentUtils.registerImage(DockerAgentUtils.java:65)
        

      Jenkins Setup:

      • There is no Jenkins agent and Jenkins master runs in Docker container.
      • To be able to run docker command in the container, I prefered Docker outside of Docker(dood) solution
      • exposed port 9765 for Artifactory Plugin's internal proxy
      • used volume for Jenkins's data
      • ran Jenkins container as swarm service
      • Followed Jenkins Artifactory Plugin - Setting Up Docker Build Info by choosing port 9765
      Dockerfile.myjenkins
      FROM artifactory.mycompany.com/jenkins
      
      USER root
      
      # To be able to build Docker images within the container, we have chosen 
      # Docker outside of Docker(dood) solution in preference to Docker in 
      # Docker(dind). By using dood we are able to execute "docker" commands
      # without installing Docker into the container. See following
      # pages to get better understanding of all the benefits of dood:
      # - Jenkins with DooD (Docker outside of Docker): https://github.com/axltxl/docker-jenkins-dood
      # - Running Docker in Jenkins (in Docker): http://container-solutions.com/running-docker-in-jenkins-in-docker/
      RUN apt-get update \
       && apt-get install -y sudo \
       && rm -rf /var/lib/apt/lists/* \
       && echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers \
       && printf '#!/bin/bash\nsudo docker.bin "$@"\n' > /usr/local/bin/docker \
       && chmod +x /usr/local/bin/docker
      
      USER jenkins
      
      # Artifactory Plug-in's build-in proxy for Docker images: 
      # https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Artifactory+Plugin+-+Setting+Up+Docker+Build+Info#JenkinsArtifactoryPlugin-SettingUpDockerBuildInfo-EnabletheJenkinsBuildInfoProxy
      EXPOSE 9765
      
      Build & Push myjenkins Image
      docker build -f Dockerfile.myjenkins -t artifactory.mycompany.com/myjenkins .
      ...
      docker push artifactory.mycompany.com/myjenkins
      
      Create myjenkins Swarm Service
      docker service create --name myjenkins -p 8080:8080 -p 50000:50000 -p 9765:9765 --replicas 1 \
        --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock,readonly \
        --mount type=bind,src=$(which docker),dst=/usr/bin/docker.bin \
        --mount type=volume,src=volume_myjenkins,dst=/var/jenkins_home \
        artifactory.mkk.com.tr/myjenkins
      

      Setup Test:

      • On host machine;
        • Connected to port 9765 successfully: telnet localhost 9765
        • Executed following docker command successfully:
          docker pull artifactory.mycompany.com/hello-world
          
      • On Jenkins;
        • Created a dummy job and executed the same docker command successfully.

            eyalbe Eyal Ben Moshe
            as_kumlali Ali Sadik Kumlali
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: