How This Mess Works

So I promised a brief explanation of how this is put together, as I thought it was worth building a website from scratch. Not quite FROM scratch, but, well, not too far either.

                        DIAGRAM 1.A

             +---------------------------------+
             |  raspberry pi                   |
             +---------------------------------+
             |                                 |
             |  ---------------+               |
             |  | rpi_apline   |               |---------- 
             |  +--------------+               |  boot   +|
             |  | nginx        +----------+    | from sd  |
             |  |              |          |    |  card   +|
             |  | uwsgi        | <-----+  |    |---------- 
             |  | django       |       |  |    |
             |  ---------------+       |  |    |
+----------+ |                         |  |    |
|------------+-------------------+     |  |    |
|----------|                     |     |  |    |
|----------|  +-+                |     |  |    |
|----------|  | |                |     |  |    |
|----------|  +-+  root volume   |     |  |    |
|----------|           on        |     |  |    |
|----------|  +-+  thumb drive   |     |  |    |
|----------|  | |                |     |  |    |
|----------|  +-+                |     |  |    |
|----------|                     |     |  |    |
|------------+-------------------+     |  |    |
+----------+ |                         |  |    |
             +-------------------------+--+----+
                                       |  |
                 +------------------+  |  |
           +-----+                  +--+  |
           |     |    home router   |     |     +---
           |  +--+                  +-----+     |
           |  |  +------------------+           | t
           |  |                                 | h
           |  |  +-----------------+            | e
           |  |  | google cloud    |            |
           |  |  +-----------------+            | i
           |  |  |                 |            | n
           |  |  |    +-------+    |            | t
           | ++-----> |       +---------------> | e
           |     |    | nginx |    |            | r
           +----------+       | <---------------+ n
                 |    +-------+    |            | e
                 |                 |            | t
                 |                 |            |
                 +-----------------+            +---


The short answer is this website is hosted on my local hardware, on a raspberry pi, in an alpine docker container, running supervisord maintaining nginx and uwsgi, the latter of which is using the django framework to render pages and save data to a mounted volume on a thumb drive in a sqlite.db file.

The anatomy of the raspberry pi (3, of course. It's my webserver after all) is a boot partition on the sd card, which references a thumb drive as its root partition. This guide goes over it pretty clear detail and it's worked great.

To avoid ruffians bothering me at home, I set up a google cloud engine supertiny instance that's running the official nginx docker image with a simple proxy set up- forward :80 and :443 traffic to my super secret hidden base.

I wanted deployment to be as simple as possible, so I set up this as an ideal deployment workflow:

  • git clone the code repository
  • run ./build-prod.sh
    • build-prod.sh runs docker build . -t prod
    • build-prod.sh runs docker run . -t prod

I strayed a bit from that workflow, but eventually I crafted a CD script that regularly pulls from master, checks if the script needs to be reloaded (due to changes in the CD script itself), and if not it builds a new docker image and replaces the existing running container with one from the newly built code.

That's it! It took probably three weekends to string and glue everything together. Despite this, any pushes to master in github are automatically deployed within five minutes and if both the webserver melted into the ground and my proxy disappeared in an s3-colored cloud of smoke, it would take less than a couple hours to build everything back up.

Except for backups. Ok, adding that to the todo list.

← All writing