How do I run ./gradlew bootBuildImage inside Google Cloud Build?

48 views Asked by At

I have a Spring Boot 3 application that I want to compile into a native binary and package inside a Docker container. I'm using Gradle as my build tool, and GraalVM as the JDK. The app is to be deployed in Google Cloud Run. My GCP Pipeline is a cloudbuild.yml file, which runs the build/deploy tasks when triggered. If possible, I'd like to use the Spring Boot Gradle plugin built-in support for Paketo Buildpacks, in order to minimize the amount of configuration I have to write. I.e. inside the cloudbuild.yml file, I'd like to run:

./gradlew bootBuildImage

The directives for using GraalVM to build a native image are specified inside the build.gradle file like this:

tasks.named("bootBuildImage") {
  environment["BP_NATIVE_IMAGE"] = true
  buildpacks = ['gcr.io/paketo-buildpacks/graalvm', 'gcr.io/paketo-buildpacks/java-native-image']
}

This works fine from my Mac command line, but when run in an environment that uses Docker images to run the build, such as Google Cloud Build, "Docker in Docker" is required. Google supports CNCF buildpacks with some specialized container images and the pack command, but it seems like it's more work to get that going. Is it a viable path to think that I should use the built-in support for Buildpacks in the Gradle plugin, or am I "fighting the system" and should just focus on using the Google Buildpacks containers with the pack command? Further down the road, this will probably migrate from Google Cloud Build to Harness, so that's a consideration as well.

0

There are 0 answers