fabric8io / docker-maven-plugin

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

Wrong artifact name when building during a deploy phase #1485

Open dadoonet opened 3 years ago

dadoonet commented 3 years ago

Description

So let me try to explain the behavior.

I have a project where I'm building the docker image within the deploy phase. (Which is probably a bad idea).

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>docker-build-push</id>
            <phase>deploy</phase>
            <goals>
                <goal>build</goal>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I'm able to fix my build by splitting both phases (as shown below) but I think it's a bug that the behavior changes depending if you just have deployed or not the artifact before.

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>docker-build</id>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
        <execution>
            <id>docker-push</id>
            <phase>deploy</phase>
            <goals>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
</plugin>

What is funny in this story, is that the behavior changes if you call maven with -Dmaven.deploy.skip=true. In that case, the artifact is not uploaded to OSS Sonatype and then the local version is actually used instead of the remote one. So the docker build is correct. 😄

Info

Server: Docker Engine - Community Engine: Version: 20.10.5 API version: 1.41 (minimum version 1.12) Go version: go1.13.15 Git commit: 363e9a8 Built: Tue Mar 2 20:15:47 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.3 GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b runc: Version: 1.0.0-rc92 GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff docker-init: Version: 0.19.0 GitCommit: de40ad0



Hope this helps.
rohanKanojia commented 3 years ago

Thanks for reporting. I'll try to reproduce this and see if it's maven behavior or a bug in plugin itself. Do you have some sample reproducer project to try out?

dadoonet commented 3 years ago

@rohanKanojia Sadly not. But I could try to build one if you need it.