Let’s talk Deployments with Google Home, CircleCI and Google Container Engine
Tl;dr — how we use Google Home to drive some of our DevOps work with CircleCI. See a video of a proof of concept at the end of this page.
Background: In past articles, I described our journey into Google Cloud Platform and how we leveraged our findings to come up with ideas to simplify our build/test/deploy processes and to share them with the community.
We dealt with deployments that involved backend services, pub/sub consumers, storage buckets, CloudSQL databases, numerous GCP projects, certificates, CDNs, multiple environments (QA, Staging (pre-production), Smoke test and Production). This gave rise to Blue/Green deployments and other innovative ways to not screw up our applications in production while maintaining a steady pace of deployments. CircleCI has been an excellent tool for our needs and their APIs are really good. We’ve used both CircleCI 1.0 and 2.0 for this.
Now that we’ve reached a point where we can deploy our applications to Production in under 5 minutes in a fully automated manner, I wanted to see what else we could do to simplify our day to day work.
So, I decided to start talking. Talking to Google Home, that is.
Google Home is a voice activated speaker, similar to Amazon’s Alexa. You converse with it using the Google Assistant, a virtual personal assistant. Classic examples include asking about the weather, asking it to play songs from your Spotify playlist etc. When you would like to do more with it beyond what it currently offers, you can extend its capabilities by creating an Action.
In my case, I have an action that allows me to do builds and deployments to Google Cloud Platform, so I would interact with the assistant by saying something like “Ok, Google. Talk to the Dev Ops Helper”.
It is powered by DialogFlow (formerly API.AI), a conversational platform that learns based on your input and allows you to translate your needs into actions.
The rest of this article deals with how we’re using Google Home and the DialogFlow tools (formerly API.AI) to use Natural Language Understanding to do some of the heavy lifting for us.
The diagram below from Google shows the flow from the user to the device to DialogFlow (API.AI) to invoking a Cloud Function written in node.js.
The diagram below shows how a user can communicate with the Dev Ops Helper (the Google Assistant in our case) via voice commands. These commands in turn execute Google Cloud Functions (node.js). The Cloud Function invokes RESTful APIs in CircleCI that trigger builds in various branches of our repository in GitHub.
Also shown is a second interaction where an application is hosted in GCP and has exposed an endpoint that invokes Kubernetes APIs (similar to what kubectl does) to manage the GKE cluster.
While there are many Home applications, here are some of the ways we can leverage Google Assistant with some of the needs at work:
- Instructing the Assistant to do builds and deployments to our various environments. Of course, we also use the CircleCI-Github webhooks, but this is more fun and the demo video later in this article does exactly that.
- Querying your GCP Kubernetes cluster (we use Google Container Engine extensively) using K8s APIs to get more information about and to modify our deployments, replicas, services etc. with voice commands. You can easily bring up/down your workers (ActiveJobs in the Rails world), scale your deployments, and do pretty much anything the Kube API will let you do.
- Viewing dashboards of system health, Production errors, you name it. If it can be delivered via a RESTful endpoint, it can most likely be obtained by asking Google Home.
At a very high level, you would need to know the following:
- You have created a project in the Actions Console
- You understand the following concepts:
Actions: Actions help you connect with users and get things done. For example, in the demo, I use an action that allows me to kick off builds and deployments to environments of my choice.
Entities: Entities are the values that the user provides to the assistant. For example: in the popular Google Home videos, you see a user specify the Pizza toppings they want. In my case, I use the “environment” entity to tell the Assistant what environment I would like to do the build/deploy to.
Intents: Intents are what the user tells the Assistant. To keep it simple, a user saying something like “I would like to do a QA build” could be an intent. You can train the Assistant to fine tune user requests and map them to the right intent. I have a few intents including an “env-intent” that handles my requests for deploying my application to different environments.
Fulfillment: Ultimately, your intent needs to do “something”. This could be responding to your request with a static response or something more dynamic that might come from a backend service. Fulfillments help with this by allowing you to point to a WebHook that corresponds to a HTTPS RESTful API that could be either an endpoint in your application or a Google Cloud Function that provides the required output. In my example, my Cloud Function in node.js invokes a RESTful CircleCI API that triggers builds in the master and develop branches in my Github Repository.
In the video below, I use Google Home to kick off builds in two different environments: QA and Staging. This is just a sample of some of the things we can do and the possibilities are many.
Conclusion: Overall, it was a very smooth process. From setting up the Actions project to creating a simple app that has the potential to do so much more. Integrating with the Google Home device itself was seamless.
Please note, there are some excellent resources from Google on how to get started with your custom Assistant and you can find them in the links below. I’ll be sharing my Github repo and more implementation details soon.
- Google Assistant: https://home-assistant.io/addons/google_assistant/
- Cloud Functions: https://cloud.google.com/functions/
- Actions on Google: https://developers.google.com/actions/
- Building your own serverless actions: https://www.slideshare.net/bretmc/google-home-and-google-assistant-workshop-build-your-own-serverless-action-on-google-app
- My prior articles on these topics: https://medium.com/@nithinmallya4