spotify / docker-maven-plugin

INACTIVE: A maven plugin for Docker
Apache License 2.0
2.66k stars 575 forks source link

mvn -DpushImage Fail : no basic auth credentials #309

Closed CuriousJDev closed 7 years ago

CuriousJDev commented 7 years ago

Description

I am trying to push Docker image to my nexus3 private repo for Docker which is Ubuntu over virtualBox. I have nexus running over HTTPS and When I have verified over command line using below commands then I am able to push successfully in nexus

$> docker login -u <username> -p <password> <fully qualified machine name :SSL port of repo>
$> docker push <fully qualified machine name :SSL port of repo>/<image-name>:latest

But when trying in Jenkins using maven command

$>mvn -gs /usr/share/maven/conf/settings.xml clean -X package docker:build -DpushImage

Then I am getting below stacktrace

[WARNING] Failed to push linuxVB:18079/release, retrying in 10 seconds (5/5).
[INFO] Pushing linux:18079/release
The push refers to a repository [linuxVB:18079/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:39 min
[INFO] Finished at: 2017-02-08T12:44:31+00:00
[INFO] Final Memory: 37M/90M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project release: Exception caught: no basic auth credentials -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project release: Exception caught
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Exception caught
    at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:130)
    at com.spotify.docker.BuildMojo.execute(BuildMojo.java:86)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: com.spotify.docker.client.exceptions.DockerException: no basic auth credentials
    at com.spotify.docker.client.AnsiProgressHandler.progress(AnsiProgressHandler.java:52)
    at com.spotify.docker.Utils$DigestExtractingProgressHandler.progress(Utils.java:150)
    at com.spotify.docker.client.ProgressStream.tail(ProgressStream.java:77)
    at com.spotify.docker.client.DefaultDockerClient.push(DefaultDockerClient.java:1040)
    at com.spotify.docker.Utils.pushImage(Utils.java:83)
    at com.spotify.docker.BuildMojo.execute(BuildMojo.java:363)
    at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:128)
    ... 23 more
[ERROR] 
[ERROR]

I have added nexus repo credential in setting.xml

<server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
      <configuration>
            <email>abc@email.com</email>
      </configuration>
    </server>
  </servers>

also config.json has auth entry for repo

{
    "auths": {
        "<jenkins host name:repo port>": {
            "auth": "XWZtaW53YWRtaW4xMjM="
        }
    }
}

What do you expect

Expect it to push image.

What happened instead

Getting exception for no basic auth found and using $docker images

I can see my image is built successfully.

I am not sure what am I doing?

Thanks

Software:

Full backtrace

[DEBUG] Auth Config null
[DEBUG] Registry Config Json {"":{"serveraddress":"","password":"","auth":"","email":"","username":""}}
[DEBUG] Registry Config Encoded eyIiOnsic2VydmVysImVtYWlsIjoiIiwidXNlcm5hbWUiOiIifX0=
Step 1/6 : FROM frolvlad/alpine-oraclejdk8:slim
 ---> 83b387a3b515
Step 2/6 : VOLUME /tmp
 ---> Using cache
 ---> b2b5bfb3bbd8
Step 3/6 : ADD release-0.0.1.jar app.jar
 ---> 0b8cd11640f1
Removing intermediate container 28b47d6027c6
Step 4/6 : RUN sh -c 'touch /app.jar'
 ---> Running in d7a749627889
 ---> 26340fe61db4
Removing intermediate container d7a749627889
Step 5/6 : ENV JAVA_OPTS ""
 ---> Running in 7097f82b28bd
 ---> f9ad2a6b6ff9
Removing intermediate container 7097f82b28bd
Step 6/6 : ENTRYPOINT sh -c java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
 ---> Running in f90c99745c0e
 ---> f92d7d0bf711
