This combination of technologies enables developers to create scalable and efficient microservices or serverless applications that run on Cloud Run. With an option to build GraalVM native image that can be deployed using Cloud Build.
- jar (default): produces a runnable fat JAR.
- native-image: generates a GraalVM native image.
- docker: builds a Docker image with the application artifacts (compiled classes, resources, dependencies, etc).
- docker-native: builds a Docker image with a GraalVM native image inside.
In order to successfully build a docker image, the docker daemon must be running.
mvn clean package -Dpackaging=dockerIt's an equivalent of executing the jib::dockerBuild goal.
Once successfully finished, you can find the final image in Docker daemon tagged as europe-west1-docker.pkg.dev/gcp_project_id/docker-images/cloud-run-micronaut:short_sha
Before attempting to push the image, make sure you run GraalVM JDK. The easiest way to install GraalVM on Linux or Mac is to use SDKMan.io.
Java 21, check the latest version at GraalVM downloads
sdk install java 21.0.3-graalCommand to push the Docker image of the application to the Artifact Registry:
mvn clean deploy -Dpackaging=dockerthe final image will be pushed at:
europe-west1-docker.pkg.dev/gcp_project_id/docker-images
Before the push, make sure the authentication is correctly configured gcloud credential helper (recommended)
There is a dedicated Cloud Build configuration for GraalVM native image build. To use it, build-graalvm.yaml file must be utilized.
Note about the workaround: docker push is used instead of mvn deploy as the micronaut-maven-plugin to upload docker image to the Artifact Registry supports only auth.username/auth.password instead of preferred gcloud credential helper, see Choosing an authentication method
INFO io.micronaut.runtime.Micronaut - Startup completed in 183ms. Server Running: http://localhost:8080
GET 200 648 B 57 ms Safari 16.5.2 https://cloud-run-micronaut-nj5jdl6g3q-ew.a.run.app/ #first attempt
GET 200 648 B 2 ms Safari 16.5.2 https://cloud-run-micronaut-nj5jdl6g3q-ew.a.run.app/
compared to the Default JAR packaging
INFO io.micronaut.runtime.Micronaut - Startup completed in 3573ms. Server Running: http://localhost:8080
GET 200 648 B 1.387 s Safari 16.5.2 https://cloud-run-micronaut-nj5jdl6g3q-ew.a.run.app/ #first attempt
GET 200 648 B 5 ms Safari 16.5.2 https://cloud-run-micronaut-nj5jdl6g3q-ew.a.run.app/
gcloud builds submit --substitutions=REPO_NAME="cloud-run-micronaut",SHORT_SHA="1.0.0" --config build-graalvm.yaml .To speed up the build time, you can configure a more powerful machine type (attach it to the end of the Cloud Build YAML). The first 120 build-minutes per day are free (applicable only to the default one).
options:
machineType: 'E2_HIGHCPU_8'