Deployment Made Easy

Hey everyone,

My post today is going to be about deployment, a subject I dreaded as a beginner web developer. When I first made scholtek.com, my deployment strategy consisted of accessing the web server with Filezilla, and copying everything into the public root on my server. It was slow, and not at all scalable. It didn't allow any room for extra build processes such as minification or image compression. My builds were handled manually, one painful step at a time.

With my recent move to Django, and my new experience of deployment done by professionals at work, I decided to make things easier. The first thing I needed was a server that actually gave me some control. Up to this point, I'd been using the cheapest plan from HostGator - for shared hosting it worked very well. On my peak day, the site had more than 12,000 hits and HostGator never complained. For someone just starting out, they're a great option. But now I wanted to flexibility available with a Virtual Private Server, which provides a nice little sandbox where I can do whatever I want. Most of my experience was been with Amazon's elastic compute cloud offerings, which I enjoyed using and think is a clear choice if you're going to scale to hundreds of thousands of hits per day, but I decided to go with Digital Ocean, which boasted one click Django deployment, and a cheapest plan at $5 per month.

As can be expected, the VPS for this server is not a powerhouse. It provides 512MB memory and a single core, but even that is likely to outperform a shared hosting plan, and I have the advantage of a very low consumption website. All of the content currently on scholtek.com is static content, meaning it's the same for each and every user of the site. That provides a lot of room for caching and other optimization, which I have yet to test out (don't worry - that blog post will come as well!), and so the plan I have should be just fine.

The other benefit of Digital Ocean is their wealth of documentation. In particular, I found an article on automatically deploying with git. I'll leave the details to the article, but the summary is:

  1. Create an empty git repository on the server
  2. Create a post-receive hook on git that copies the files to your django projects location, and restarts the server
  3. Set that repo as a remote on your local git branch
  4. Type 'git push branch-to-deploy
  5. Profit!

If that sounds extremely easy, it's because it was. So this complicated manual deployment method I've been using for the past year was replaced in under 20 minutes using git and a VPS. To any web developers out there, I can't recommend this approach strongly enough.

-Keilan

Why Django?

Hello Gamers,

If any of you are exceedingly observant, or enjoy poking around my source code, you might have noticed some changes around the site recently. This is because I've migrated from a site that I cobbled together using php (which I don't know) to using Django, a python framework that simplifies a lot of web development. It's also the framework that I have the most experience with as I use it professionally. I decided to migrate the site for a number of reasons:

  1. DRY - Don't Repeat Yourself is a major principle of the Django framework and as I thought about the future of scholtek.com, I realized that if I'm going to store multiple games here, I could end up with a big task if I want to make a minor change to the game interface. Django templating allows me to build a base template, and then extend it for each individual game, so changes can made quickly and easily.
  2. Speed - It's no secret that free online games don't bring in a lot of money. So far I've been able to recoup my server costs, but just barely. Breaking even is still a better return than most hobbies, so I'll take it. However, this means that I want to be able to handle a lot of traffic without much server power. Django has an extensive caching framework, and since my site is almost entirely static content, it's a perfect use case for caching. My hope is that even a small server will be able to handle so much traffic, that if I get to that point I can buy a better server.
  3. Extensibility - When I started Scholtek, one of my goals was to learn website building from the ground up. That meant as few frameworks and existing libraries as possible. However, now that I have that experience I want to be able to build the site more quickly and easily. For that, Django really shines. It has a vibrant community and a large number of plugins, not to mention Stack Overflow questions (and we all know programming is really just finding the right answers on SO). Previously I had been spending hours on things that could take minutes, which was a great learning experience, but moving forward, Django will let me spend days on things that would take months to do on my own. Less feasible for a hobby developer.

So far the transition has been quite painless - I used fairly limited php and so the Django template system has been more than adequate to replace it, and in cases where it wasn't, it was quite simple to write extra template tags to take over. My code repetition has been reduced greatly, and I feel much more confident in my ability to extend the site. My next step is to find an affordable VPS to deploy on, and set up some handy functionality like automatic minification and one click deployment. But that's a separate post.

To be continued...

-Keilan