Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano deploy to staging and production

I am trying to deploy a Ruby On Rails app to both staging and then production using Capistrano.

The only difference between the two is the :domain and the :repository

I have followed this guide here: https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension

I have searched around the net and all I find are articles that basically rehash what I have above.

I have tried just setting the :domain and :repository in the config/deploy/staging.rb and config/deploy/production.rb

I have checked my spellings to make sure I spelt the sub-dirs correctly and the names of the files.

Reading this article: staging and live app with capistrano it looks like I should just be able to declare the differences here.

It doesn't look like the staging.rb file is actually being read. I changed my "deploy.rb" to have a single swear word as the first line, "cap deploy" gives me the expected error.

If I put a single swear word on the first line of "staging.rb" or "production.rb" I get the same error:

`method_missing': undefined local variable or method `domain'

The line in question is:

role :web, domain

because the value is not being picked up. But surely it should fail on the single swear word in staging.rb or production.rb and not run at all?

If I move the :domain and :repository back into the main "deploy.rb" file I get the error with the swear word. So it would seem that I can't set variables in the "staging.rg" and "production.rb" files but just complete tasks.

Any help would be much appreciated or do you think I should just take the pizza delivery job ...

deploy.rb:

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

set :user, 'dave'

set :applicationdir, "~/rails/example.com"

set :scm, 'git'

set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true

set :keep_releases, 5
after "deploy:update", "deploy:cleanup"

# roles (servers)
role :web, domain
role :app, domain
role :db,  domain, :primary => true

after "deploy", "deploy:migrate"

# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
# set :rake, 'bundle exec rake'

# additional settings
default_run_options[:pty] = true  # Forgo errors when deploying from windows
set :ssh_options, {:forward_agent => true}
#ssh_options[:keys] = %w(/home/user/.ssh/id_rsa)            # If you are using ssh_keysset :chmod755, "app config db lib public vendor script script/* public/disp*"set :use_sudo, false


# Passenger
namespace :deploy do
   task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
      run " touch #{File.join(current_path,'tmp','restart.txt')}"
   end
end

And my config/deploy/staging.rb file:

set :domain, 'example.com'
set :repository,  "ssh://[email protected]/~/rails/chamonix-mont-blanc.net"

If I put the :domain and :repository in the main "deploy.rb" it all works fine and dandy.

like image 946
Jez Caudle Avatar asked Aug 17 '12 06:08

Jez Caudle


1 Answers

Move roles to your staging.rb file so that it looks like

set :domain, 'example.com'

role :web, domain
role :app, domain
role :db,  domain, :primary => true

set :repository,  "ssh://[email protected]/~/rails/chamonix-mont-blanc.net"

Remove roles code from deploy.rb. Also, you'll have to modify your production.rb similarly.

like image 124
Kulbir Saini Avatar answered Sep 25 '22 12:09

Kulbir Saini