Skip to content

Instantly share code, notes, and snippets.

@daniel-shuy
Last active January 3, 2020 15:30
Show Gist options
  • Save daniel-shuy/30bbcb103c7ff578422378ff0fd8a8ad to your computer and use it in GitHub Desktop.
Save daniel-shuy/30bbcb103c7ff578422378ff0fd8a8ad to your computer and use it in GitHub Desktop.
jib-maven-plugin configuration template

jib-maven-plugin's default example runs the build goal during the package phase. The build goal will push the docker image to the remote registry, which may be too frequent to run in the package phase for some projects.

This template instead configures the jib-maven-plugin to run the following goals in the following phases:

Phase Goal Goal Description
package buildTar Build docker image as tar file
install dockerBuild Build docker image and install in Docker daemon
deploy build Build docker image and push to remote Docker registry

which is more in-line with the definition of each phase.

This template also provides sensible defaults like using the project groupId and artifactId to construct the docker image name, and using the project version as the Docker image tag.

The reason why the to.image configuration cannot be shared between the install and push executions, is because the dockerBuild goal will also push to the remote Docker registry if the to.image configuration is prefixed with the registry hostname.

Written with jib-maven-plugin version 1.8.0.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ... -->
<properties>
<docker.image>${project.groupId}/${project.artifactId}</docker.image>
<docker.registry>docker.io</docker.registry>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<id>build</id>
<phase>package</phase>
<goals>
<goal>buildTar</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>dockerBuild</goal>
</goals>
<configuration>
<to>
<image>${docker.image}</image>
</to>
</configuration>
</execution>
<execution>
<id>push</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<to>
<image>${docker.registry}/${docker.image}</image>
</to>
</configuration>
</execution>
</executions>
<configuration>
<to>
<tags>
<tag>${project.version}</tag>
</tags>
</to>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment