Powerful Django development process for your cheap web hosted website by Olivier on 19/10/2015 15:50

Context

I was recently looking around for a web framework to build our company website. I compared the existing ones: Wordpress, Joomla, Drupal and their respective reviews. One of the comments I read was: once you choose a framework, you stay with it!
I was a bit worry to choose an initial solution that would not scale with our growing business.

I had already played with Django in the past. And I knew how powerful and flexible Django is. I thought that might be the best choice for our company website. Django Wordpress Joomla Drupal

I knew the web hosting solution we choose when we bought our domain name supports python. So I was assuming they were probably supporting Django too. And bad news! It did not!
As our primary focus is not the web development, we did not want to invest into a dedicated server. And we went for a cheap web hosting solution (£2/month). So, there was no possibility to install additional python modules for our website.
Luckily I found this page: https://gist.github.com/pyguerder/6c67248c4fbcc3b88871 that gives some hints to enable Django on OVH web hosting.

Continuous Integration & Django process

Keeping track of the changed files can be tedious. The best way to keep track of changes is to use Control Version System such as GIT. Copying the files to your FTP is not enough to make a Django based website running. You also need to 'syncdb', update the database and 'collectstatic'.

From these requirements, I went to develop our own deployment script. The aim was to deploy a new version of the website into a single command line!

GIT does not support repository over FTP. Fortunately, there are few people who developed solutions to workaround this limitation. I chose the project https://github.com/ezyang/git-ftp.
I wanted by deployment script to only lives into a single source file. So, I modified this github project to add django support.

The way the script works:

  1. Push the file changes (tracked by GIT) to the FTP server
  2. Create the /media and /static directories (if they do not exist yet)
  3. Invoke the script deploy.cgi on the website to 'syncdb', update the database and 'collectstatics'
  4. Delete the deploy.cgi from the server

To push a new version of our website, we only need to launch ./deploy.py -s production

Issues & Testing

Our web hosting solution offers PostgreSQL. Unfortunately, it was not as simple as copying some .py files to add support for PostgreSQL. The psycopg2 python module requires to be built on the host machine. And obviously, I do not have access to the server so no possibility to build it myself...
I used phpinfo() to find what was the architecture and the Operating System the webserver was running on. And it shown me my server runs on a Intel 32bit Debian Linux.
I had the idea to re-use the debian package python-psycopg2 for my environment.

The website is developed using the django server in local (ie: ./manage.py runserver). But to avoid any bad surprises while deploying on the production server, we installed a similar configuration than the one running there: FTP server, Apache and PostreSQL.
By doing so, we could develop/test our deployment script and django production environment much faster than directly pushing to the server after every single fix.

Security warnings & Limitations

As the django website runs in CGI, the performance are not necessary great. But we do not have a large Internet traffic at the moment and migrating our solution to a dedicated server should be trivial!

Our web hosting solution only provides python 2.6. It means the latest version of Django we can use is Django 1.6 which is not supported anymore - so no more security updates or bug fixes. That is an important consideration to take in account.

Open Source

We have always been great Open Source supporters! That's the reason we contributed as many changes and comments we had made to the respective projects we have been using.

And it is also the reason why I am writing this blog today to enable people with similar needs.
We have also 'open-sourced' a template and our deployment script and a tutorial to allow people to take advantage of our process: https://github.com/labapart/django-website

I will be happy to get as many feedback as possible!

No comment yet

Login to comment Comment as anonymous