Hi,
Is it possible to add new function to push multiple tags?
I saw docker-maven-plugin is already with this function.
Always we may need to push image with two tags, one is with version like 1.0.0, and another one is latest.
Thanks!
+1
I think this would do it by always tagging as latest in addition to the user's tag.
https://gist.github.com/darrylb-github/8a1bb5777bc2c5714a0b0788d92ccd1b
Can't build or test without the parent pom and permission settings restrict pushing branch / PR.
Could you have two executions, one for each tag you want to create? Like:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${version}</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>tag-latest</id>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
<execution>
<id>tag-version</id>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
</executions>
<configuration>
<repository>spotify/foobar</repository>
</configuration>
</plugin>
As @dflemstr says, you can have multiple tags, but is not possible to push both to registry with mvn dockerfile:push, even if you map the push goal to execution.
We have had the same issue, we fixed (workaround it) with two executions as proposes by @dflemstr
but only for the push, the tagging can be done with the imageTags
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>push-image-fix-version</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<skipDocker>${maven.deploy.skip}</skipDocker>
</configuration>
</execution>
<execution>
<id>push-image-latest</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<imageName>myImageName:latest</imageName>
</configuration>
</execution>
</executions>
<configuration>
<imageName>myImageName:${docker.image.version}
</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<serverId>ourServer</serverId>
<registryUrl>ourRegistry</registryUrl>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.war</include>
</resource>
</resources>
<imageTags>
<imageTag>${docker.image.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<forceTags>true</forceTags>
</configuration>
</plugin>
@schnaker85 your code snippet references the old docker-maven-plugin, shouldn't this be: dockerfile-maven-plugin?
<executions>
<execution>
<id>build-image</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>tag-image-latest</id>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
<execution>
<id>tag-image-version</id>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
<execution>
<id>push-image-latest</id>
<goals>
<goal>push</goal>
</goals>
<phase>deploy</phase>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
<execution>
<id>push-image-version</id>
<goals>
<goal>push</goal>
</goals>
<phase>deploy</phase>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
</executions>
Running multiple executions indeed works (although we push the same image twice), but we ran into another issue: each 'execution' builds and deploys a docker-info.jar. Our Nexus repository doesn't allow to reupload a stable artifact with the same name and version.
We ran into the same issue but don't bind the build, tag and push goals to any of the maven phases.
Please note i'm using version 1.3.3 of the plugin because of issue: #62
We use Gitlab CI runners for our build pipeline. So we build our (Spring Boot) jar in the first step of the pipeline.
mvn clean package
And in the next build step of our pipeline we:
docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
mvn dockerfile:build
mvn dockerfile:tag@tag-version
mvn dockerfile:push@push-latest
mvn dockerfile:push@push-version
We execute the goals of the plugin with the specific execution id.
This is our setup in our pom.xml:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${docker.file.maven.plugin.version}</version>
<executions>
<execution>
<id>build-and-tag-latest</id>
<phase>none</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>tag-version</id>
<phase>none</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
<execution>
<id>push-latest</id>
<phase>none</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
<execution>
<id>push-version</id>
<phase>none</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
</executions>
<configuration>
<repository>${docker.registry}/${docker.image.prefix}/${project.artifactId}</repository>
</configuration>
</plugin>
I hope this information is useful for other people who run into similar issues.
+1
We have solved it this way:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-plugin.version}</version>
<executions>
<execution>
<id>tag-latest</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
<execution>
<id>tag-version</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
</executions>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
+1
We have solved it this way:
<plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${dockerfile-maven-plugin.version}</version> <executions> <execution> <id>tag-latest</id> <phase>deploy</phase> <goals> <goal>build</goal> <goal>tag</goal> <goal>push</goal> </goals> <configuration> <tag>latest</tag> </configuration> </execution> <execution> <id>tag-version</id> <phase>deploy</phase> <goals> <goal>build</goal> <goal>tag</goal> <goal>push</goal> </goals> <configuration> <tag>${project.version}</tag> </configuration> </execution> </executions> <configuration> <repository>${docker.image.prefix}/${project.artifactId}</repository> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin>
good~~~
@mrclrchtr No need to build your image twice. You can get rid of the build goal in your second execution (tag-version in your case)
Summarizing with a Dockerhub example with credentials stored in settings.xml is:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<repository>docker.io/anandvarkeyphilips/enterprise-validator</repository>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
<executions>
<execution>
<id>build-tag-push-version</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
<execution>
<id>tag-push-latest</id>
<phase>deploy</phase>
<goals>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
</executions>
</plugin>
Most helpful comment
We ran into the same issue but don't bind the build, tag and push goals to any of the maven phases.
Please note i'm using version 1.3.3 of the plugin because of issue: #62
We use Gitlab CI runners for our build pipeline. So we build our (Spring Boot) jar in the first step of the pipeline.
mvn clean packageAnd in the next build step of our pipeline we:
We execute the goals of the plugin with the specific execution id.
This is our setup in our pom.xml:
I hope this information is useful for other people who run into similar issues.