A demo project built with Jakarta EE and MicroProfile – a service that returns random combination of an adjective and a noun as a JSON list.
The code can be deployed to several runtimes. This is done to illustrate the switching runtimes with minor changes to the code and to observe the performance.
Runtime | Build | Run | Address |
---|---|---|---|
Open Liberty | mvn -f pom-liberty.xml clean package |
java -jar target/randomstrings.jar |
http://localhost:8080/api/rnd |
Quarkus | mvn -f pom-quarkus.xml clean package |
java -jar target/quarkus-app/quarkus-run.jar |
http://localhost:8080/api/rnd |
Helidon | mvn -f pom-helidon.xml clean package |
java -jar target/randomstrings.jar |
http://localhost:8080/api/rnd |
Note: You can run your Quarkus application in dev mode
that enables live code reloading:
./mvnw -f pom-quarkus.xml quarkus:dev
All containers are multistage build containers and can be found in a folder structure for each runtime and are marked with jvm
and native
, depending on flavour you want to build. The same containers are used to create images for the Cloud deployments as well.
https://cloud.google.com/artifact-registry/docs/repositories/create-repos#docker
Build images using Cloud Build, add to the registry and deploy to Cloud Run
Runtime | Build & Deploy to Cloud Run |
---|---|
Quarkus – JVM | gcloud builds submit --substitutions=_APP_RUNTIME="quarkus",_APP_RUNTIME_FLAVOUR="jvm" |
Quarkus – Native | gcloud builds submit --substitutions=_APP_RUNTIME="quarkus",_APP_RUNTIME_FLAVOUR="native" |
OpenLiberty – JVM | gcloud builds submit --substitutions=_APP_RUNTIME="liberty",_APP_RUNTIME_FLAVOUR="jvm" |
Helidon – JVM | gcloud builds submit --substitutions=_APP_RUNTIME="helidon",_APP_RUNTIME_FLAVOUR="jvm" |
Helidon – Native | gcloud builds submit --substitutions=_APP_RUNTIME="helidon",_APP_RUNTIME_FLAVOUR="native" |
Cloud Run uses port 8080 by default. All runtimes are configured to expose that port. These configurations are done in:
Runtime | Port Config |
---|---|
Quarkus | defaults to 8080 |
OpenLiberty | setup in server.xml |
Helidon | setup in microprofile-config.properties |
Lets you provide configuration parameters for your application (specification).
The example class RandomStringsSupplier
shows you how to configure and define default values for variables.
Available at: <URL>/health
.
The health status can be used to determine if the 'computing node' needs to be discarded/restarted or not (specification). These probes (liveness, readiness, startup) are available at separate URLs and can easily be integrated with the Cloud's health checks as they return HTTP codes (and human-readable) responses.
The class ServiceHealthCheck contains an example of a custom check which can be integrated to health status checks of the instance.
The index page contains a link to the status data.
Available at: <URL>/metrics
.
The Metrics exports Telemetric data in a uniform way of system and custom resources (specification).
The class RandomStringsController
contains an example how you can measure the execution time of a request. The index page also contains a link to the metric page.
Available at: <URL>/openapi
.
Exposes the information about your endpoints in the format of the OpenAPI v3 specification (docs).
The index page contains a link to the OpenAPI information of the available endpoints for this project.
This is an example of how application using CRaC can be set-up. See shell scripts in crac folder for more details.
# 1. build the image
cd src/scripts/crac; ./checkpoint.sh
# 2. tag the image
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
echo $PROJECT_ID
docker tag randomstrings-crac:checkpoint europe-north1-docker.pkg.dev/${PROJECT_ID}/rndstrs/randomstrings-crac
# 3. push the image to GCR
docker push europe-north1-docker.pkg.dev/${PROJECT_ID}/rndstrs/randomstrings-crac
# 4. deploy the image to Cloud Run
gcloud run deploy randomstrings-quarkus-crac \
--image=europe-north1-docker.pkg.dev/${PROJECT_ID}/rndstrs/randomstrings-crac \
--execution-environment=gen2 \
--allow-unauthenticated \
--region=europe-north1 \
--args="--cap-add CHECKPOINT_RESTORE --cap-add SETPCAP -XX:+UnlockExperimentalVMOptions -XX:+IgnoreCPUFeatures"