Coder Social home page Coder Social logo

jib-google-cloud-build's Introduction

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>

jib-google-cloud-build's People

Contributors

coollog avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.