#133 Capistrano Tasks
Oct 27, 2008 | 8 minutes | Tools, Deployment
Do you know how to make Capistrano tasks? See how to change default deployment behavior with custom tasks in this episode.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Capistrano also has built-in support for git submodules, which won't get checked out by default. This is handy if you are tracking plugins or rails as submodules. Turn it on with this setting:
set :git_enable_submodules, 1
Excellent screencast! I was using an "after deploy" task to regen restart.txt and couldn't figure out how to get rid of the "missing pid" error. Moving it into the :deploy namespace was just what I needed.
Is there an easy way to access something like previous_release_path in the case that you want to copy something from the last release to the new release?
You lost me on the last step... I snapped my fingers, but my code didn't auto-document. Am I missing a gem or something? ;-)
Thanks for this screencast.
@Javan: Usually you don't copy from release to release. Anything that needs to be shared between releases should be put in the shared directory and symlinked from the releases/current directories.
Thanks for the screencast.
Maybe you can talk a little about webistrano next time. So you can use capistrano in a website so you can easily manage a bunch of websites and you can share symlinks.
Ryan,
Your screencasts are great. Like you, I had trouble understanding Capistrano at first. I found Ezra Zygmuntowicz's Deploying Rails Application book's Chapter 5 on Capistrano to be very helpful in getting the concepts straight, and after reading that last night had no trouble implementing a deploy script that I had been struggling with all week-end.
Bharat
One problem I am having is creating a Capistrano for Workling/Startling. I have created a task to start workling, everything executes properly but the process is never started.
Anybody has succefully created a Workling client start capistrano recipe ?
@Marcio, it's hard to say what the problem is without knowing the error message or the code. I recommend making a thread on a forum or mailing list where you can go into these details. It may have to do with a missing gem or config file.
Ryan,
Great screencast, one of many uses I have found for Capistrano is the ability to "automate" copying production database data to the development machine. Credit the code I re-used to http://marklunds.com/articles/one/339 although there are multiple other URLs with examples. It sure is useful to be able to automate repetitive tasks on the remote servers.
This was a great post. Our app has a large number of tutorial flash videos in the public folder. I've already started building in the separate asset uploads. Thanks for the tips.
Ryan,
although it has been said many times i have to say this one more time:
Your screencasts are absolutely outstanding and helped me A LOT.
Ryan,
You should really check out passenger recipes for Capistrano its maturing nicely and is very functional.
http://github.com/jtrupiano/passenger-recipes/tree/master
Capistrano extensions which is also required
http://github.com/jtrupiano/capistrano-extensions/tree/master
I did a little write-up about working with file assets and Capistrano deployments that people may be interested in:
http://almosteffortless.com/2007/03/25/working-with-attachment_fu/
Ryan,
I don't see how /shared/config/database.yml gets created.
Did you create the /shared/config directory and place the database.yml file into that directory manually before running the cap script.
Thanks for the screencasts!
@Javan, you want #{previous_release}.
There's also a 'deploy:cleanup' task that is really useful for limiting the number of releases:
http://pastie.org/343030
I believe putting the rsync task in there will run it on the server machine, where you probably want to run that on your local machine to rsync files from the local machine to the server.
Is there a way to run commands/tasks for deployment on the local machine?
Thanks, this helped tremendously.
Because of my total lack of knowledge about symlinks and Linux in general, I was a bit confused about something there.
In this example:
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
the latter path links *to* the former, right? I.e. you create a symlink *from* #{release_path}/public/assets *to* #{shared_path}/assets
So, anything being saved to /public/assets actually ends up in the shared/assets folder.
Please tell me if I'm wrong.
Fantastic, thanks. Have spent all day trying to work out how I could reconcile the fact that my apps have very large files and my shared hosting account has very small processor allocation. git seems to be a hungry beast and before total despair I found this railscast. hope this will resolve the issue!! thanks so much.
this is the most helpful thing i have come across for understanding capistrano. 8 mins instead of rereading the capistrano site and whatever else I could find 100 times.
@Sean - the shared folder gets created when you run cap deploy:setup. I'm not sure how the database.yml file got there though. If there isn't an automatic way to upload files in the shared folder, my guess is that ryan uploaded it there (via ftp or the like).
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
SEO Companies In Lahore
If your assets directory has a lot of compressible files, e.g. text, XML, JS, etc. rsync -z to compress can be worthwhile. Rather than -r which just recurses into the directory, consider -a (--archive) which preserves timestamps, ownership, symlinks, etc. Depending on circumstances this can be less surprising...