You can use the "on" keyword to declare a general event handler:

   on :before, :check_rails_env

The "before" and "after" keywords are just syntactic sugar, wrapped  
around the "on" keyword". In fact, "before :deploy, :check_rails_env"  
is identical to:

   on :before, :check_rails_env, :only => :deploy

Beware, though: the "before" trigger is called before EVERY task,  
even if that task was called by another task. On the other hand, the  
"start" trigger is called only for tasks invoked at the "top" (e.g.,  
from the command-line, etc.).

Regarding staging environments, here is a variation on a technique I  
presented at RailsConf:

   STAGES = %w(staging production)
   STAGES.each do |name|
     desc "Set the target stage to `#{name}'."
     task(name) do
       set :stage, name.to_sym
       load "config/deploy/#{stage}"
     end
   end

   on :start, :except => STAGES do
     if !exists?(:stage)
       abort "no stage specified, please choose one of #{STAGES.join 
(", ")}"
     end
   end

You then put your staging-specific configuration in config/deploy/ 
staging.rb and config/deploy/production.rb.

Hope that helps,

Jamis

On Jun 15, 2007, at 7:39 AM, Chrisl wrote:

>
>
> I've used an approach very similar to Simon Harris's (http://
> www.redhillconsulting.com.au/blogs/simon/archives/000359.html) for
> deploying to staging & production environments but using cap 1.99.1.
>
> This means that I have an extra task for each environment:
>
> desc "Settings specific to staging environment"
> task :staging do
>   set :rails_env, "staging"
>   set :mongrel_port, "7700"
> end
>
> desc "Settings specific to production environment"
> task :production do
>   set :rails_env, "production"
>   set :mongrel_port, "8800"
> end
>
> This means I have to type 'cap staging deploy:cold' for example. If I
> forget and type 'cap deploy:cold' things break in a not-terribly-
> elegant way with an exception being thrown.
>
> To get round this I put in a before hook for deploy, start & stop to
> ensure that the staging or production tasks have been called:
>
> set :rails_env, nil
> task :check_rails_env do
>   if rails_env.nil?
>     puts
>     puts "Usage: cap staging <task>     - runs task on staging
> environment"
>     puts "   or: cap production <task>  - runs task on production
> environment"
>     puts
>     exit(1)
>   end
> end
>
> before :deploy, :check_rails_env
> before "deploy:start", :check_rails_env
> before "deploy:stop", :check_rails_env
>
> Is it possible to specify a wildcard for before, e.g.
>
> before "deploy:*", :check_rails_env
>
> or is there a more elegant way of making rails_env a prerequisite for
> all tasks, or perhaps all tasks in a namespace?
>
> -Chrisl
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to