Deploying a Quarkus app to Google Cloud Run
If you haven’t heard of Google Cloud Run, which was just announced at Cloud Next ’19, check out cloud.google.com/run for more details. Essentially this is a way to deploy and scale your stateless containers on a serverless infrastructure — no infra or cluster to setup/manage, auto-scaling (including to zero), and billing as you go based on actual user requests, not on instances running.
Quarkus is also a recent project by RedHat introduced here and meant to support cloud native Java apps with an option to compile them down to native code. The following instructions walk you through deploying a Quarkus native app to Cloud Run.
Following the Quarkus instructions (getting started, and native images) I built and packaged the sample app using these commands :
$ mvn package -Pnative -Dnative-image.docker-build=true
$ docker build -f src/main/docker/Dockerfile -t quarkus/getting-started .
The Java application is compiled into a native Linux 64-bit binary optimized for startup time and memory consumption using GraalVM and is containerized.
The resulting docker image is then pushed to Cloud Registry :
$ docker tag 0b03762bad42 eu.gcr.io/quarkus/quarkus-quickstart/quickstart
$ docker push eu.gcr.io/quarkus/quarkus-quickstart/quickstart
At this point you are ready to deploy your container to Cloud Run :
$ gcloud beta run deploy \
That’s really it! Nothing else to configure !
Your app is now exposed as a service on a
run.app domain and it will auto-scale from 0 to multiple container instances to adapt to the incoming load.
The logs show a nice startup time indeed :
Quarkus 0.11.0 started in 0.333s
If you enjoy Quarkus, Google Cloud Run is a great option to deploy your containers. If you’d rather deploy to an existing Kubernetes cluster which you manage then try Cloud Run on GKE and deploy that same container!
Next steps would be to hook up the application to Cloud SQL, Cloud Datastore or other GCP databases.
Here are a few additional resources:
- Services, revisions, and container instances
- How any given instance can support multiple requests
- Container runtime contract (what stateless container actually means)
If you’d like to take Cloud Run for a spin, check out these codelabs :
- https://codelabs.developers.google.com/codelabs/cloud-run-hello (Managed version)
- https://codelabs.developers.google.com/codelabs/cloud-run-gke (GKE version)