How I do Python/Django on OS X
(this is a repost from the startupās devblog)
At the startup I am working at, we currently run our own stack of bits on an Ubuntu AWS EC2 compute unit along with other services on the AWS infrastructure. This server currently has Postgis (Postgres with spatial additions), Apache, Python, Django and various other python specific utilities like Tornado and Celery. Its fairly easy to build a VM image that closely match those specs down to the actual version number of the bits installed, or even to just grab the AMI image and have it run as a VM image locally.
One of the things I loathe the most is cluttering my system with installations of things that I have no control over. As such, I am a huge fan of things like MacPorts and also Homebrew. As far as installing things on OS X, those 2 are the limits I would go. When it comes to writing Python/Django and also perhaps Ruby On Rails, having the āenvironmentā setup is a big deal and OS X is not one that is particularly tolerant. Being a huge fan of āself-containnessā, it was unacceptable to hack around too much with the CLI and Macports to get everything working right.
So to deal with all these bullshit, Iāve come up with a setup that I am fairly happy with and am actually fairly productive in. All server sided development is done with a VM image of the environment that closely resembles production but with some additional things to make it easy.
The following is the list of things that can make server sided development easier on OS X,
VMWare Fusion
Avahi (ZeroConf)
Transmit
Git
Your-Favorite-Text-Editor
VMWare Fusion
Runs your average Virtual Machine images. I like it because it is a pretty stable piece of sofware with VMWareās engineering pedigree when it comes to virtual machines. You donāt really use much of its features for running a purely server type VM, but I like that it has pretty tight integration with OS X and plays nicely with most VM formats.
The added benefit of using a VM is that you technically can have a master cloned copy of the production environment that can be passed around to your developers thus reducing the time to get setup and transitioning to actually doing productive useful work.
Avahi (ZeroConf)
This is the name of the package that contains the ZeroConf daemon for Ubuntu. This is a nice to have as it makes local DNS resolutions really easy since OS X supports ZeroConf out of the box through Bonjour. The added benefit is that if your development team mostly use Macs, everyone can see your VM on the network. Since it has a constant domain name, this fits the self contained principle of my software architecture philsophy and makes moving and packaging the VM image really easy. No more fiddling with IP addresses is always a plus along with the fact that you can work in an IPv4 or IPv6 environment.
Getting Avahi setup on Ubuntu is fairly easy through aptitude. Configuration-wise, I like to advertise the sftp/ssh service along with the django local server parameters. Using the defaults is perfectly fine to get Avahi up and running. All that is left is to create the services that it will advertise.
This is an example .service file for the ssh service,
<?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_sftp-ssh._tcp</type> <port>22</port> </service> </service-group>
Once these files are created in the /etc/avahi/services directory its just a simple /etc/init.d/avahi restart to get it to reload the configuration and you should see it being advertised.
Safari is nicely Bonjour aware too.
Transmit
You can of course use any other service that lets you mount SFTP shares, but since I already own Transmit, its Transmit Disk feature really makes things easy. Prerequsites when using this method to do development work would be that you have the stuff you are working on be within your home directory on the VM. So at the end, its just a simple matter of firing up the VM, forgetting about it and telling Transmit to mount the Bonjour discovered SFTP share to get access to the physical files.
This setup ensures you would not need to have another copy on your actual Mac and upload files in order to test it on the server within the VM. One caveat is that git doesnāt seem to run well over SFTP so you still would need to deal with actual source control commits within the actual VM. If youāre 1337 enough, you would probably have Terminal open and an SSH session started to the Bonjour domain. Otherwise, its just a simple matter of having Mission Control manage the window that VMWare Fusion is to allow for fast switching.
GIT
I cannot state how awesome git is for development work. The fact that it is a decentarlized system allows any number of people to work on features to eventually syncing those changes. I typically work on a branch of a single feature doing constant commits when things change. Once a feature is complete, I would squash those commits to make things more comprehensive before doing a Pull Request to the main repository for code review before merging.
In order to make merging easier, I would constantly rebase my feature branch whenever new things get pushed to the master branch. This causes less headaches when the final merge happens and generally makes the repository maintainer much happier.
One advantage of not being able to use GUI tools for dealing with git over SFTP is that you have a chance to get proficient with the command line commands. No better way to learn things than actually doing it.
Your-Favorite-Text-Editor
So what is the point of all these? Its so you can use your favorite text editor on OS X.
If youāre a hardcore vim or emacs person, this would probably have no meaning for you, but for the rest of the human race that arenāt that proficient at non WYSIWYG text editors, this is a fairly simple way to let you use your favorite text editor to do development work.












