title: Capistrano deploy to staging and production
body: <p>I am trying to deploy a Ruby On Rails app to both staging and then production using Capistrano.</p>
  
  <p>The only difference between the two is the :domain and the :repository</p>
  
  <p>I have followed this guide here: <a href="https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension" rel="nofollow noreferrer">https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension</a></p>
  
  <p>I have searched around the net and all I find are articles that basically rehash what I have above.</p>
  
  <p>I have tried just setting the :domain and :repository in the config/deploy/staging.rb and config/deploy/production.rb</p>
  
  <p>I have checked my spellings to make sure I spelt the sub-dirs correctly and the names of the files.</p>
  
  <p>Reading this article: <a href="https://stackoverflow.com/questions/10679455/staging-and-live-app-with-capistrano">staging and live app with capistrano</a> it looks like I should just be able to declare the differences here.</p>
  
  <p>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.</p>
  
  <p>If I put a single swear word on the first line of "staging.rb" or "production.rb" I get the same error:</p>
  
  <pre><code>`method_missing': undefined local variable or method `domain'
  </code></pre>
  
  <p>The line in question is:</p>
  
  <pre><code>role :web, domain
  </code></pre>
  
  <p>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?</p>
  
  <p>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.</p>
  
  <p>Any help would be much appreciated or do you think I should just take the pizza delivery job ...</p>
  
  <p>deploy.rb:</p>
  
  <pre><code>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 =&gt; 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 =&gt; 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 =&gt; :app, :except =&gt; { :no_release =&gt; true } do
        run " touch #{File.join(current_path,'tmp','restart.txt')}"
     end
  end
  </code></pre>
  
  <p>And my config/deploy/staging.rb file:</p>
  
  <pre><code>set :domain, 'example.com'
  set :repository,  "ssh://dave@example.com/~/rails/chamonix-mont-blanc.net"
  </code></pre>
  
  <p>If I put the :domain and :repository in the main "deploy.rb" it all works fine and dandy.</p>