fabric8io / docker-maven-plugin

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

docker:tag fails with: Cannot invoke "io.fabric8.maven.docker.config.BuildImageConfiguration.cleanupMode()" because "buildConfig" is null #1610

Open OndraZizka opened 1 year ago

OndraZizka commented 1 year ago

Description

I'm trying to create a docker tagged image with Docker Maven Pugin.

The build goal works, but when trying to tag the image, DMP fails:

Execution start of goal io.fabric8:docker-maven-plugin:0.40.2:tag failed: Cannot invoke "io.fabric8.maven.docker.config.BuildImageConfiguration.cleanupMode()" because "buildConfig" is null

Same if I try with mvn docker:tag: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.40.2:tag failed: Cannot invoke "io.fabric8.maven.docker.config.BuildImageConfiguration.cleanupMode()" because "buildConfig" is null

The build of the image happens before that:

[INFO] --- docker-maven-plugin:0.40.2:build (start) @ tracker-service ---
[INFO] Reading assembly descriptor: /home/o/work/tracker-service/src/main/docker/docker-assembly.xml
[INFO] Copying files to /home/o/work/tracker-service/target/docker/mycompany/tracker-service/1.0-SNAPSHOT/build/maven
[INFO] Building tar: /home/o/work/tracker-service/target/docker/mycompany/tracker-service/1.0-SNAPSHOT/tmp/docker-build.tar

I have tried to search for what buildConfig. I assume it is a model for the <build> section of the respective image. But that one works for build.

Info

    <plugin>
        <!-- The Docker Maven plugin is used to create docker image with the fat jar -->
        <groupId>io.fabric8</groupId><artifactId>docker-maven-plugin</artifactId><version>${version.docker-maven-plugin}</version>
        <configuration>
            <images>
                <image>
                    <alias>mongo</alias>
                    <name>mongo:5</name>
                    <run>
                        <wait><time>6000</time><log>Waiting for connections</log></wait>
                        <log><prefix>MO</prefix><color>yellow</color></log>
                        <!-- Assign dynamically mapped ports to maven variable (which can be reused in integration tests) -->
                        <ports><port>mongo.port:27017</port></ports>
                        <env>
                            <MONGO_INITDB_ROOT_USERNAME>root</MONGO_INITDB_ROOT_USERNAME>
                            <MONGO_INITDB_ROOT_PASSWORD>kotlin4ever</MONGO_INITDB_ROOT_PASSWORD>
                        </env>
                    </run>
                </image>

                <!-- Image holding the artifact of this build -->
                <image>
                    <alias>service</alias><!-- Alias name which can used for linking containers during runtime -->
                    <name>dacadoo/${project.artifactId}:${project.version}</name>

                    <build>
                        <from>openjdk:20</from>
                        <assembly>
                            <descriptor>${basedir}/src/main/docker/docker-assembly.xml</descriptor>
                            <!--
                            <descriptorRef>artifact-with-dependencies</descriptorRef>
                            -->
                        </assembly>
                        <ports><port>8080</port></ports>
                        <!--
                        <cmd>java -jar /maven/tracker-service.jar</cmd>
                        -->
                        <entryPoint><exec><arg>java</arg><arg>-jar</arg><arg>/tracker-service.jar</arg></exec></entryPoint>
                    </build>

                    <!-- Runtime configuration for starting/stopping/linking containers -->
                    <run>
                        <!-- Assign dynamically mapped ports to maven variables (which can be reused in integration tests) -->
                        <ports><port>service.port:8080</port></ports>
                        <wait>
                            <time>10000</time><url>http://${docker.host.address}:${service.port}/health</url>
                        </wait>
                        <links><link>mongo:mongo</link></links>
                        <log><prefix>TS</prefix><color>cyan</color></log>
                    </run>
                </image>
            </images>
        </configuration>

        <!-- Hooking into the lifecycle -->
        <executions>
                    <execution><id>start</id><goals><goal>build</goal></goals><phase>pre-integration-test</phase></execution>
                    <execution><id>stop</id><goals><goal>tag</goal></goals><phase>post-integration-test</phase></execution>
        </executions>
    </plugin>
OndraZizka commented 1 year ago

I've also posted a StackOverflow question in case it's me using it wrongly: https://stackoverflow.com/questions/73933182/fabric8-docker-maven-plugin-dockertag-fails-with-cannot-invoke-buildimageconf

rhuss commented 1 year ago

Yes, it could be that a mvn docker:tag iterates over all image configurations and fails if a build section is missing (which is the case for your mongo DB image). If so, this is a bug. Happy to take any help for fixing this.

As alternative you might consider to leverage the <tags> option in the build configuration for tagging, instead of docker:tag.