Everyone is talking about SwitchTower these days, so I just had to check it out. When I got it to work, I was quite pleased with how it works, but there were quite a few issues along the road.
First of: What is SwitchTower? Basically, it is a tool for automating deployment of applications, focused around Ruby on Rails. With SwitchTower in place, I am able to write stuff like “
rake deploy” and “
rake deploy will: check in my code locally, check out the latest version on the server, and update a symbolic link to point to it. On the best of days, it is “one click deployment”.
However, it took me quite a bit of effort to get it to work. Much of the reason for this, was that I am running my development on Windows with a local CVSROOT and deploying to Linux. This introduced some hitches.
rake deploy will not run on Windows out of the box. The reason: it is defined as
system "switchtower -vvvv -r config/deploy -a deploy". On Windows, this should be
system "switchtower.cmd -vvvv -r config/deploy -a deploy". In addition, I am saddened by the fact that rake does a system call out to execute switchtower, instead of directly invoking Ruby code.
Source repository location: I had major problems with the version control. The documentation is not explicit about this, so I wasn’t sure, but SwitchTower does a checkout from the server, instead of checking out at the client, packing the code, and shipping it. If you CVS server is behind a firewall that can’t be reached from the server, this won’t work, quite simply. Instead of using CVS I decided to switch to hosting SVN on the same server as the application.
Subversion on Windows: Getting SVN to work on Windows was not straightforward, either. Basically, I had to edit the rather obscure “
C:\documents and settings\username\Application Data\Subversion\config” file to set the correct ssh-client. I also had to use svn+ssh, which means I had to specify the password in the SwitchTower deploy.rb-file (ouch!). I also had to patch up switchtower/lib/scm/subversion.rb: It uses the regexp “
/^Password.*:/” to check if the server prompts for password. But my server says: “
Unix and Windows incompabilities: Getting it to work on the server. I have encountered a number of problems with getting it to work, none of which are caused (or solved) by SwitchTower. First: Make sure the shebang (“#!…/ruby”) line in dispatch.rb, dispatch.cgi and dispatch.fcgi is correct. Since I don’t deploy on Apache on Windows, I have left all these as #!/usr/local/bin/ruby. Second: File format. This is extremely important: .htaccess and dispatch.* should have Unix line endings (many Unices come with “dos2unix” for fixing this). Luckily, Ruby is quite lenient about line endings, so these four files are the only ones where file format is critical. Third: The production server in database.yml has to be set correctly. All these issues are best fixed by making changes to the files in your repository.
Last, dispatch.* should be executable. I am not sure if this is even possible in CVS, but in SVN, you just set the “
svn:executable” property, and Bob’s your uncle. I do wish that SwitchTower could’ve set the executable bit, though.
With all these gotchas, I finally got SwitchTower to work. So far, once I have gotten it to work, it is a thing of beauty. My second deployment worked on the first try! Check it out, but bring a good guide (like this document) and some patience – SwitchTower still have quite sharp edges.