Locked out!
I managed to lock myself out of my EC2 instance when I was managing my keys. So in order to update my blog, I had to deploy it to a new EC2 instance. I decided to take the opportunity to improve the way I’m deploying new versions of my site.
Note: This will be a technical post. If you’re following along with my adventure in Albania, you can skip this one.
Docker, for fun and profit
Docker is a program which manages “containers”. A container is it’s own isolated system inside a running Linux operating system, separated from other containers and from the main entry point. Docker runs containers from “images”, which contain all the files, programs, and settings necessary for the main program in a container. It’s similar to a lightweight virtual machine.
I was able to use this to pre-package the environment necessary to run my server. Instead of having to remember how to set up nodeJs, install the npm packages, and run the server, I encoded that in my Dockerfile. The Dockerfile contains instructions to build docker containers.
| |
Now I can run it anywhere that has Docker, and I don’t need to worry about installing all my dependencies. They’re all already baked in to the image.
I created a repository on Dockerhub to host my images, so that I can easily pull them down with the web server. Dockerhub has easy integration with Github - all you have to do is link your accounts and you can set up an automatic build whenever you push your code. It also has webhooks - whenever a build completes, it will send a message to any URL you provide. I’m using that to build a chain of tools to automatically deploy my blog whenever I push a new version to Github.
Launching the new server
I went to AWS console and fired up a new EC2 instance, using my existing key pair. I decided this time to track everything I did and keep it in a shell script to make it easy to set up a new instance anytime I need. I shouldn’t treat my web server like a pet, it’s easier to treat it like a head of cattle. When a pet gets sick, you spend a lot of time and effort to nurse it back to health. When a cow gets sick, you slaughter it and buy a new cow.
My init script looks like this (after much trial and error):
| |
I ran that script against a fresh EC2 instance and it fired up my blog! Also, every time I make a new post, I only have to upload it to Github and it’s automatically deployed to my web server in less than 10 minutes. Success!
Hooking up automatic notifications
I’m using MailChimp to manage my email list for my newsletter. It has a ton of great features, even on the free account. One is an automatic campaign which is sent out based on an RSS feed. This is perfect for updating users whenever I post a new blog entry.
I created a sub-section of my subscribers list based on whether they had opted out of receiving blog updates. There’s a new radio dial on the sign-up form that looks like this:
I set up an automatic campaign to send an email with the content of my most recent blog posts. It checks the RSS feed here every day at 4am eastern time, and if there’s a new post, it sends a message and also posts for me on facebook. Neat, eh?

Well, that’s it for this adventure in useless stuff I didn’t really need to do but had fun doing. See you next time, technical readers!