fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 643 forks source link

NPE when using <external> #1253

Open OndraZizka opened 5 years ago

OndraZizka commented 5 years ago

Description

When using <external>, DMP throws a NPE. Following the docs at https://dmp.fabric8.io/#combining-property-config .

Info

* Docker version :Docker version 18.04.0-ce, build 3d479c0
* If it's a bug, how to reproduce :
It seems it's caused by lack of some expected property.
            <configuration>
                <logDate>default</logDate>
                <useColor>true</useColor>
                <verbose>build</verbose>
                <logStdout>true</logStdout>
                <autoPull>true</autoPull>
                <images>
                    <!-- RocketDB with Dev Tools. -->
                    <image>
                        <alias>centos7-devtools</alias>
                        <name>gitlab.k.arpage.ch:4999/ad-swiss/ad-epd/rocketdb:centos7-with-dev</name>
                        <external>
                            <type>properties</type>
                            <prefix>docker</prefix>
                            <mode>override</mode>
                        </external>
                        <build>
                            <tags></tags>
                            <from>centos:7</from>
                            <runCmds>
                                <!-- set -e; set -o pipefail; shopt -s inherit_errexit; -->
                                <run>yum update -y</run>
                                <run>yum install -y curl wget unzip tree git openssl openssh-client</run>

                                <run>mkdir -p /sw/ &amp;&amp; chmod a+rwx /sw/</run>
                                <!--<run>yum -y install maven</run> Gives 3.0.5 -->
                                <run>( \
                                    wget --no-verbose -O jdk12.tgz https://download.java.net/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_linux-x64_bin.tar.gz; \
                                    tar xvzf jdk12.tgz -C /sw/; \
                                    rm jdk12.tgz; \
                                    rm -rf /sw/jdk12; \
                                    mv /sw/*jdk* /sw/jdk12; \
                                    java -version; \
                                )</run>
                                <!--
                                echo 'export PATH="$PATH:/sw/jdk12/bin"' >> ~/.bashrc; \
                                echo 'export JAVA_HOME=/sw/jdk12' >> ~/.bashrc; \
                                export PATH="$PATH:/sw/jdk12/bin"; \
                                -->

                                <run>wget --no-verbose -O maven.zip http://www.pirbot.com/mirrors/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.zip</run>
                                <run>unzip maven.zip -d /sw/</run>
                                <run>rm maven.zip</run>
                                <run>rm -rf /sw/maven</run>
                                <run>mv /sw/apache-maven-* /sw/maven</run>
                                <!--
                                <run>echo 'export PATH="$PATH:/sw/maven/bin"' >> ~/.bashrc</run>
                                <run>echo 'export M2_HOME=/sw/maven' >> ~/.bashrc</run>
                                <run>export PATH="$PATH:/sw/maven/bin"</run>
                                -->
                                <run>mvn -v</run>
                            </runCmds>
                            <optimise>false</optimise>
                            <cmd>/bin/bash</cmd>
                        </build>
                        <run>
                            <env><JAVA_HOME>/sw/jdk12</JAVA_HOME></env>
                            <env><M2_HOME>/sw/maven</M2_HOME></env>
                            <env><PATH>$M2_HOME/bin:$JAVA_HOME/bin:$PATH</PATH></env>
                        </run>
                    </image>
                </images>
            </configuration>

...

/sw/jdk12:/sw/maven:$PATH
This throws:

Caused by: java.lang.NullPointerException at io.fabric8.maven.docker.config.handler.property.PropertyConfigHandler.extractBuildConfiguration (PropertyConfigHandler.java:136) at io.fabric8.maven.docker.config.handler.property.PropertyConfigHandler.resolve (PropertyConfigHandler.java:73) at io.fabric8.maven.docker.config.handler.ImageConfigResolver.resolve (ImageConfigResolver.java:98) at io.fabric8.maven.docker.AbstractDockerMojo$1.resolve (AbstractDockerMojo.java:331) at io.fabric8.maven.docker.config.ConfigHelper.resolveConfiguration (ConfigHelper.java:159) at io.fabric8.maven.docker.config.ConfigHelper.resolveImages (ConfigHelper.java:57) at io.fabric8.maven.docker.AbstractDockerMojo.initImageConfiguration (AbstractDockerMojo.java:325) at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:224) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) 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:956) 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:567) 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)

spyderz42 commented 5 years ago

I had this happen to me as well. I fixed it, by moving away from external to docker.imagePropertyConfiguration = override in my top level pom, and docker.imagePropertyConfiguration = skip in the pom where I am setting some image build information such as name, tags, and contextDir.

I take this back.. setting the override in my top level pom ignored my Dockerfiles and completely broke my images

rhuss commented 5 years ago

There's a fix merged in recently which should solve this issue. Could you please try whether a d-m-p built from master does fix it for you ?

OndraZizka commented 5 years ago

I can try when I get to dmp again, which will be in around few weeks. If that's ok.

rhuss commented 5 years ago

I can try when I get to dmp again, which will be in around few weeks. If that's ok.

No worries. We will have then probably already the next release, to you can directly test on a released version then.

svenhaag commented 5 years ago

Same here with exact same version under Windows 10:

Caused by: java.lang.NullPointerException
    at io.fabric8.maven.docker.config.handler.property.PropertyConfigHandler.extractBuildConfiguration (PropertyConfigHandler.java:140)
    at io.fabric8.maven.docker.config.handler.property.PropertyConfigHandler.resolve (PropertyConfigHandler.java:73)
    at io.fabric8.maven.docker.config.handler.ImageConfigResolver.resolve (ImageConfigResolver.java:98)
    at io.fabric8.maven.docker.AbstractDockerMojo$1.resolve (AbstractDockerMojo.java:331)
    at io.fabric8.maven.docker.config.ConfigHelper.resolveConfiguration (ConfigHelper.java:159)
    at io.fabric8.maven.docker.config.ConfigHelper.resolveImages (ConfigHelper.java:57)
    at io.fabric8.maven.docker.AbstractDockerMojo.initImageConfiguration (AbstractDockerMojo.java:325)
    at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:224)
<image>
    <alias>app</alias>
    <name>foo/bar:latest</name>
    <build>
        <dockerFile>${project.build.directory}/work/docker/Dockerfile</dockerFile>
        <imagePullPolicy>Always</imagePullPolicy>
    </build>
    <external>
        <type>properties</type>
        <prefix>docker</prefix>
        <mode>override</mode>
    </external>
    <run>
        <ports>
            <port>docker.test.proxy.port:8443</port>
        </ports>
        <env>
            <ENABLE_DEBUG>true</ENABLE_DEBUG>
        </env>
        <wait>
            <http>
                <url>${docker.test.url}</url>
                <method>GET</method>
                <status>200</status>
            </http>
            <time>${docker.test.start.timout}</time>
        </wait>
        <log>
            <enabled>true</enabled>
            <color>cyan</color>
        </log>
    </run>
</image>
svenhaag commented 5 years ago

There's a fix merged in recently which should solve this issue. Could you please try whether a d-m-p built from master does fix it for you ?

Can you please link the corresponding issue or commit fix? Thanks.

==> I think it's this one: https://github.com/fabric8io/docker-maven-plugin/issues/1274

rohanKanojia commented 5 years ago

@svenhaag : Are you able to reproduce this error on a SNAPSHOT build of master of this plugin?

svenhaag commented 5 years ago

@svenhaag : Are you able to reproduce this error on a SNAPSHOT build of master of this plugin?

Yeah, indeed it works as expected. Thanks!

rohanKanojia commented 5 years ago

@svenhaag : cool, it would be released soon

rhuss commented 4 years ago

Let's plan a release for the weekend.