Cloud Run, the Google Cloud Vision API, and 'Twilio-vision'
About three years ago, I published a blog post describing how to build a Kubernetes-based app that let you text images to a Twilio phone number (once set up), and get a text back with information about how the Cloud Vision API labeled the image. (The example code referenced in that earlier post is obsolete, due to API changes.)
This little app is a perfect use case for the newly-announced Cloud Run service.
Cloud Run is a managed compute platform that enables you to run stateless containers that are invocable via HTTP requests. Cloud Run is serverless: it abstracts away all infrastructure management. It is built from Knative, letting you choose to run your containers either fully managed with Cloud Run, or in your Google Kubernetes Engine cluster with Cloud Run on GKE.
A Cloud Run app will scale to zero instances when it’s not being used, and will scale up transparently when needed, with no intervention required; it’s fully managed. You pay only when your app is processing a request, in 100ms increments. It supports any app that can be packaged into a Docker image for Linux.
We can use the same Docker image as used for the Kubernetes app Deployment, and deploy it to Cloud Run instead. The new code is here (updated from the previous version to reflect API changes): https://github.com/amygdala/code-snippets/tree/master/cloud_run/twilio_vision.
yaml file for the original Kubernetes app Deployment set some environment variables that were used by the app code. For the Cloud Run version, we can just set those env variables on the command line when we deploy, like this:
gcloud beta run deploy --image gcr.io/<your_project>/twilio-vision:v1 --update-env-vars MESSAGE_BLURB="Courtesy of the Google Cloud Vision API..."
Give it a try by texting an image to: (785) 336-5113. (The texted images are not retained by Google Cloud Platform, but are stored temporarily with Twilio).
See the example’s README for more information on setting up such an app for yourself.
Thanks to Julia Ferraioli for the original version of this app.