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.

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 docker packaging, setting -Djib.buildGoal=buildTar or -Djib.buildGoal=build only affects the earlier package phase and prevents Jib from creating a local Docker-daemon image. The deploy phase still uses mn:docker-push to publish an image from the local Docker daemon, so mvn deploy -Dpackaging=docker currently requires -Djib.buildGoal=dockerBuild or the default behavior with no jib.buildGoal override.

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