#133
Oct 27, 2008

Capistrano Tasks

Do you know how to make Capistrano tasks? See how to change default deployment behavior with custom tasks in this episode.
Download (11.1 MB, 8:49)
alternative download for iPod & Apple TV (10.1 MB, 8:49)

Resources

Directory Structure

  myapp/releases
  myapp/current -> releases/20081019001122
  myapp/shared


cap deploy

  deploy:update_code
  deploy:symlink_shared
  deploy:symlink
  deploy:restart
# deploy.rb
set :application, "railscasts.com"
role :app, application
role :web, application
role :db,  application, :primary => true

set :user, "deploy"
set :deploy_to, "/var/www/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git://github.com/ryanb/railscasts.git"
set :branch, "master"

namespace :deploy do
  desc "Tell Passenger to restart the app."
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
  
  desc "Symlink shared configs and folders on each release."
  task :symlink_shared do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
  end
  
  desc "Sync the public/assets directory."
  task :assets do
    system "rsync -vr --exclude='.DS_Store' public/assets #{user}@#{application}:#{shared_path}/"
  end
end

after 'deploy:update_code', 'deploy:symlink_shared'

RSS Feed for Episode Comments 33 comments

2. Jose Oct 27, 2008 at 06:27

Great screencast ryan, thanks.

True that taskhelper...


2. Chris Saylor Oct 27, 2008 at 06:42

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


3. Bill Oct 27, 2008 at 07:02

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.


4. Russ Jones Oct 27, 2008 at 08:13

That assets trick was great, thanks for sharing Ryan


5. Javan Oct 27, 2008 at 09:46

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?


6. Daryl Oct 27, 2008 at 10:13

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.


7. Jacob Atzen Oct 27, 2008 at 14:51

@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.


8. Michael Oct 27, 2008 at 16:05

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.


9. Bharat Oct 27, 2008 at 17:21

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


10. Marcio Castilho Oct 27, 2008 at 20:17

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 ?


12. Ryan Bates Oct 28, 2008 at 08:09

@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.


13. David Johnson Oct 28, 2008 at 10:08

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.


16. Forrest Zeisler Oct 30, 2008 at 10:11

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.


16. Thanks! Oct 31, 2008 at 23:02

Thanks, you are on the right track!


17. buggybunny Nov 02, 2008 at 11:18

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.


18. David Trasbo Nov 03, 2008 at 23:42

Maybe you should consider some kind of moderation system for these comments. "cheap wow gold"? Hmm...


19. Scott Davis Nov 06, 2008 at 13:02

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


20. Trevor Turk Nov 10, 2008 at 06:58

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/


23. asder Nov 23, 2008 at 19:12

www.virdeal.com/sell-EVE-online-isk.php
www.virdeal.com/sell-ArchLord-Gold.php
www.virdeal.com/sell-City-of-Heroes-Influence.php
www.virdeal.com/sell-Cabal-Online-Alz.php
www.virdeal.com/sell-Fly-For-Fun-penya.php
www.virdeal.com/sell-City-Of-Villains-Infamy.php
www.virdeal.com/sell-City-of-Heroes-Influence.php
www.virdeal.com/sell-ArchLord-Gold.php
www.virdeal.com/sell-KAL-Online-Geons.php


24. sherlockhua Nov 26, 2008 at 02:06

<a href="http://www.3zoom.com/WOW(US)/cheap-powerleveling-8.html">Wrath of the lich king powerleveling</a><br />
  <a href="http://www.3zoom.com/buy-game-card-8.html">WOTLK cdkey</a><br />
  <a href="http://www.3zoom.com/WOW(EU)/cheap-powerleveling-9.html">WOTLK powerleveling</a><br />
  <a href="http://www.3zoom.com/euwarhammer-Alarielle/warhammer-gold-10-2156.html">Warhammer gold</a><br />
  <a href="http://www.3zoom.com/uswarhammer-Anlec/warhammer-gold-5-2189.html">Warhammer online gold</a><br />
  <a href="http://www.3zoom.com/war-all/cheap-powerleveling-5-all.html">Warhammer leveling</a><br />
  <a href="http://www.3zoom.com/uswarhammer-all/warhammer-cdkey-5-all.html">Warhammer timecard</a><br />
  <a href="http://www.3zoom.com/atlantica-Macedon/cheap-gold-15-3154.html">Atlantica online gold</a><br />
  <a href="http://www.3zoom.com/atlantica-Thebes/cheap-gold-15-3153.html">Atlantica gold</a><br />
  <a href="http://www.3zoom.com/atlantica-Thebes/cheap-powerleveling-15-3153.html">Atlantica powerleveling</a><br />
  <a href="http://www.3zoom.com/atlantica-Thebes/cheap-powerleveling-15-3153.html">Atlantica online powerleveling</a><br />
  <a href="http://www.3zoom.com/atlantica-Mycenae/cheap-account-15-3152.html">Atlantica account</a><br />
  <a href="http://www.3zoom.com/atlantica-Sikyon/cheap-account-15-3151.html">Atlantica online account</a>

