Search code examples
google-container-registry

Google Cloud Builder - Gradle


Following the post at https://cloudplatform.googleblog.com/2017/03/Google-Cloud-Container-Builder-a-fast-and-flexible-way-to-package-your-software.html

I understand that Gradle is supported for Google Container Builder. Yet I am not able to find any examples. I am specifically interested in setting the gradle version explicitly in the build.


Solution

  • We build Spinnaker components using Gradle within Google Cloud Container Builder.

    We have a Gradle wrapper checked into our GitHub repo, and we set the version within the distributionUrl of the gradle-wrapper.properties file:

    #Thu Nov 12 15:41:58 PST 2015
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
    

    Source: https://github.com/spinnaker/gate/blob/master/gradle/wrapper/gradle-wrapper.properties

    We then call ./gradlew normally. Here's a cloudbuild.yaml example from the same repo:

    steps:
    - name: 'java:8'
      env: ["GRADLE_USER_HOME=cache"]
      entrypoint: "bash"
      args: [ "-c", "./gradlew gate-web:installDist -x test"]
    - name: 'gcr.io/cloud-builders/docker'
      args: ["build", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:latest", "-f", "Dockerfile.slim", "."]
    images:
    - 'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'
    - 'gcr.io/$PROJECT_ID/$REPO_NAME:latest'
    

    Source: https://github.com/spinnaker/gate/blob/master/cloudbuild.yaml