Source to Cloud Run

Biju Kunjummen
2 min readJul 21, 2023

Consider a scenario where you have to go from source code to having a running application, in the cloud, quickly.

One of the easiest ways to do this is to use a neat feature in the Google Cloud command line tool, which looks like this:

gcloud run deploy myshinyservice --source .

This encapsulates a bunch of things that happen under the covers:

  1. The source code is zipped up and uploaded to Google Cloud Storage(GCS)
  2. A Cloud Build build is triggered, which uses the zipped source and creates a container image using Cloud Native Buildpack
  3. Finally, the image is deployed and run on Cloud Run

If the steps work cleanly, at the end the endpoint of the running application is printed to the console!

This works great in getting an application running quickly. Let’s consider a few examples.

Demo

Consider first a simple Java-based Spring Boot application, generated using the Spring Boot starters:

curl -G https://start.spring.io/starter.zip -d dependencies=webflux,actuator \
-d bootVersion=3.1.2 -o my-project.zip

unzip my-project.zip

and you should have a working Spring Boot-based Java application. Now to get this application running execute:

gcloud run deploy myshinyservice --source .

Assuming that gcloud command line utility is configured correctly, the URL of the deployed service will be the output:

Building using Buildpacks and deploying container to Cloud Run service [my-project] in project [myproject] region [us-west1]
✓ Building and deploying new service... Done.
✓ Uploading sources...
✓ Building Container... Logs are available at [https://console.cloud.google.com/cloud-build/builds/dfadsf?project=adfafd].
✓ Creating Revision...
✓ Routing traffic...
✓ Setting IAM Policy...
Done.
Service [my-project] revision [my-project-00001-gow] has been deployed and is serving 100 percent of traffic.
Service URL: https://my-project-test-uw.a.run.app

There is one wrinkle here though, by default Cloud Native buildpacks assume Java 11 as the runtime, whereas the entire world has likely moved onto Java 17, to fix this just provide an environment variable in a project.toml file this way:

[[build.env]]
name = "GOOGLE_RUNTIME_VERSION"
value = "17"

Conclusion

I use this approach to quickly get small proof of concept applications running in Cloud Run and move onto a more structured CI/CD-based approach for real development work. “gcloud run — source” is neat in how it hides a bunch of complexity involved in setting up the pipeline, publishing images and using images for a Cloud runtime.

--

--

Biju Kunjummen

Sharing knowledge about Java, Cloud and general software engineering practices