Moving to Google Cloud Run


Last night I moved this site from a VM in the UK to a static deployment in Google Cloud Run. It’s a neat service that can take a pre-packaged container and route HTTP and gRPC requests to that container. The concept of having immutable versions of infrastructure deployed, such that it’s clear what the deltas between versions were, and rollback is clearly nothing new, but it’s really nice that it’s quite so easy to deploy things on GCP this way now.

I’ve got something similar built for personally. We’ve also been moving a lot of our infrastructure this way for OpenConfig, including adopting Cloud Build for CI/CD.

One interesting learning from this deployment experience was the requirement for nginx rewrites. In the original blog application I wrote (PHP, I believe, or maybe it was Django), I decided to make URLs not end with a /, and hence a number of the external links to the site use that form. I’ve been doing redirects for a while on the old nginx and httpd installs to make those continue to work. Moving into GCR, adding the redirects made the request hang, which I found quite odd. It turns out that one needs to specify:

server {
	listen $PORT;
	port_in_redirect off;

as part of the nginx config. If you don’t do this, then the request will redirect to yoururl.tld:$PORT, and since the loadbalancer in front of the container isn’t expecting requests at $PORT, then this ends up hanging. I didn’t quite find anything just spelling this out elsewhere, so figured it was worth writing down here.

I hope folks that are reading here, the few that there are 😉, are staying safe and mentally and physically healthy during the strange times we find ourselves in.

All the best, r.