2013-10-15 58 views
0

我定義了一些階段特定的capistrano變量,但它們不覆蓋默認值。Capistrano階段值不會覆蓋默認值

配置/部署/ staging.rb:

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

set :domain,  'test.etask.me' 

配置/ 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 

帽部署輸出:

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" 

正如你可以看到Capistrano的認爲,它是生產環境(請看cd/home/ec2-user/etask/生產/shared/cached-copy)。它使用默認值而不是deploy/staging.rb中定義的值。即使我檢查用戶變量的值 - 它會引發錯誤(值未定義),儘管事實上我在deploy/staging.rb中設置了用戶。

我已經完成了capistrano wiki中描述的所有事情。我瀏覽了大量其他相關帖子,但他們沒有解決我的問題。

回答

0

移動這個require 'capistrano/ext/multistage'到deploy.rb的底部:

和運行
cap staging deploy(不cap deploy staging) 嘗試這樣,它會使用重寫PARAMS從登臺ENV。

+0

'cap deploy'將會導致'cap staging deploy',因爲登臺是默認階段。無論如何,這兩種方法都會產生與上圖相同的輸出。 – FUT

+0

嘗試編輯答案一次,看看是否有幫助。 –

+0

移動需要在底部,並檢查所有的'部署staging'和'分期deploy' - 相同的結果:( – FUT

0

最後我介紹了一個黑客使其工作。我已經取代

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

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

它也需要三根線,但它確實工作。我希望當我遷移到capistrano 3.x