Cloud Run
Deploy a container to serverless environment using a single command.
Cloud Run is a fully managed container runtime environment, where you can deploy any HTTP serving container, and Cloud Run will automatically scale out the number of instances as needed, and scale down to zero when no one is using it.
cd $HOME
git clone https://github.com/saturnism/jvm-helloworld-by-example
cd jvm-helloworld-by-example/helloworld-springboot-tomcat
./mvnw package
gcloud services enable containerregistry.googleapis.com
Use Jib to containerize the application:
PROJECT_ID=$(gcloud config get-value project)
./mvnw compile com.google.cloud.tools:jib-maven-plugin:2.4.0:build \
-Dimage=gcr.io/${PROJECT_ID}/helloworld
# To use Cloud Run
gcloud services enable run.googleapis.com
PROJECT_ID=$(gcloud config get-value project)
gcloud run deploy helloworld \
--region=us-central1 \
--platform=managed \
--allow-unauthenticated \
--image=gcr.io/${PROJECT_ID}/helloworld
Once deployed, Cloud Run will display the HTTPs URL. You can also find the URL with the command line:
gcloud run services describe helloworld \
--region=us-central1 \
--platform=managed
You can
curl
the URL:URL=$(gcloud run services describe helloworld \
--region=us-central1 \
--platform=managed \
--format='value(status.address.url)')
curl ${URL}
By default, Cloud Run will deploy with the smallest 1CPU 256MB instance. You can specify a larger instance, and configure environment variables with the
gcloud
CLI:PROJECT_ID=$(gcloud config get-value project)
gcloud run deploy helloworld --platform=managed --allow-unauthenticated \
--cpu=2 --memory=512M --set-env-vars="SPRING_PROFILES_ACTIVE=prod" \
--image=gcr.io/${PROJECT_ID}/helloworld
Last modified 3yr ago