Removing intermediate container f90c99745c0e
Successfully built f92d7d0bf711
[INFO] Built linuxVB:18077/release
[INFO] Pushing linuxVB:18077/release
The push refers to a repository [linuxVB:18077/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[WARNING] Failed to push linuxVB:18077/release, retrying in 10 seconds (1/5).
[INFO] Pushing linuxVB:18077/release
The push refers to a repository [linuxVB:18077/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[WARNING] Failed to push linuxVB:18077/release, retrying in 10 seconds (2/5).
[INFO] Pushing linuxVB:18077/release
The push refers to a repository [linuxVB:18077/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[WARNING] Failed to push linuxVB:18077/release, retrying in 10 seconds (3/5).
[INFO] Pushing linuxVB:18077/release
The push refers to a repository [linuxVB:18077/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[WARNING] Failed to push linuxVB:18077/release, retrying in 10 seconds (4/5).
[INFO] Pushing linuxVB:18077/release
The push refers to a repository [linuxVB:18077/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[WARNING] Failed to push linuxVB:18077/release, retrying in 10 seconds (5/5).
[INFO] Pushing linuxVB:18077/release
The push refers to a repository [linuxVB:18077/release]
7397efdb4130: Preparing 
ffa7395501fe: Preparing 
9e4a776bfca4: Preparing 
9f5e0b558c16: Preparing 
60ab55d3379d: Preparing 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:39 min
[INFO] Finished at: 2017-02-08T12:44:31+00:00
[INFO] Final Memory: 37M/90M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project release: Exception caught: no basic auth credentials -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project release: Exception caught
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Exception caught
    at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:130)
    at com.spotify.docker.BuildMojo.execute(BuildMojo.java:86)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: com.spotify.docker.client.exceptions.DockerException: no basic auth credentials
    at com.spotify.docker.client.AnsiProgressHandler.progress(AnsiProgressHandler.java:52)
    at com.spotify.docker.Utils$DigestExtractingProgressHandler.progress(Utils.java:150)
    at com.spotify.docker.client.ProgressStream.tail(ProgressStream.java:77)
    at com.spotify.docker.client.DefaultDockerClient.push(DefaultDockerClient.java:1040)
    at com.spotify.docker.Utils.pushImage(Utils.java:83)
    at com.spotify.docker.BuildMojo.execute(BuildMojo.java:363)
    at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:128)
    ... 23 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
bucht commented 7 years ago

Check that the "registryUrl" in the pom.xml refers to the entry in the config.json ("")

CuriousJDev commented 7 years ago

Thanks bucht. It was on same line serverId was missing from configuration element.

hafizullah commented 7 years ago

@CuriousJDev sorry for my ignorance, I have arrived at the same issue as you. Could you please give me an idea as to which bit is server-id once you create a repository in aws? many thanks

tdelesio commented 7 years ago

One thing I would recommend that really tripped me up was the version of the plugin. I was using a very old plugin version and it was giving me this error. When I changed to the current version it magiclly worked.

Trisia commented 5 years ago

One thing I would recommend that really tripped me up was the version of the plugin. I was using a very old plugin version and it was giving me this error. When I changed to the current version it magiclly worked.

We successfully solved this problem through your suggestion, in version 1.2.0 problem can not be solved, so we try a lower version of 1.1.1, nice, problem be solved. here is my config

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.1.1</version>
    <configuration>
        <imageName>${docker.registry}/${project.name}:${project.version}</imageName>
        <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
        <skipDockerBuild>false</skipDockerBuild>
        <pushImage>true</pushImage>
        <serverId>nexus</serverId>
        <registryUrl>${docker.registry}</registryUrl>
        <resources>
            <resource>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

note: you should config your username and password in maven configration file settings.xml

coenvl commented 5 years ago

One thing I would recommend that really tripped me up was the version of the plugin. I was using a very old plugin version and it was giving me this error. When I changed to the current version it magiclly worked.

We successfully solved this problem through your suggestion, in version 1.2.0 problem can not be solved, so we try a lower version of 1.1.1, nice, problem be solved. here is my config

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.1.1</version>
    <configuration>
        <imageName>${docker.registry}/${project.name}:${project.version}</imageName>
        <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
        <skipDockerBuild>false</skipDockerBuild>
        <pushImage>true</pushImage>
        <serverId>nexus</serverId>
        <registryUrl>${docker.registry}</registryUrl>
        <resources>
            <resource>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

note: you should config your username and password in maven configration file settings.xml

Thanks, this helped me out. Switching back to 1.1.1 did the trick for me as well.