Helm108 the Web Server

Blogging About My Server

I recently finished rebuilding the server that this website and some of my projects run on, and now I’m going to write blog posts about what I did and how. Also why. The main goal of this project was to end up with a web server I was happy with, but I also decided to take copious notes on what I was doing and how I did it with the intention of writing blog posts about it when I was done.

My plan for these posts isn’t just to show off the final project and go “tadaaaa!” but to detail each problem I faced and how I solved it, even if I ultimately scrapped that approach. Just because I didn’t like the solution doesn’t mean someone else won’t find the information useful for whatever they’re doing.

What it gotta do

My main requirement for my server was that I could deploy projects to it via git push; I was done with SSH’ing into things. Almost all of the coding I do in my free time is in Javascript so it had to be able to deploy node projects. www.helm108.com was powered by Jekyll at the time so it also had to be able to handle Ruby projects but that was about it.

I had a look for some good solutions for this and found Dokku. Dokku is a self-hosted open source alternative to Heroku and it’s pretty cool. You add your site as a remote in your git project and specify the subdomain you want the project to run from, and providing your project supports the default settings then a git push dokku master will have you up and running in no time. Pretty sweet.

I use Digital Ocean and they offer preconfigured images that you can use. Dokku is on that list so that turned out to be really easy to get working, but eventually I started running into problems with it. Some of them were so long ago that I can’t actually remember any details, but I remember installing a plugin that broke the help output so I couldn’t see how to do things I needed, and I remember it being difficult to work out why one of my projects would just stop working until I deleted it from the server and re-pushed it. This blog would often not re-build properly and new posts wouldn’t appear until I ssh’d in and ran commands manually.

Another issue I had with Dokku was that it runs each project in its own Docker container. While that has its benefits, I didn’t feel that I needed a separate install of an entire OS and node and my other dependencies just for my stupid little projects. Dokku uses a vanilla Ubuntu image by default. I spent some time making my projects use Alpine Linux which reduced both memory and storage use, but I still felt that I wouldn’t have any problems running everything on the host OS.

It’s entirely probable that I was doing something wrong or that I hadn’t read the right part of the documentation. It’s also been about 8 months since I really tried to do anything with Dokku, so since it’s still in active development don’t take the issues I experienced with it as a review of its current state. However, at the time I found the problems I was having frustrating to deal with and I wasn’t able to solve them.

Guess I’ll build my own one then

In late October/early November I decided to solve my problems by building my server myself. The company I work for had switched to Hashicorp’s suite of tools for building and running our servers and as they’re almost all open source and I had direct access to people that knew how to use them it seemed like a reasonable choice for my own server. I spoke to a couple people on our devops team and they recommended Puppet for doing the actual scripting.

My requirements were pretty much the same as before; I wanted to be able to deploy my projects via a git push, and the server needed to be able to run node projects. It also had to handle Ruby as I was still using Jekyll at the time.

I’d read up how best to do a production deploy of a node project and PM2 came up as a solid choice. It replaces node as your command runner (as in pm2 start server.js instead of node server.js) and once it’s in charge of your project it lets you easily check the status of your running node projects, and can be set up to automatically restart your projects if they die for some reason or if the box restarts.

So, git push to deploy, and uses Hashicorp’s tools and has PM2 on it. The text file that I took my notes in now sits at 1752 lines long. My task now is to turn those lines into useful paragraphs with code samples.