# clone the repo
git clone https://github.com/GoogleCloudPlatform/serverless-production-readiness-java-gcp.git
cd services/reference
java -version
java -version
# should indicate this or later version
java version "21" 2023-09-19
Java(TM) SE Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)
./mvnw package spring-boot:run
From a terminal window, test the app
curl localhost:8085/metadata
./mvnw package
./mvnw native:compile -Pnative
java -Dspring.aot.enabled=true -jar target/reference-1.0.0.jar
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=reference
./mvnw spring-boot:build-image -DskipTests -Pnative -Dspring-boot.build-image.imageName=reference-native
docker run --rm -p 8080:8085 reference
docker run --rm -p 8080:8085 reference-native
Check existing deployed Cloud Run Services
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
echo $PROJECT_ID
gcloud run services list
If you have built the image locally, tag it first and push to a container registry
# tag the image
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
echo $PROJECT_ID
# tag and push JIT image
docker tag reference gcr.io/${PROJECT_ID}/reference
docker push gcr.io/${PROJECT_ID}/reference
# tag and push Native image
docker tag reference-native gcr.io/${PROJECT_ID}/reference-native
docker push gcr.io/${PROJECT_ID}/reference-native
Check existing deployed Cloud Run Services
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
echo $PROJECT_ID
gcloud run services list
Deploy the Reference JIT image
# note the URL of the deployed app
gcloud run deploy reference \
--image gcr.io/${PROJECT_ID}/reference \
--region us-central1 \
--memory 2Gi --allow-unauthenticated
Deploy the Reference Native Java image
# note the URL of the deployed app
gcloud run deploy reference-native \
--image gcr.io/${PROJECT_ID}/reference-native \
--region us-central1 \
--memory 2Gi --allow-unauthenticated
Start the containerized app locally:
curl --location 'http://localhost:8087/metadata'
Test the application in Cloud Run
# find the Reference URL is you have not noted it
gcloud run services list | grep reference
reference latest 072323ccd2f7 43 years ago 366MB
# validate that app passes start-up check
curl <URL>:/start
# retrieve the metadata from the URL
curl <URL>:/metadata
If you have deployed the service with security enabled, (no --allow-unauthenticated flag) you can test it with a Bearer token. You can use also an alternative HTTP test client
TOKEN=$(gcloud auth print-identity-token)
# Get the URL of the deployed service
# Test JIT image
http -A bearer -a $TOKEN https://<BASE_URL>/metadata
# Test JIT image - Docker image built with Dockerfile
http -A bearer -a $TOKEN <BASE_URL>/metadata
# Test Native Java image
http -A bearer -a $TOKEN <BASE_URL>/metadata