Monday 11 September 2017

Playing with Google Cloud Services

Late last night I wanted to build a simple but humorous website (the details of which shall remain veiled from you). The website simply needed to serve up a random image, i, (from a collection of N) and then serve a title that I had associated with said i. That is, show an image and a caption.

Being an engineer, I knew I simply must over-engineer this simple challenge. I also wanted to use it as an opportunity to learn a little about the Google Cloud Services products (Google's answer to Amazon Web Services).

I spent some time perusing the vast litany of products that Google Cloud Services provides; from storage, to compute, to SQL to container hosting to VM hosting; it's all there. I didn't see anything missing (yet).

My initial design looked something like the following (artwork courtesy of yours truly).
My Website 1.0
The general idea was that I would have some sort of Google Cloud Function that would house the business logic of my project. It would simply get a random number in a given range and then request an image with that number from Google Cloud Storage and return its url. I would house the captions in a database (in this initial design I chose Spanner since that seemed hip and cool and in the news but then I realised it was expensive so opted for postgres later). This initial design was missing where the html would actually be served from as we will find out later.

Google Cloud Storage was the most impressive thing so far. It was really easy to setup and get used to; it was easy to understand and striaghtforward to use.

I realised fairly quickly that Google Cloud Function was not appropriate for what I was doing. What I should be using was Google App Engine (known as GAE). This thing was built literally for hosting websites (mine was not static). I followed the initial hello world tutorial and realised it only needed a tiny bit of tweaking for me to use it for my website.
After about 2 hours I was serving some simple HTML from GAE (using a Go application) that would simply generate a random number in a given range and then serve the image with that name from my GCS. Simple.

Now I wanted to serve the captions for these images. Initially you could see that I wanted to put them in a database (Postgres because I don't like MySql). Postgres is still in beta on Google Cloud Services. Getting Postgres in a usable state was tremendously hard. I was able to create the tables through an interactive prompt launched from the GAE website but it was very difficult to get my GAE connected to the same instance - I spent 1 hour jerking around with certificates and keys to only get hangs. I could at some point connect interactively with psql from my GAE prompt but not reliably - not sure what was going on. There are tutorials on GAE for connecting to postgres from Java and Python (which seems to need a proxy!?) but nothing for Go (yet). So I was kinda stuck up a creek without a paddle.

So I just mashed the captions into the code and put out version 0.1.

The end design looking something like this:

The diagram is actually pretty inaccurate since the go code doesn't actually talk to GCS but it just generates the URL and the browser downloads it.

The whole process was pretty cool all in all. I was able to get up and running without spending a penny (1 year of $300 for free when you sign up woo) and jump around the different products easily. The integration between the Postgres/GAE stuff was terrible. It was really hard to work out how to get the auth setup. I also didn't take enough time to setup the interactive tools locally - my internet was spotty - and using the web based tmux console was very painful and slow. But it was fun to bash something out from my browser that hit GCS and used Go without having to download a megalith of tools that I would never look at again.

ICV?

Saturday 25 March 2017

Chat Apps

This xkcd really struck a chord with me. Current chat apps on my phone are:

  • Slack
  • Allo
  • Hangout
  • Whatsapp
  • Facebook Messenger
  • SMS
Spoilt for choice...

Sunday 15 January 2017

Magic List of Things to Consider if you're going Cycling?


  • Bike
  • Lock
  • Jersey
  • Shorts
  • Sunglasses
  • Helmet
  • Garmin
  • Garmin Cable
  • Water bottle
  • Inner tube
  • Puncture repair kit
  • pump
  • shoes
  • Multi tool
  • Spanner

Can we just autofill city and state? Please!

Coming from a country that is not the US where zip/postal codes are hyper specific, it always drives me nuts when you are filling in a form ...