The -SNAPSHOT
part of all files (attached on an Maven deployment 'task') will be replaced by the timestamped version at deploy:deploy
phase.
1) create Docker image file
Extend the artifact POM with docker-maven-plugin
(provided by spotify at https://github.com/spotify/docker-maven-plugin) .
[...]
You can also bind the build goal to the package phase, so the container will be built when you run just mvn package.
[...]
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.11</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<imageName>${project.build.finalName}</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
The Docker image name will be defined at <imageName />
and use the artifact file name (${project.build.finalName}
).
imageName: Built image will be given this name.
More information about the build
goal: mvn com.spotify:docker-maven-plugin:help -Ddetail=true -Dgoal=build
or https://github.com/spotify/docker-maven-plugin
2) attach Docker image file on Maven deploy task
Attach - if docker-maven-plugin
doesn't do it for you - the Docker image file with the build-helper-maven-plugin
(http://www.mojohaus.org/build-helper-maven-plugin/usage.html).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.finalName}</file>
<type>...</type>
<classifier>docker</classifier>
</artifact>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
After these steps the artifact files itself and the Docker image artifact are deployed to Maven repository with identical version strings.