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

.mavenrc not honored #909

Open
reissseb opened this issue Feb 13, 2024 · 9 comments
Open

.mavenrc not honored #909

reissseb opened this issue Feb 13, 2024 · 9 comments

Comments

@reissseb
Copy link

I am using the Maven plugin dockerfile-maven-plugin to build a Docker image for a maven module.

To build the image I just run mvn package. I have to login to the company registry once with docker login before running the Maven build for the first time. After that I don't have to do anything anymore. mvn package is enough to build my image.

But that doesn't work with mvnd package:

[INFO] --- dockerfile:1.4.13:build (package) @ <module> ---
[INFO] Google Container Registry support is disabled
[INFO] dockerfile: <path>/target/Dockerfile
[INFO] contextDirectory: <path>/<module>
[INFO] Building Docker context <path>/<module>
[INFO] Path(dockerfile): <path>/<module>/target/Dockerfile
[INFO] Path(contextDirectory): <path>/<module>
[INFO]
[INFO] Image will be built as <company-registry-url>/<registry-path>/<module-name>:<version>
[INFO]
[INFO] Step 1/20 : FROM <company-registry-url>/eclipse-temurin:17.0.8_7-jre-alpine
[INFO]
[ERROR] Head "<company-registry-url>/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required
[WARNING] An attempt failed, will retry 1 more timesorg.apache.maven.plugin.MojoExecutionException: Could not build image

[omitted stack trace]

Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.13:build (package) on project <module> Could not build image: Head "<company-url>/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required -> [Help 1]

It looks a bit like, that mvnd doesn't use the local docker daemon to build the image

The problem sounds similar to #157

@ppalaga
Copy link
Contributor

ppalaga commented Feb 13, 2024

Could you please run mvnd package -e and paste the stack trace?

@ppalaga
Copy link
Contributor

ppalaga commented Feb 13, 2024

The problem sounds similar to #157

Why do you think so? I do not see any system properties mentioned in your report.

@ppalaga
Copy link
Contributor

ppalaga commented Feb 13, 2024

BTW, does the problem persist when you start with a fresh daemon after authenticating with docker? Something like

docker login
mvnd --stop
mvnd package

If that works, it could mean that the docker plugin is keeping some global state, which would have to be fixed in the plugin.

@reissseb
Copy link
Author

BTW, does the problem persist when you start with a fresh daemon after authenticating with docker? Something like

docker login
mvnd --stop
mvnd package

If that works, it could mean that the docker plugin is keeping some global state, which would have to be fixed in the plugin.

No, still fails with missing authentication. I only have to login to our Docker registry once. After a successful login, mvn package just works (also docker pull/push).
Only a manual docker logout or an update of the authentication parameters would let the build fail.

@reissseb
Copy link
Author

Could you please run mvnd package -e and paste the stack trace?

$ mvnd package

[omitted previous steps like compile]

[INFO] --- dockerfile:1.4.13:build (package) @ <module> ---
[INFO] Google Container Registry support is disabled
[INFO] dockerfile: <path>/target/Dockerfile
[INFO] contextDirectory: <path>/<module>
[INFO] Building Docker context <path>/<module>
[INFO] Path(dockerfile): <path>/<module>/target/Dockerfile
[INFO] Path(contextDirectory): <path>/<module>
[INFO]
[INFO] Image will be built as <company-registry-url>/<module>:<version>
[INFO]
[INFO] Step 1/20 : FROM <company-registry-url>/eclipse-temurin:17.0.8_7-jre-alpine
[INFO]
[ERROR] Head "<company-registry-url/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required
[WARNING] An attempt failed, will retry 1 more timesorg.apache.maven.plugin.MojoExecutionException: Could not build image
    at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:247)
    at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:135)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:265)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:254)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:143)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:318)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:214)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:74)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:111)
    at io.takari.maven.builder.smart.SmartBuilderImpl.buildProject (SmartBuilderImpl.java:209)
    at io.takari.maven.builder.smart.SmartBuilderImpl$ProjectBuildTask.run (SmartBuilderImpl.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:840)
Caused by: com.spotify.docker.client.exceptions.DockerException: Head "<company-registry-url>/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required
    at com.spotify.plugin.dockerfile.LoggingProgressHandler.handleError (LoggingProgressHandler.java:105)
    at com.spotify.plugin.dockerfile.LoggingProgressHandler.progress (LoggingProgressHandler.java:63)
    at com.spotify.docker.client.DefaultDockerClient$BuildProgressHandler.progress (DefaultDockerClient.java:312)
    at com.spotify.docker.client.ProgressStream.tail (ProgressStream.java:77)
    at com.spotify.docker.client.DefaultDockerClient$ResponseTailReader.call (DefaultDockerClient.java:2754)
    at com.spotify.docker.client.DefaultDockerClient$ResponseTailReader.call (DefaultDockerClient.java:2738)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:840)
