Google Cloud Run

Overview

Containers, Containers, Containers. It seems like Docker is all the rage… well, there is a reason. Docker containers make life easier for all developers as it gets rid of the “it worked on my computer” problem. I won’t be going to deep into Docker here, but please see our Intro to Docker post.

In a Nutshell, Docker allows us to spin up environments with the click of a button, and as many as we want, ensuring they are all the same. For local development, this is amazing as it installs all the dependencies for you. Imagine you want to start up an app where there was: a database, API server, proxy server, and an application server. Even if you had just acquired a new computer and have no programs installed, you would install Docker and run a single command to get all the pieces up and running. Even better, if you did have all the correct languages and libraries installed, but they were outdated, there would be no need to upgrade them as there would be no conflicts. In this post, I will be talking about Google Cloud Run and how it manages your environment for you, given a Docker image. GCR will then spin up any number of Conainters needed from it and scale on the fly!

Google Cloud Run Console

Our Configuration

Assuming you are familiar with the basics of Docker, I will continue to discuss Google Cloud Run, which I will be referring to as GCR. We can deploy any Docker image meant to take incoming traffic, such as APIs or Web App, and scale it using GCR. The configuration is quite easy being that Google provides us with an interface to specify how to scale your containers. Each GCR instance references a Docker image; it then creates a cluster of containers scaling dynamically as needed. You can configure things such as:

  • The maximum amount of containers you want the GCR instance to scale to
  • The amount of memory to allocate to a single container
  • The max requests a single container can accept concurrently
  • Environment variables. Note that using NODE_ENV can get overwritten if you are using a framework like Nextjs. You can use ENV_CONFIG or some other variable.
Google Cloud Run Domain Mapping

Alongside this, GCR fully manages your container cluster. We can easily configure domains/sub-domains to point to a particular cluster, fully supporting https as well. Whether you purchased your domain from Google or any other vendor, such as GoDaddy, you can easily verify and map it from within the same interface. If you did not purchase your domain from Google, you need to update your DNS configuration to validate that you are the owner. To verify that you are the owner, you need to add a new TXT record with a value GCR provides you.

Our actual configuration is automated from Google Cloud Build, see our post for more info. This way, each time we push to our code repo, we are provided with a fully managed environment to test only the changes on that feature branch. When the changes are ready, we can merge into staging/master, and it will get tested and deploy all behind the scenes.

Some Issues

Currently, GCR does not allow you to have at minimum 1 container running; it is set to 0. Because of this, if your environment does not get many requests, there will be a warmup time. This warmup time would cause the initial request to take a second or two. This is not an issue if you have consistent traffic to your site, which would not allow the environment to scale down to 0.

We are still experimenting on the best way to debug the cloud container, so if you have any suggestions, please do let us know in the comments below. If you have any trouble setting up your GCR instances or want us to go into more detail, please let us know below.

Conclusion

We will recommend Google Cloud Run if you are looking to have a fully managed environment. It will also be a great fit if you are looking for the ability to spin up multiple environments on the fly that are scalable and self-managed. We would not recommend this if your environment is not dockerized or if your dockerized environment is not being used as an exposed service or web application. You can find more information on Google’s page here.

Thank you for reading and please feel free to share using the links below!

6 Replies to “Google Cloud Run”

Leave a Reply

Your email address will not be published. Required fields are marked *