Does multistage require separate deploy files?

279 views
Skip to first unread message

me

unread,
Jan 23, 2008, 11:58:47 PM1/23/08
to Capistrano
Forgive me if this is a basic question. I'm attempting to support
multiple-stage deployment, and I start out with:

set :stages, %w(production staging qa)
require 'capistrano/ext/multistage'

in my deploy.rb file.

But I get an error where it appears to try to find a file based on one
of the environment names:

$ cap qa deploy:setup
* executing `qa'
/usr/local/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/
configuration/loading.rb:184:in `find_file_in_load_path': no such file
to load -- config/deploy/qa (LoadError)

Does this mean I need to have the following files, as well?
config/deploy/qa.rb
config/deploy/production.rb
config/deploy/staging.rb

Rafael G.

unread,
Jan 24, 2008, 10:24:26 AM1/24/08
to capis...@googlegroups.com
me escribió:
Yes :)

--
Rafael Garcia Ortega

rgo.vcf

me

unread,
Jan 24, 2008, 10:51:26 AM1/24/08
to Capistrano
In the spirit of DRY, would it still be possible to keep things in one
deploy.rb and just do for the following since (so far, I think) that's
how each of the three deploy files would differ from each other?

set :deploy_to, "/srv/www/htdocs/#{application}/#{stages}"
set :mongrel_conf, "#{deploy_to}/current/config/mongrel_cluster/
#{stages}.yml"
> rgo.vcf
> 1KDownload

Izidor Jerebic

unread,
Jan 25, 2008, 2:52:41 AM1/25/08
to capis...@googlegroups.com

The simplest way of doing multi-stage is to create separate tasks for
each stage, and define variables therein:

task :first do
set :var, "value 1"
set..
end

task :second do
set :var, "value 2"
set ..
end

and then calling cap like "cap first deploy" or "cap second deploy".

No need for anything else....

izidor

Rafael G.

unread,
Jan 25, 2008, 5:10:11 AM1/25/08
to capis...@googlegroups.com
I use config/deploy.rb for common things (tasks, variables,...), then in
every stage put customized things.
For example:

== config/deploy.rb

set :stages, %w(foo bar)
set :default_stage, "foo"
require 'capistrano/ext/multistage'

set :repository, "https://repository/trunk"
set :user, "my_user"

...

# Some common tasks


== config/deploy/foo.rb

role :app, "foo.host.com"
role :web, "foo.host.com"
role :db, "foo.host.com", :primary => true

== config/deploy/bar.rb

role :app, "bar.host.com", "bar2.host.com"
role :web, "bar.host.com"
role :db, "bar.host.com", :primary => true


In this case. I used differents hosts in differents stages. You can do
the same with tasks.
Regards

me escribió:


--
Rafael Garcia Ortega

rgo.vcf

lamp5matt

unread,
Jan 25, 2008, 10:07:17 AM1/25/08
to Capistrano
I'm getting no love from multistage. I have the gem, and
set :stages, %w(qa dev)
set :default_stage, "dev"
require 'capistrano/ext/multistage'

but config/deploy/dev.rb doesn't seem to get loaded -- in particular
run "this sucks"
role :web, "jtjdev"

but

>cap dev connect
...
servers: ["64.34.XXX.XX"] #the qa server!

and i don't get the 'this sucks' message either
> rgo.vcf
> 1KDownload

Rafael G.

unread,
Jan 25, 2008, 10:22:34 AM1/25/08
to capis...@googlegroups.com
delete in config/deploy/dev.rblamp5matt
run "this sucks"

and try this task:

cap dev shell

then put:

pwd

It will show you the path in remote server.

Regards!

PS: I think that "run ..." must be in a task.

escribió:


--
Rafael Garcia Ortega

rgo.vcf

me

unread,
Jan 25, 2008, 2:06:29 PM1/25/08
to Capistrano
On a slight tangent, do you also end up with different mongrel_conf
files?
If so, how do you deal with what to put in script/spin?


I'm torn because I'm now trying to figure out how to do something
like:

/usr/bin/mongrel_rails cluster::start -C /path/app_name/#{stage}/
current/config/mongrel_cluster.yml
> rgo.vcf
> 1KDownload

Rafael G.

unread,
Jan 27, 2008, 1:36:10 PM1/27/08
to capis...@googlegroups.com
Normally, I have different mongrel_cluster.yml files but never use
script/spin.
I rewrite deploy:%w(start stop restart) and make tasks for config files.

For example:

== config/deploy.rb
# Common variables
# ...

# Tasks for mongrel
desc "Modified restart task for work ONLY with mongrel cluster"
task :restart do
stop
start
end
desc "Modified start task for work ONLY with mongrel cluster"
task :start do
run "cd #{deploy_to}/current && mongrel_rails cluster::start"
end
desc "Modified stop task for work ONLY with mongrel cluster"
task :stop do
run "cd #{deploy_to}/current && mongrel_rails cluster::stop"
end

