I've grown tired of committing changes to my subversion repository, logging into my server, updating my live checkout, and restarting python processes. I finally decided to implement Capistrano and eliminate this repetition.
Here are my repetitive set of commands:
$ ssh playgroundblues.com
$ cd ~/projects/playgroundblues
$ svn up
$ cd ~/www/playgroundblues.com/www
$ touch django.fcgi
Now, with the help of Capistrano, I just type:
$ cap deploy
You'll first need to install Capistrano which is as simple as gem install -y capistrano. Once that's complete you need to create a "capfile" which is where you'll define your tasks:
task :deploy, :hosts => "username@playgroundblues.com" do
run "cd ~/projects/playgroundblues; svn up; cd ~/www/playgroundblues.com/www/; touch django.fcgi"
end
The above will vary depending on your host and directory setup. After you save the above file and as long as you're in the directory where the capfile resides you can, in the terminal, type cap deploy and Capistrano does the rest. Bliss.
Related tags: capistrano, deployment, ruby
Comments
Nathan Borror http://www.playgroundblues.com
I should point out, Ryan told me about Capistrano about year and a half ago and it's taken me this long to finally install it :-\
Wilson Miner http://www.wilsonminer.com/
I just set up a capfile to do the same thing for my site this weekend. I also wired up Adrian's S3 upload script to upload my media files to S3 as one of the tasks.
Jeff Croft http://jeffcroft.com/
So I know almost nothing about Capistraino, but it sounds interesting. Allow me to ask a dumb question: is Capistraino installed on your local Mac, on the your web server, or both?
I assume, from your post, you're typing "cap deploy" on your local Mac. Is that right? Or are you SSHing in and then doing that on the remote server?
Nathan Borror http://www.playgroundblues.com
@Jeff - You just install it locally. No need to install it on the server.
Ben Turner
Nathan, thanks for putting these directions up. I'll have to delve into Capistrano after I finish getting my development environment setup. I realized as I was configuring my environment I was going to have a lot of "svn up" commands to run. Whew!
Tom Watson http://tincorporated.com
Very, very cool. Forgive me if I'm asking some dumb questions but...
Are these "capfiles" only used by Capistrano? Is it basically just a fancy "alias" on your local machine? Is there much benefit to using Capistrano over logging into the server via ssh and running a batch command?
Xian http://mintchaos.com
@tom, for a simple case like this, an alias + maybe a script file will do just fine. Capistrano's real beauty comes out when you have it performing multiple tasks across multiple servers simultaneously. There are some pretty neat things you can do with it.
Tim http://fewagainstmany.com
sweet ! I'll give it a try at work today. Thanks Nathan
Šime
Did you tried Vlad the Deployer? There is also Python solution forming up: http://pypi.python.org/pypi/Fabric
Pete http://lincolnloop.com
Are you deploying on every commit? If so, a simple subversion post-commit hook would handle your needs:
ssh playgroundblues.com "svn up ~/projects/playgroundblues && touch /www/playgroundblues.com/www/django.fcgi"
If your svn repo is on the same server, you can skip the ssh command.
Nathan Borror http://www.playgroundblues.com
@Tom - You're right, I could set up some aliases but, like Jeff said, when you start managing multiple projects and multiple servers it's much easier to use Capistrano.
Plus my bash skills suck and this gives me a reason to use Ruby which I actually like (shhh don't tell anyone).
@Pete - I don't always deploy on every commit. I usually leave some breathing room in between a major commit and updating a live site. I've never used post-commit hooks but you've sparked my interest.
Jon Buda http://www.inkandcoffee.com
Dude, yes, Capistrano is the shit. Quite the timesaver. And you don't have to feel bad about liking Ruby, it's better than Python anyways ;) But anyways, yeah it rocks, glad you're enjoying it.
Bryan Veloso http://avalonstar.com
Definitely looking at using this for my next release. I'm glad that more references than the one Google link I found are now available for it! Now I won't feel like a complete idiot while using it. :D
Ryan Carver http://fivesevensix.com
Hooray! Now you should check out git. svn is old school.
Mike Stickel http://screenflicker.com/mike/
Um, yeah. Capistrano is the shit! I've only seen pieces of it in action and I'm only using v1 but it's awesome. Capistrano 2 is even better!
@Tom: The Capfiles are only on your local machine (and your repo if you've added it). They aren't aliases, the Capfile holds all your methods for the cap command. You can do pretty much anything you want, you just have to write a method for it.
@Bryan: Yeah, the worst thing about Capistrano is the documentation. :(
Lucas Vogelsang http://lucasvo.com
I heard of capistrano and even intended to use it. but I decided to use fabric instead. It's pretty much a python version of capistrano.
My deployment script can even handle new installations, create sql databases. We integrated the django template rendering engine, and extended fabric with an option that renders the file(variables are defined in the fabfile and inserted into my various config files(lighttpd.conf, settings.py). If anyone's interested in the code I'm happy to share it. Just write me an email.
The documentation isn't better though :(
Magda http://www.pluch.info
Capistrano documentation is just awful