docker-maven-plugin icon indicating copy to clipboard operation
docker-maven-plugin copied to clipboard

Wrong artifact name when building during a deploy phase

Open dadoonet opened this issue 4 years ago • 2 comments

Description

  • TL;DR: when using mvn deploy, docker plugin downloads the latest uploaded artifact from sonatype and does not use the finalName of the artifact.
  • TL;DR: do not build your docker image within a deploy phase.

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

  • docker-maven-plugin version : 0.36.1
  • Maven version (mvn -v) :
Maven home: /Users/dpilato/.sdkman/candidates/maven/current
Java version: 15.0.1, vendor: Oracle Corporation
Java home: /Users/dpilato/.sdkman/candidates/java/15.0.1-open
Default locale: fr_FR, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
  • Docker version :
Client: Docker Engine - Community
 Cloud integration: 1.0.9
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:13:00 2021
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

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.

dadoonet avatar Jul 27 '21 14:07 dadoonet

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?

rohanKanojia avatar Jul 27 '21 16:07 rohanKanojia

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

dadoonet avatar Jul 27 '21 16:07 dadoonet