FUT
FUT

Reputation: 373

Capistrano stage values do not override defaults

I define some stage specific capistrano variables but they do not override default values.

config/deploy/staging.rb:

set :user, 'ec2-user'
set :rails_env, 'staging'

set :domain,      'test.etask.me'

config/deploy.rb:

set :application, 'etask'

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

set(:unicorn_env) { rails_env }

role(:web) { domain }
role(:app) { domain }
role(:db, :primary => true) { domain }

set(:deploy_to)    { "/home/#{user}/#{application}/#{fetch :rails_env}" }
set(:current_path) { File.join(deploy_to, current_dir) }

default_run_options[:pty] = false

require 'rvm/capistrano'
require 'bundler/capistrano'

set :using_rvm, true
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user

set :repository,  '[email protected]:adaptiveservices/etask-website.git'
set :scm,         :git
set :branch,      'master'
set :git_shallow_clone, 1
set :keep_releases, 3

set :use_sudo,    false
set :deploy_via,  :remote_cache

set :git_enable_submodules, 1

cap deploy output:

triggering load callbacks
  * 2013-10-15 15:44:25 executing `staging'
    triggering start callbacks for `deploy'
  * 2013-10-15 15:44:25 executing `multistage:ensure'
  * 2013-10-15 15:44:25 executing `deploy'
  * 2013-10-15 15:44:25 executing `deploy:update'
 ** transaction: start
  * 2013-10-15 15:44:25 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote [email protected]:adaptiveservices/etask-website.git master"
    command finished in 2270ms
  * executing "if [ -d /home/ec2-user/etask/production/shared/cached-copy ]; then cd /home/ec2-user/etask/production/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q
 --hard 88e8556a3cce96e77d51a40b96f2dcd1437c939a && git submodule -q init && git submodule -q sync && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git
 submodule -q update --init $GIT_RECURSIVE && git clean -q -d -x -f; else git clone -q -b master --depth 1 [email protected]:adaptiveservices/etask-website.git /home/ec2-user/etask/production/shared/cache
d-copy && cd /home/ec2-user/etask/production/shared/cached-copy && git checkout -q -b deploy 88e8556a3cce96e77d51a40b96f2dcd1437c939a && git submodule -q init && git submodule -q sync && export GIT_RECURS
IVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule -q update --init $GIT_RECURSIVE; fi"

As you can see capistrano thinks that it is production environment (look at the cd /home/ec2-user/etask/production/shared/cached-copy). It uses default values instead of defined in deploy/staging.rb. Even if I check what the value of user variable - it throws an error (value is not defined) in spite the fact that I set user inside deploy/staging.rb.

I have done all the things as described in capistrano wiki. I looked through tons of other related posts and they do not solve my issue.

Upvotes: 0

Views: 2367

Answers (2)

FUT
FUT

Reputation: 373

Finally I introduced a hack to make it work. I have replaced

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

with

set :stages, %w(production staging)
set :stage, ARGV.select { |arg| stages.include? arg }.first || 'staging'
load "config/deploy/#{stage}.rb"

It also takes three lines but it DOES work. I hope I will get rid of that code when migrating to capistrano 3.x

Upvotes: 1

Sahil Dhankhar
Sahil Dhankhar

Reputation: 3656

move this require 'capistrano/ext/multistage' to the bottom of deploy.rb:

and run
cap staging deploy(not cap deploy staging) Try that way it will use overridden params from staging env.

Upvotes: 0

Related Questions