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

cd $HOME
git clone https://github.com/saturnism/jvm-helloworld-by-example
cd jvm-helloworld-by-example/helloworld-springboot-tomcat

Build

./mvnw package

Containerize

Enable API

Enable the Container Registry API so that you can push container images to Container Registry.

gcloud services enable containerregistry.googleapis.com

Jib

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

Learn different ways to containerize a Java application in the Container Image section.

Deploy

Enable API

# To use Cloud Run
gcloud services enable run.googleapis.com

Deploy Container

PROJECT_ID=$(gcloud config get-value project)

gcloud run deploy helloworld \
  --region=us-central1 \
  --platform=managed \
  --allow-unauthenticated \
  --image=gcr.io/${PROJECT_ID}/helloworld

Connect

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}

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:

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

Learn More

Last updated