Spring Boot on GCP
  • Introduction
  • Getting Started
    • Google Cloud Platform
    • Cloud Shell
    • gcloud CLI
    • Hello World!
      • Cloud Shell
      • App Engine
      • Cloud Run
      • Kubernetes Engine
      • Compute Engine
      • Cloud Functions
  • Application Development
    • Development Tools
    • Spring Cloud GCP
    • Cloud Services
      • Databases
        • Cloud SQL
        • Cloud Spanner
        • Cloud Firestore
          • Datastore Mode
          • Native Mode
      • Messaging
        • Cloud Pub/Sub
        • Kafka
      • Secret Management
      • Storage
      • Cache
        • Memorystore Redis
        • Memorystore Memcached (beta)
      • Other Services
    • Observability
      • Trace
      • Logging
      • Metrics
      • Profiling
      • Debugging
    • DevOps
      • Artifact Repository
  • Deployment
    • Runtime Environments
    • Container
      • Container Image
      • Secure Container Image
      • Container Awareness
      • Vulnerability Scanning
      • Attestation
    • Kubernetes
      • Kubernetes Cluster
      • Deployment
      • Resources
      • Service
      • Health Checks
      • Load Balancing
        • External Load Balancing
        • Internal Load Balancing
      • Scheduling
      • Workload Identity
      • Binary Authorization
    • Istio
      • Getting Started
      • Sidecar Proxy
  • Additional Resources
    • Code Labs
    • Presentations / Videos
    • Cheat Sheets
Powered by GitBook
On this page
  • Getting Started - Click to Deploy
  • Getting Started - Manual Deployment
  • Clone
  • Build
  • Containerize
  • Deploy
  • Connect
  • Additional Configurations
  • Learn More

Was this helpful?

  1. Getting Started
  2. Hello World!

Cloud Run

Deploy a container to serverless environment using a single command.

PreviousApp EngineNextKubernetes Engine

Last updated 4 years ago

Was this helpful?

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 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 .

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

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

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

Container Image
Optimizing Java Applications on Cloud Run
Cloud Run
Hello World Application
Container Registry
Deploy a Spring Boot app on Cloud Run