# Tasks for config files
namespace :config_files do
require 'erb'
desc "Create config files:database.yml, mongrel_cluster.yml and mailer.rb"
task :default do
database_yml
mongrel_cluster_yml
mailer_rb
local_config_rb
end
desc "Make symlink for config files"
task :symlink do
symlink_database_yml
symlink_mongrel_cluster_yml
symlink_mailer_rb
symlink_local_config_rb
end

desc "Create mongrel_cluster yaml in shared path"
task :mongrel_cluster_yml do
template = File.read(File.join(File.dirname(__FILE__), "deploy/templates", "mongrel_cluster.erb"))
result = ERB.new(template).result(binding)
run "mkdir -p #{shared_path}/config"
put result, "#{shared_path}/config/mongrel_cluster.yml"
end

desc "Make symlink for mongrel_cluster yaml"
task :symlink_mongrel_cluster_yml do
run "ln -nfs #{shared_path}/config/mongrel_cluster.yml #{release_path}/config/mongrel_cluster.yml"
end

# More config_files tasks
# ...

# More common tasks
# ...

== config/deploy/templates/mongrel_cluster.erb

---
user: <%= mongrel_username %>
group: <%= mongrel_group %>
cwd: <%= current_path %>
port: "<%= mongrel_port %>"
environment: <%= rails_env || 'production' %>
address: 127.0.0.1
pid_file: <%= shared_path %>/log/mongrel.pid
log_file: <%= shared_path %>/log/mongrel.log
servers: <%= mongrel_servers %>

== config/deploy/stage1.rb
set :user, "foo"
# Mongrel configuration variables
set :mongrel_port, 8008
set :mongrel_servers, 3
set :mongrel_username, user # Change if user is diffent to shell user
set :mongrel_group, user # Change if group is different to shell group

role :app, "foo.com"
role :web, "foo.com"
role :db, "bar.com", :primary => true

# More tasks and variables
#...


== config/deploy/stage2.rb
# Mongrel configuration variables
set :mongrel_port, 3000
set :mongrel_servers, 2
set :mongrel_username, "foobar"
set :mongrel_group, "foobar"

role :app, "baz.com"
role :web, "baz.com"
role :db, "baz.com", :primary => true

# More tasks and variables
#...

More or less :)

Regards

me escribió:


--
Rafael Garcia Ortega

rgo.vcf

me

unread,
Feb 11, 2008, 2:57:08 PM2/11/08
to Capistrano
Thanks for all this!

I'm getting around to implementing this per your example, and I have a
few questions as I'm getting core dumps.


In the below snippet:

> # Tasks for config files
>   namespace :config_files do
>   require 'erb'
>     desc "Create config files:database.yml, mongrel_cluster.yml and mailer.rb"
>     task :default do
>       database_yml
>       mongrel_cluster_yml
>       mailer_rb
>       local_config_rb
>     end

I commented out databas_yml, mailer_rb, and local_config_rb since I
wanted to address just my issue with the mongrel cluster pointing to
the right YAML file at startup. Was this wrong to do, especially
commenting out database_yml? Does this mean it is unable to find the
location for database.yml?


Rafael G.

unread,
Feb 12, 2008, 4:33:35 AM2/12/08
to capis...@googlegroups.com
If you commented the others tasks you would create only
mongrel_cluster.yml file (If you had database.yml - all required files -
in your repository no problem else the rails app. will fail).

With this tasks only create the files in shared path, remember that I
used a trigger/callback that creates symbolics links after
deploy:update_code. All will run ok before create symlinks in config path.

me escribió:


>
> I commented out databas_yml, mailer_rb, and local_config_rb since I
> wanted to address just my issue with the mongrel cluster pointing to
> the right YAML file at startup. Was this wrong to do, especially
> commenting out database_yml? Does this mean it is unable to find the
> location for database.yml?
>
>

Surely, you will fail because it lacks the configuration files.

Regards

--
Rafael Garcia Ortega

rgo.vcf

Student

unread,
Feb 13, 2008, 12:08:25 PM2/13/08
to Capistrano
I've gone overboard with vendor everything, and have checked in all my
gems as well as the rubygem tar file. As a result, I have added the
following task:

task :before_finalize_update, :except => { :no_release => true } do
run "cd #{latest_release} ; ruby deploy/deploy.rb"
end

where my deploy/deploy.rb script does a whole LOT of stuff to get my
checked out code ready to run. If you used

task :before_finalize_update, :except => { :no_release => true } do
run "cd #{latest_release} ; ruby deploy/deploy.rb #{stage}"
end

you should have plenty of room to play...
> rgo.vcf
> 1KDownload
Reply all
Reply to author
Forward
0 new messages