Skip to content

Latest commit

 

History

54 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloud Run service skeleton based on the Micronaut framework

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.

Packaging types of the Micronaut Maven Plugin

  • 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.

Default JAR packaging

Build to local Docker daemon

mvn clean package -Dpackaging=docker

It'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

Manual build and remote deployment of the docker image

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-graal

Command to push the Docker image of the application to the Artifact Registry:

mvn clean deploy -Dpackaging=docker

the 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)

GraalVM support

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

Performance boost seen directly on GCP

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/

Check Native Image Support for Google Cloud Libraries

Supported APIs

Cloud Build testing

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'

Additional useful links

About

Cloud Run service skeleton based on the Micronaut framework, with the option to build a GraalVM native image that can be deployed using Cloud Build.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages