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.

Getting Started - Click to Deploy

You can deploy a Hello World Application simply by click on the Run on Google Cloud button below!

Getting Started - Manual Deployment

Clone

1
cd $HOME
2
git clone https://github.com/saturnism/jvm-helloworld-by-example
3
cd jvm-helloworld-by-example/helloworld-springboot-tomcat
Copied!

Build

1
./mvnw package
Copied!

Containerize

Enable API

Enable the Container Registry API so that you can push container images to Container Registry.
1
gcloud services enable containerregistry.googleapis.com
Copied!

Jib

Use Jib to containerize the application:
1
PROJECT_ID=$(gcloud config get-value project)
2
3
./mvnw compile com.google.cloud.tools:jib-maven-plugin:2.4.0:build \
4
-Dimage=gcr.io/${PROJECT_ID}/helloworld
Copied!
Learn different ways to containerize a Java application in the Container Image section.

Deploy

Enable API

1
# To use Cloud Run
2
gcloud services enable run.googleapis.com
Copied!

Deploy Container

1
PROJECT_ID=$(gcloud config get-value project)
2
3
gcloud run deploy helloworld \
4
--region=us-central1 \
5
--platform=managed \
6
--allow-unauthenticated \
7
--image=gcr.io/${PROJECT_ID}/helloworld
Copied!

Connect

Once deployed, Cloud Run will display the HTTPs URL. You can also find the URL with the command line:
1
gcloud run services describe helloworld \
2
--region=us-central1 \
3
--platform=managed
Copied!
You can curl the URL:
1
URL=$(gcloud run services describe helloworld \
2
--region=us-central1 \
3
--platform=managed \
4
--format='value(status.address.url)')
5
6
curl ${URL}
Copied!

Additional Configurations

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:
1
PROJECT_ID=$(gcloud config get-value project)
2
3
gcloud run deploy helloworld --platform=managed --allow-unauthenticated \
4
--cpu=2 --memory=512M --set-env-vars="SPRING_PROFILES_ACTIVE=prod" \
5
--image=gcr.io/${PROJECT_ID}/helloworld
Copied!

Learn More

Last modified 1yr ago