【问题标题】:Capistrano stage values do not override defaultsCapistrano 阶段值不会覆盖默认值
【发布时间】:2013-10-23 07:02:21
【问题描述】:

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

config/deploy/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 中描述的所有事情。我浏览了大量其他相关帖子,但它们并没有解决我的问题。

【问题讨论】:

    标签: ruby-on-rails ruby deployment capistrano


    【解决方案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 时我会摆脱该代码

    【讨论】:

    • 我爱你.. 它有效。
    【解决方案2】:

    将此require 'capistrano/ext/multistage' 移动到 deploy.rb 的底部:

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

    【讨论】:

    • cap deploy 将导致 cap staging deploy 因为暂存是默认阶段。无论如何,这两种方法都会产生如上所示的相同输出。
    • 将 require 移到底部并检查了 deploy staging 和 staging deploy - 结果相同:(
    • 这很奇怪。我们以不同的方式使用它:deploy.rb(仅包含这两行):set :stages, %w(staging production)require 'capistrano/ext/multistage' 然后 staging.rb 和 production.rb 具有为环境定义的所有内容(虽然有些重复的代码但有效)跨度>
    • 我在另外两个项目中也有同样的事情。它在那里工作!但它在这里不起作用。太奇怪了。一整天都解决不了这个问题
    猜你喜欢
    • 1970-01-01
    • 2011-12-20
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    相关资源
    最近更新 更多