Summary
This post is a continuation of the previous quick start on containerizing a Node.js app. In this post, I'll use the same simple app + Dockerfile and deploy the app to Google's Cloud Run platform.Cloud Run is an alternate method for server-less app deployments. Google Cloud Functions is other method. Whereas Cloud Functions has very specific language requirements, Cloud Run has none. Whatever you build in a container is fair game. The only requirement is the app needs to respond to HTTP requests as a trigger. Cloud Run provides similar auto-scaling capabilities as Cloud Functions making it an excellent choice for a self-managing app deployment.
Step 1: Create a Google Cloud Project
Step 2: Enable Cloud Build and Cloud Run APIs
Step 3: Build the Container
$ gcloud config set project cloudrun-quickstart-261521 Updated property [core/project]. $ gcloud builds submit --tag gcr.io/cloudrun-quickstart-261521/cloudrun-quickstartCreating temporary tarball archive of 331 file(s) totalling 1.6 MiB before compression. Uploading tarball of [.] to [gs://cloudrun-quickstart-261521_cloudbuild/source/1575934972.69-7637137b7675474ab861a2f4185529c6.tgz] Created [https://cloudbuild.googleapis.com/v1/projects/cloudrun-quickstart-261521/builds/7591715a-3e15-4323-b570-0c2dc191fb3a]. Logs are available at [https://console.cloud.google.com/gcr/builds/7591715a-3e15-4323-b570-0c2dc191fb3a?project=945345104488]. ... DONE -------------------------------------------------------------------------------------------------------------------------------------------- ID CREATE_TIME DURATION SOURCE IMAGES STATUS 7591715a-3e15-4323-b570-0c2dc191fb3a 2019-12-09T23:42:55+00:00 57S gs://cloudrun-quickstart-261521_cloudbuild/source/1575934972.69-7637137b7675474ab861a2f4185529c6.tgz gcr.io/cloudrun-quickstart-261521/cloudrun-quickstart (+1 more) SUCCESS
Step 4: Deploy to Cloud Run
Screen shots below of the Cloud Run console. Note in the second screen shot the concurrency controls available. You can specify the number of requests per container and the max container auto-scale growth.Step 5: Execute
$ curl -i https://cloudrun-quickstart-6saiqefrtq-uc.a.run.app HTTP/2 200 x-powered-by: Express content-type: text/html; charset=utf-8 etag: W/"b-Kq5sNclPz7QV2+lfQIuc6R7oRu0" x-cloud-trace-context: 4f70f43d41086a3d8ea2320a166a5f89;o=1 date: Mon, 09 Dec 2019 23:58:10 GMT server: Google Frontend content-length: 11 alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000 hello world
Step 6: Clean up
Copyright ©1993-2024 Joey E Whelan, All rights reserved.