Quick rundown of the deployment process

Cloud SQL setup

A few head scratchers trying to get the Postgres Cloud SQL instance setup and communicating with my local development server:

  • Local PostgreSQL service (running on my computer) was still running and sitting on port 5432, so the Cloud SQL proxy couldn't connect to the my newly created Cloud instance
  • My gcloud SDK authentication had lapsed, or gone stale, or something. So the proxy wouldn't connect to the Cloud SQL instance. Had to re-authenticate
  • The Cloud SQL instance was setup to accept unsecured connections, which apparently the proxy didn't like

We're up and running on Google Cloud SQL using a PostgreSQL instance. Still running the site locally to continue development, but the database is Cloud SQL using the proxy to my instance.

App Engine setup

In theory the deployment is as simple as 'gcloud app deploy' after specifying a few settings in app.yaml. But, two big issues popped up when trying to deploy:

  • Initially I was getting a 502 bad gateway error, but that was pretty quickly fixed by adding the gunicorn entry point to app.yaml
  • A much harder (or more elusive) error was repeated 500 errors when requesting pages, after say the first successful request. Ends up that this site exceeded the memory size of the default F1 instance, and I hadn't specified to use F2 in app.yaml

Cloud Storage setup

The biggest issue encountered was CORS. A specific font was not allowed to be shared from my Cloud Storage bucket to my App Engine instance even after I set CORS for the whole bucket, annoying. I ended up finding the specific file in the bucket and "editing metadata" to include "Access-Control-Allow-Origin" with value of "*". Which finally worked.

There isn't good documentation on GCS (that I could fnd) that describes how to confgure Django + GCS to allow for user uploaded content (images, documents, etc) to be stored and saved in a Cloud Storage bucket. Documentation talks about static fles, but not media. Finally got media uploading working using this guide here.

Finally, for some weird reason the latest version of django-storages wasn't displaying any media files that had been uploaded. I could upload them in the admin section, and see them in the bucket, but when trying to view or embed into a post I would get a 500 error. Reverted to version 1.6.5 to fix, as seen below in this sweet SpaceX photo:

test_image

Topic Tags