Unnecessary

Projects

About

Martian on the Loose: A Quick Cloud Run Site

Apr 25, 2019

In my previous post I discussed Google Cloud Run as a docker-based PaaS. An opportunity arose to put together a quick website to help people play the Martian on the Loose scavenger hunt game which is currently running to promote The Expanse television series. The game is managed entirely on twitter by the actor Cas Anvar who plays one of the main characters in the series, and was instrumental in rallying fans to save the show when SyFy canceled it, ultimately leading Amazon to produce the show’s upcoming 4th season.

The downside of running a game on twitter is that the rules post becomes increasingly harder to find as the game continues. There are also a couple of regular posts of clues, required to solve the puzzle for each scavenger hunts, and it seems fairly common for there to be confusion over finding the clues for the most recent hunt. In order to fix this, I decided to put together a web site which holds both the instructions and the links to the clues for the current scavenger hunt. I also retyped the instructions to make it more accessible.

The site is a simple static website, which I could have hosted just about anywhere. Netlify, Zeit, or Surge are all great choices for serving a static site, but I decided to give Cloud Run a try. I’ve put up the full source code on github. The Dockerfile uses the nginx:mainline image and copies in the static files along with a configuration template and a shell script with adjusts the Nginx listening port at runtime. The script is necessary because Cloud Run passes in a PORT environment variable to indicate which port the server should listen on.

I use a cloudbuild.yaml to ensure the Google Cloud Build system builds the container, stores it in the container registry, and then deploys it to Cloud Run automatically. I can therefore just use the command

gcloud builds submit .

to build and deploy the website into production. In order for this to work, the following roles must be added to the Cloud Build service account (which is the project number followed by @cloudbuild.gserviceaccount.com):

This can be done from the IAM & admin page in the Google Cloud Console.

So far it looks like it’s working well, although there are many ways to deploy a static site, and Cloud Run is not really the optimal solution. Despite the fact that the resulting container is rather large at 114 MB, it still started up from a cold state in less than a second (749 ms from request sent to response received), and then has typically returned a web page in 3-15 ms. The build time for the container on Google Cloud Build was 40 seconds. Overall it seems like a relatively painless way to deploy a web site.

Tags: #cloud