[INFO] Google Container Registry support is disabled
[INFO] dockerfile: <path>/target/Dockerfile
[INFO] contextDirectory: <path>/<module>
[INFO] Building Docker context <path>/<module>
[INFO] Path(dockerfile): <path>/<module>/target/Dockerfile
[INFO] Path(contextDirectory): <path>/<module>
[INFO]
[INFO] Image will be built as <company-registry-url>/<module>:<version>
[INFO]
[INFO] Step 1/20 : FROM <company-registry-url>/eclipse-temurin:17.0.8_7-jre-alpine
[INFO]
[ERROR] Head "<company-registry-url>/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] Total time:  33.002 s (Wall Clock)
[INFO] Finished at: 2024-02-14T07:09:46Z
[INFO] --------------------------------------------------------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.13:build (package) on project <module>: Could not build image: Head "<company-registry-url>/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required -> [Help 1]org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.13:build (package) on project <module>: Could not build image
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:336)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:318)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:214)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:74)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:111)
    at io.takari.maven.builder.smart.SmartBuilderImpl.buildProject (SmartBuilderImpl.java:209)
    at io.takari.maven.builder.smart.SmartBuilderImpl$ProjectBuildTask.run (SmartBuilderImpl.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:840)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not build image
    at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:247)
    at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:135)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:265)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:254)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:143)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:318)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:214)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:74)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:111)
    at io.takari.maven.builder.smart.SmartBuilderImpl.buildProject (SmartBuilderImpl.java:209)
    at io.takari.maven.builder.smart.SmartBuilderImpl$ProjectBuildTask.run (SmartBuilderImpl.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:840)
Caused by: com.spotify.docker.client.exceptions.DockerException: Head "<company-registry-url>/eclipse-temurin/manifests/17.0.8_7-jre-alpine": unknown: Authentication is required
    at com.spotify.plugin.dockerfile.LoggingProgressHandler.handleError (LoggingProgressHandler.java:105)
    at com.spotify.plugin.dockerfile.LoggingProgressHandler.progress (LoggingProgressHandler.java:63)
    at com.spotify.docker.client.DefaultDockerClient$BuildProgressHandler.progress (DefaultDockerClient.java:312)
    at com.spotify.docker.client.ProgressStream.tail (ProgressStream.java:77)
    at com.spotify.docker.client.DefaultDockerClient$ResponseTailReader.call (DefaultDockerClient.java:2754)
    at com.spotify.docker.client.DefaultDockerClient$ResponseTailReader.call (DefaultDockerClient.java:2738)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:840)

@ppalaga
Copy link
Contributor

ppalaga commented Feb 14, 2024

I guess one would have to debug the execution of the plugin to see why it does not pick the credentials. Esp. the AuthSuppliers enabled in https://github.com/spotify/dockerfile-maven/blob/986f960cb82085d2f666acd6c2682672d47f5bb0/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java#L450 would be interesting.
You can pass -Dmvnd.debug to mvnd to start the daemon in debug mode. See mvnd --help for more info.

@reissseb
Copy link
Author

The problem is the property -Ddockerfile.useMavenSettingsForAuth of the plugin dockerfile-maven-plugin.

I set it to true in my .mavenrc file.

Setting it as a CLI option does work:

mvnd package -Ddockerfile.useMavenSettingsForAuth=true

So does adding it to the [project-home]/.mvn/jvm.config like stated in this comment: #567 (comment)

But it does not work, when I add it to the user property file ~/.m2/mvnd.properties like this:
mvnd.jvmArgs=-Ddockerfile.useMavenSettingsForAuth\=true

Stated in this comment: #567 (comment)

How can I achieve that? Is that even possible?

(we set other options like the path to a keystore with -Djavax.net.ssl.keyStore). So I would like to set these options in the property file of the user

@ppalaga
Copy link
Contributor

ppalaga commented Feb 15, 2024

Thanks for the investigation @reissseb.

Apparently mvnd does not honor .mavenrc.

In case of stock Maven it is sourced inside the mvn shell script:

  if [ -f "$HOME/.mavenrc" ] ; then
    . "$HOME/.mavenrc"
  fi

It is honored by mvnd.sh though - using mvnd.sh instead of mvnd would be the most straightforward workaround for your problem.

I do not think mvnd.properties is the right place for this.

Another possible way of solving this would be to put those local properties into a profile in settings.xml that would be active by default.

@gnodet do you think we should support .mavenrc?

@ppalaga ppalaga changed the title Building docker image with "dockerfile-maven-plugin" does not work with private (company) registry .mavenrc not honored Feb 15, 2024
@reissseb
Copy link
Author

That doesn't work either. The property is set as a MAVEN_OPTS in the .mavenrc:

MAVEN_OPTS="-Ddockerfile.useMavenSettingsForAuth=true"

And MAVEN_OPTS is not supported by mvnd AFAIK.

I guess I am back to using jvm.config or the CLI option.

Thanks for your help @ppalaga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants