Turbogears Webfaction Deployment

This site's hosting is provided by the excellent WebFaction. It took me a little while to get a workflow I was comfortable with using, that had the various properties I require, namely:

  • Static content served by the webserver, not cherrypy
  • Everything version controlled, in a single repository (exluding the wordpress instance)
  • Commits to the VCS without requiring those changes to be reflected on the server
  • The ability to rollback updates on the server easily
  • Completely offline working with commit access

Webfaction works on the principle of "applications" and "websites" that can be joined in fairly arbitrary ways. An application for instance could be a directory of files, a turbogears instance, or even a wordpress blog. A website is just an association of an application to a domain name and a path on that domain. So in the case of badrunner.net i have 3 applications, a static directory of files in /static, a turbogears instance for the main site, and a wordpress instance for this blog. The static content of the turbogears instance is serverd by symbolically linking the directories inside the turbogears webapp directory into the static webapp directory. Version control is all handled by bazaar, which is just a fantastic system to work worth. To set this up, just go into the project directory then:

bzr init
bzr add <files I care about>  
bzr commit

Now all the files I want versioned are under bazaar's control, see bazaar-vcs.org for more infofmation on using bazaar. Then you can just copy the whole directory to your local machine (or bzr branch if you so choose), and its already configured to use vcs. However, the next stage involves getting changes from the local machine onto the server and vice versa. First thing to do is create a bazaar repository to push code to (you push commited changes from a branch, and can then pull those changes into another). Having a bazaar repository is actually useful for me anyway, as it provides a place I can push other projects too easily (I am a software developer after all), without any extra work. To do this I created directory bzr in my home directory, and then initialised that with:

bzr init-repository ~/bzr

I can now push and pull to this location over sftp in the case of my local machine, or just locally on the server. I end up with the simple work flow of editing the site locally, commiting as often as I want along the way without fear of server downtime, doing a bzr push at each point I feel the site is ready to deploy. Now, this push alone does not cause the site files to change, it merly gives me the option of being able to log into the server, change to the webapps directory and doing a bzr pull when im fully commited to deploying. At this point you need to restart the turbogears application as you normally would, and all is well!