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

NullPointerException after upgrading to 0.29.0 #1200

Closed
papegaaij opened this issue Apr 10, 2019 · 14 comments · Fixed by #1202
Closed

NullPointerException after upgrading to 0.29.0 #1200

papegaaij opened this issue Apr 10, 2019 · 14 comments · Fixed by #1202
Assignees

Comments

@papegaaij
Copy link

Description

After upgrading from 0.28.0 to 0.29.0 we get the folloing NullPointerException when trying to build a docker image:

Caused by: java.lang.NullPointerException
    at io.fabric8.maven.docker.config.BuildImageConfiguration.getAbsoluteContextDirPath (BuildImageConfiguration.java:329)
    at io.fabric8.maven.docker.assembly.DockerAssemblyManager$1.customize (DockerAssemblyManager.java:133)
    at io.fabric8.maven.docker.assembly.DockerAssemblyManager.createBuildTarBall (DockerAssemblyManager.java:312)
    at io.fabric8.maven.docker.assembly.DockerAssemblyManager.createDockerTarArchive (DockerAssemblyManager.java:179)
    at io.fabric8.maven.docker.service.ArchiveService.createArchive (ArchiveService.java:123)
    at io.fabric8.maven.docker.service.ArchiveService.createArchive (ArchiveService.java:118)
    at io.fabric8.maven.docker.service.BuildService.buildImage (BuildService.java:117)
    at io.fabric8.maven.docker.service.BuildService.buildImage (BuildService.java:65)
    at io.fabric8.maven.docker.BuildMojo.buildAndTag (BuildMojo.java:73)
    at io.fabric8.maven.docker.BuildMojo.processImageConfig (BuildMojo.java:104)
    at io.fabric8.maven.docker.BuildMojo.executeInternal (BuildMojo.java:60)
    at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:225)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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)

Other than the version, we did not change any configuration.

Info

  • d-m-p version : 0.29.0
  • Maven version (mvn -v) :
Apache Maven 3.5.4
Maven home: /usr/share/maven
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-17-generic", arch: "amd64", family: "unix"
  • Docker version : Docker version 18.06.1-ce, build e68fc7a
@rohanKanojia
Copy link
Member

rohanKanojia commented Apr 10, 2019

@papegaaij : Oh 😞 , apologies for the inconvenience caused. could you please share a sample pom with which I can reproduce this issue?

@rohanKanojia
Copy link
Member

rohanKanojia commented Apr 10, 2019

@papegaaij : What is your configuration? Could you please share? Are you using any dockerfile while building?

@rohanKanojia rohanKanojia self-assigned this Apr 10, 2019
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 10, 2019
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 10, 2019
@rohanKanojia
Copy link
Member

@papegaaij : Hi, I tried a bunch of samples but could not reproduce your issue. I've raised #1202 with possible suspicion. Could you please share a pom with which you reproduced this issue? If you don't want to share pom(in case of closed source). You can make up some similar dummy project reproducing the issue.

@sylvainmouquet
Copy link

+1 same here

@rohanKanojia
Copy link
Member

@sylvainmouquet : Hi, Could you please share a sample pom with which I can reproduce this ???

@papegaaij
Copy link
Author

I've created a very simple project that triggers the NPE: https://github.com/papegaaij/maven-docker-npe Downgrading to 0.28.0 fixes the error.

@rhuss
Copy link
Collaborator

rhuss commented Apr 12, 2019

Thanks ! @rohanKanojia Its that the <dockerFile> provided is doesn't have any directory part. So for the ix we should use file.getAbsoluteFIlePath().parentFile() instead of just file.getParentFile().

@rohanKanojia
Copy link
Member

okay, let me confirm it(to stay safe) then I'll update PR

rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 12, 2019
@rohanKanojia
Copy link
Member

@papegaaij : Okay, so I tested it with your fix and NullPointerException was resolved. But there was some other error:

[INFO] DOCKER> Status: Image is up to date for docker.io/postgres:11
[INFO] DOCKER> Pulled postgres:11 in 6 seconds 
[INFO] Building tar: /home/Rohaan/work/repos/maven-docker-npe/target/docker/docker.topicusonderwijs.nl/keyhub/keyhub-db/14.1-SNAPSHOT/tmp/docker-build.tar
[INFO] DOCKER> [docker.topicusonderwijs.nl/keyhub/keyhub-db:14.1-SNAPSHOT]: Created docker-build.tar in 34 milliseconds
[INFO] DOCKER> Step 1/3 : FROM postgres:11
[INFO] DOCKER> ---> 9c116111eb08
[INFO] DOCKER> Step 2/3 : VOLUME /var/log/postgresql
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> 4ee55faea159
[INFO] DOCKER> Step 3/3 : COPY createschema.sql /docker-entrypoint-initdb.d/
[ERROR] DOCKER> Unable to build image [docker.topicusonderwijs.nl/keyhub/keyhub-db:14.1-SNAPSHOT] : "lstat createschema.sql: no such file or directory"  ["lstat createschema.sql: no such file or directory" ]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.473 s
[INFO] Finished at: 2019-04-12T13:30:36+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.29-SNAPSHOT:build (default-build) on project keyhub-docker-db: Unable to build image [docker.topicusonderwijs.nl/keyhub/keyhub-db:14.1-SNAPSHOT] : "lstat createschema.sql: no such file or directory"  -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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

rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 12, 2019
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 12, 2019
@papegaaij
Copy link
Author

This file does exist in the repository and with 0.28.0 it is found, so this is a regression.

@rhuss
Copy link
Collaborator

rhuss commented Apr 12, 2019

Yes, indeed.

Looks like the context directory is not set properly to point to the dir containing this sql file.

@rohanKanojia
Copy link
Member

ah, okay. let me check 😞

rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 12, 2019
@rohanKanojia
Copy link
Member

BuildImageConfiguration is not aware of the source directory(src/main/docker) which had Dockerfile in this case. But during creating docker tar, we're fetching Dockerfile considering source directory(which is fetched from MojoParams) in DockerAssemblyManager:

During adding contextDir support we've changed DefaultFileSet initialization to initialize from contextDir instead of that dockerFile that was generated above.

https://github.com/fabric8io/docker-maven-plugin/pull/1189/files#diff-dc400306e02b5f3fd827516ead371e09L133

@rhuss
Copy link
Collaborator

rhuss commented Apr 12, 2019

src/main/docker is/was just the default when adockerFile is given as a relative path and no dockerFileDir (or contextDir) is set.

According to the docs:

All paths can be either absolute or relative paths (except when both dockerFileDir and dockerFile are provided in which case dockerFile must not be absolute). A relative path is looked up in ${project.basedir}/src/main/docker by default. You can make it easily an absolute path by using ${project.basedir} in your configuration.

rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 12, 2019
rhuss added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Apr 21, 2019
rhuss pushed a commit that referenced this issue Apr 21, 2019
* Fix #1200: NullPointerException in BuildImageConfiguration

Fixed my mistake.

* chore: Added additional test

* chore(BuildMojo): Fix and add test for contextDir handling

Related to #1200
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

Successfully merging a pull request may close this issue.

4 participants