epaulson10 / jib-google-cloud-build

Use Google Cloud Build with Jib.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Google Cloud Build with Jib

This example shows how to use Google Cloud Build and Jib to build your Java project into a container image.

Prerequisites

Make sure you enable the Cloud Build API and have the Cloud SDK installed. The gcloud binary should be on your PATH.

See the Cloud Build Quickstart for instructions.

Build a Maven project

To build your Maven project into a container image, use cloudbuild-jib-maven.yaml as the Cloud Build build configuration file:

gcloud builds submit --config cloudbuild-jib-maven.yaml <Maven project directory>

Make sure to change the _IMAGE_NAME substitution to the name of the image you wish to build.

Build a Gradle project

To build your Gradle project into a container image, first add Jib to your build.gradle:

plugins {
  id 'com.google.cloud.tools.jib' version '1.0.0'
}

Then, use cloudbuild-jib-gradle.yaml as the Cloud Build build configuration file:

gcloud builds submit --config cloudbuild-jib-gradle.yaml <Gradle project directory>

Make sure to change the _IMAGE_NAME substitution to the name of the image you wish to build.

Build a Gradle project without applying the Jib plugin

You can also build any Gradle project without having to add Jib to the build.gradle. First, copy auto-jib.gradle to your Gradle project directory. Then, uncomment the init-script arg in cloudbuild-jib-gradle.yaml and submit the build with:

gcloud builds submit --config cloudbuild-jib-gradle.yaml <Gradle project directory>

HelloWorld example

Try building the provided helloworld-sample Java project on Google Cloud Build:

Maven

gcloud builds submit --config cloudbuild-jib-maven.yaml helloworld-sample

Gradle

Uncomment the init-script arg in cloudbuild-jib-gradle.yaml and submit the build with:

gcloud builds submit --config cloudbuild-jib-gradle.yaml helloworld-sample

Speeding up your build

By default, Google Cloud Build does not cache anything across builds. However, you can use Google Cloud Storage to cache files across builds to potentially speed up subsequent builds. Note that this may not necessarily speed up your build since it involves sending cache data to and from Google Cloud Storage.

First, create a Google Cloud Storage bucket to use for storing the cache files.

Then, for Maven, use cloudbuild-jib-maven+cache.yaml as the Cloud Build configuration file. Change the _GCS_CACHE_BUCKET substitution to the bucket you just created and submit the build with:

gcloud builds submit --config cloudbuild-jib-maven+cache.yaml <Maven project directory>

For Gradle, use cloudbuild-jib-gradle+cache.yaml:

gcloud builds submit --config cloudbuild-jib-gradle+cache.yaml <Gradle project directory>

About

Use Google Cloud Build with Jib.


Languages

Language:Java 100.0%