# clone the repo
git clone https://github.com/GoogleCloudPlatform/serverless-production-readiness-java-gcp.git
cd services/quotes
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:8080
# Output
Hello from your local environment!
./mvnw clean package
./mvnw clean package -Pnative -DskipTests
./mvnw package -DskipTests
./mvnw native:compile -Pnative -DskipTests
java -Dspring.aot.enabled -jar target/bff-1.0.0.jar
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=bff
./mvnw spring-boot:build-image -DskipTests -Pnative -Dspring-boot.build-image.imageName=bff-native
docker run --rm -p 8080:8080 bff
docker run --rm -p 8080:8080 bff-native
gcloud builds submit --machine-type E2-HIGHCPU-32
gcloud builds submit --config cloudbuild-docker.yaml --machine-type E2-HIGHCPU-32
gcloud builds submit --config cloudbuild-native.yaml --machine-type E2-HIGHCPU-32
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 bff gcr.io/${PROJECT_ID}/bff
docker push gcr.io/${PROJECT_ID}/bff
# tag and push Native image
docker tag bff-native gcr.io/${PROJECT_ID}/bff-native
docker push gcr.io/${PROJECT_ID}/bff-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 BFF JIT image
gcloud run deploy bff \
--image gcr.io/${PROJECT_ID}/bff \
--region us-central1 \
--memory 2Gi --allow-unauthenticated
Deploy the BFF Native Java image
gcloud run deploy bff-native \
--image gcr.io/${PROJECT_ID}/bff-native \
--region us-central1 \
--memory 2Gi --allow-unauthenticated
Test the application locally
# read the existing Quotes
curl --location 'http://localhost:8080/quotes'
# add an additional Quote
curl --location 'http://localhost:8080/quotes' --header 'Content-Type: application/json' --data '{
"author" : "Isabel Allende",
"quote" : "The longer I live, the more uninformed I feel. Only the young have an explanation for everything.",
"book" : "City of the Beasts"
}'
# Re-read the list of Quotes
curl --location 'http://localhost:8080/quotes'
Test the application in Cloud Run
TOKEN=$(gcloud auth print-identity-token)
# Copy the URL of the deployed app
# Test JIT image
http -A bearer -a $TOKEN https://<BASE_URL>/quotes