<a href="http://www.3zoom.com/atlantica-Macedon/cheap-gold-15-3154.html">AT online gold</a><br />
    <a href="http://www.3zoom.com/atlantica-Thebes/cheap-gold-15-3153.html">AT gold</a><br />
    <a href="http://www.3zoom.com/atlantica-Thebes/cheap-powerleveling-15-3153.html">AT powerleveling</a><br />
    <a href="http://www.3zoom.com/atlantica-Thebes/cheap-powerleveling-15-3153.html">AT online powerleveling</a><br />
    <a href="http://www.3zoom.com/atlantica-Mycenae/cheap-account-15-3152.html">AT account</a><br />
  <a href="http://www.3zoom.com/atlantica-Sikyon/cheap-account-15-3151.html">AT online account</a></p>

<a href="http://www.3zoom.com/darkfall-new-11.html">darkfall online</a><br />
  <a href="http://www.3zoom.com/darkfall-All/cheap-gold-11-2247.html">darkfall gold</a><br />
  <a href="http://www.3zoom.com/darkfall-All/cheap-cdkey-11-2247.html">darkfall online gold </a><br />
  <a href="http://www.3zoom.com/darkfall-All/cheap-account-11-2247.html">darkfall account</a><br />
  <a href="http://www.3zoom.com/darkfall-All/cheap-cdkey-11-2247.html">buy darkfall cdkey</a><br />
  <a href="http://www.3zoom.com/darkfall-All/cheap-powerleveling-11-2247.html">darkfall powerleveling</a>


25. Sean Dec 02, 2008 at 14:01

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!


26. Harry Dec 10, 2008 at 21:43

@Javan, you want #{previous_release}.


26. replica watches Dec 21, 2008 at 20:36

[url=http://www.watches-collection.com/]Replica Chopard Watches, Replica Watches[/url]

[url=http://www.watchespage.com]Replica Cartier Replica Chopard Watches Fake Watch[/url]

[url=http://www.pxhelp.com]Replica Watches: Replica Breitling Omega Watch Fake Watches[/url]

[url=http://www.fashion163.com]Replica Breitling Omega Replica Watches Fake Watch[/url]

[url=http://www.21replicawatch.com]Replica Watches - Fake Rolex, Breitling, Omega, Audemars Piguet watch[/url]

[url=http://www.sales-watches.net]Replica Watches Wholesale, Fake Rolex, Gucci, Chanel, Breitling[/url]

[url=http://www.watches-brand.com]Replica Watches,Fake Watch,Brand Replica,Sale Price,Discount Wristwatch[/url]


27. Patrick Berkeley Dec 22, 2008 at 21:46

There's also a 'deploy:cleanup' task that is really useful for limiting the number of releases:

http://pastie.org/343030


28. buy sneaker Dec 23, 2008 at 09:35

buy sneakers wholesale cheap sneakers wholesale jordan shoes buy air force one shoes nike shoes wholesale nike shoes nike shoes wholesale nike jordan shoes jordan shoes air joran shoes air jordan nike air jordan shoes nike air jordan wholesale air jordan air jordan wholesale wholesale jordan shoes jordan shoes wholesale cheap nike shoes discount nike shoes custom air jordan shoes custom air jordan discount air jordan shoes gucci shoes wholesale gucci shoes gucci shoes wholesale timberland boot wholesale timberland boot timberland boot wholesale wholesale wholesale bape shoes nike shox shoes nike shox air max air max shoes nike air max cheap nike jordan shoes cheap nike air jordan shoes women jordan shoes jordans jordan shoes on sale air jordans nike air max shoes discount jordan shoes custom jordan shoes cheap jordan shoes cheap air jordan shoes wholesale shoes shoes wholesale prada shoes wholesale prada shoes wholesale prada shoes bape shoes nike air force one wholesale air force one wholesale air force ones air force one wholesale air force ones


29. 1025 Dec 30, 2008 at 00:03

<a href=http://www.thepowerlevel.com>wow gold</a>
<a href=http://www.thepowerlevel.com>wow gold tips</a>
<a href=http://www.thepowerlevel.com>wow gold guide</a>
<a href=http://www.thepowerlevel.com/Gold.php?N=WOW_US>world of warcraft gold</a>
<a href=http://www.thepowerlevel.com/Gold.php?N=WOW_US>buy wow gold</a>
<a href=http://www.thepowerlevel.com/Gold.php?N=WOW_EU>cheap wow gold</a>
<a href=http://www.thepowerlevel.com/Powerleveling.php?N=WOW_US>wow power leveling</a>

<a href=http://www.thepowerlevel.com/Gold.php?N=Hero>hero gold</a>
<a href=http://www.thepowerlevel.com/Gold.php?N=Hero>hero online gold</a>


30. 深圳搬家 Jan 02, 2009 at 21:46

深圳搬家


31. 搬家公司 Jan 02, 2009 at 21:47

搬家公司


32. 深圳搬家公司 Jan 02, 2009 at 21:47

深圳搬家公司

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player