Fork me on GitHub

Deploying an application

Similarly to the packaging support, with this plugin you can use mvn deploy as the only command required to deploy an application that, depending on the <packaging>:

  • jar (default): will deploy the artifact to a remote repository using org.apache.maven.plugins:maven-deploy-plugin:deploy.

  • docker or docker-native: will push the Docker image to the configured Docker registry.

  • native-image with micronaut.native-image.jib.enabled=true: writes a daemonless tarball during package by default, or publishes during package when -Djib.buildGoal=build is set.

  • k8s or openshift: will delegate image publication to Eclipse JKube’s push goal for the selected platform.

You can use Jib to configure which registry should the image be pushed to. Refer to the Jib Maven Plugin documentation to see what are the configuration options that can be used.

For example, to push an image to Docker Hub:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <configuration>
    <to>
      <image>my-company/my-app:${project.version}</image>
    </to>
  </configuration>
</plugin>

Then, you can execute mvn deploy -Dpackaging=docker or mvn deploy -Dpackaging=docker-native.

For JVM docker packaging, the jib.buildGoal value determines how the image is published:

jib.buildGoal Deploy behavior

Omitted or dockerBuild

Jib builds the image into the local Docker daemon during package, and mn:docker-push pushes that local image during deploy.

build

Jib publishes the image directly to the registry during package. Because Maven runs package before deploy, mn:docker-push logs that the Jib registry publish path was used and skips the Docker-daemon push.

buildTar

Unsupported for deploy. It creates target/jib-image.tar and does not publish to a registry.

Use build for daemonless deploy from CI environments that do not have a local Docker daemon:

mvn deploy -Dpackaging=docker \
  -Djib.buildGoal=build \
  -Djib.to.image=registry.example.com/team/my-app:1.0.0

The command must include jib.to.image or equivalent Jib <to><image>…​</image></to> configuration. Configure registry credentials with Jib-supported mechanisms such as Maven settings, jib.to.credHelper, environment-backed jib.to.auth.username and jib.to.auth.password properties, or standard registry credential helpers. Do not commit plain-text registry secrets to the POM.

For daemonless native executable images, use native-image, enable the native image Jib workflow, and set Jib’s registry build goal:

mvn package -Dpackaging=native-image \
  -Dmicronaut.native-image.jib.enabled=true \
  -Djib.buildGoal=build \
  -Djib.to.image=my-company/my-app:latest

This path builds the local native executable, copies only that executable into a container image, and pushes with Jib registry credentials. mvn deploy -Dpackaging=native-image also runs the package phase, so the same Jib registry publish path is used when jib.buildGoal=build is configured.

For JKube-backed deployments, declare the matching JKube plugin in your POM and run either:

$ mvn deploy -Dpackaging=k8s
$ mvn deploy -Dpackaging=openshift

k8s maps deploy to org.eclipse.jkube:kubernetes-maven-plugin:push, while openshift maps deploy to org.eclipse.jkube:openshift-maven-plugin:push.

For native image Jib image creation, omitting jib.buildGoal produces target/jib-image.tar by default, and -Djib.buildGoal=build publishes directly to jib.to.image during package.

You can also omit the plugin declaration in your POM, and execute directly:

$ mvn deploy -Dpackaging=docker-native -Djib.to.image=my-company/my-app:latest

Note that in Maven, the deploy phase runs after the package phase (among others), so invoking deploy will also build the Docker image. Check the packaging support to see what options can be used.

This plugin will use your Docker configuration at ~/.docker/config.json. Essentially, if you can run docker push from your command line, you will also be able to mvn deploy your application.

In addition to that, you can supply credentials via username and password:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <configuration>
    <to>
      <image>gcr.io/my-gcp-project/my-app</image>
      <auth>
        <username>${env.REGISTRY_USERNAME}</username>
        <password>${env.REGISTRY_PASSWORD}</password>
      </auth>
    </to>
  </configuration>
</plugin>

Or with the command line:

$ mvn deploy -Dpackaging=docker-native -Djib.to.image=gcr.io/my-gcp-project/my-app -Djib.to.auth.username=$REGISTRY_USERNAME -Djib.to.auth.password=$REGISTRY_PASSWORD