0

我定义了一些特定于舞台的 capistrano 变量,但它们不会覆盖默认值。

配置/部署/staging.rb:

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

set :domain,      'test.etask.me'

配置/部署.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,  'git@bitbucket.org: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 git@bitbucket.org: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 git@bitbucket.org: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/ production /shared/cached-copy)。它使用默认值而不是在 deploy/staging.rb 中定义。即使我检查了用户变量的值 - 尽管我在 deploy/staging.rb 中设置了用户,但它会引发错误(未定义值)。

我已经完成了capistrano wiki中描述的所有事情。我浏览了大量其他相关帖子,但它们并没有解决我的问题。

4

2 回答 2

1

最后我介绍了一个 hack 让它工作。我已经换了

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 时能摆脱该代码

于 2013-10-15T15:07:00.763 回答
0

将其移至require 'capistrano/ext/multistage' deploy.rb 的底部:

并运行
cap staging deploy(不是cap deploy staging)尝试这种方式,它将使用暂存环境中的覆盖参数。

于 2013-10-15T13:04:20.540 回答