Skip to content

Instantly share code, notes, and snippets.

@ambud
Created April 21, 2016 17:47
Show Gist options
  • Save ambud/5fa4c63944edaac26d8960f6e8aabb49 to your computer and use it in GitHub Desktop.
Save ambud/5fa4c63944edaac26d8960f6e8aabb49 to your computer and use it in GitHub Desktop.
This partial POM configuration for plugin will allow you to build a docker image for your Java application. The build configuration is under a Maven profile and parameterized to only active if the DOCKER_REGISTRY environment variable is set. You are also required to have your docker file under src/main/docker with any other configurations that y…
<profiles>
<profile>
<id>docker</id>
<activation>
<property>
<name>env.DOCKER_REGISTRY</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.5</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<noCache>true</noCache>
<imageName>${project.name}:${project.version}</imageName>
</configuration>
</execution>
<execution>
<id>tag-image</id>
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<image>${project.name}:${project.version}</image>
<newName>${env.DOCKER_REGISTRY}/${project.name}:${project.version}</newName>
</configuration>
</execution>
<execution>
<id>push-image</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<imageName>${env.DOCKER_REGISTRY}/${project.name}:${project.version}</imageName>
</configuration>
</execution>
</executions>
<configuration>
<serverId>paas</serverId>
<registryUrl>https://${env.DOCKER_REGISTRY}/</registryUrl>
<imageName>${project.name}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
</imageTags>
<dockerDirectory>${project.name}/src/main/docker</dockerDirectory>
<forceTags>true</forceTags>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment