我定义了一些阶段特定的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, '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 / 生产 / shared / cached-copy)。它使用默认值而不是deploy / staging.rb中定义的值。即使我检查了用户变量的值 - 尽管我在deploy / staging.rb中设置了用户,但它仍会抛出错误(未定义值)。
我完成了capistrano wiki中描述的所有事情。我查看了大量其他相关帖子,但他们没有解决我的问题。
答案 0 :(得分:0)
将此require 'capistrano/ext/multistage'
移至deploy.rb的底部:
并运行
cap staging deploy
(不是cap deploy staging
)
尝试这种方式它将使用来自staging env。
答案 1 :(得分: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
时我会删除该代码