【问题标题】:Capistrano error when using git使用 git 时出现 Capistrano 错误
【发布时间】:2013-08-26 16:20:27
【问题描述】:

我正在尝试设置 capistrano 并想在服务器上测试之前在本地测试我的配置,但是当我运行 cap deploy -n 时,不断收到以下与 git 相关的错误

/Users/josh/.rvm/gems/ruby-1.9.3-p448@wgbh/gems/capistrano-2.15.5/lib/capistrano/recipes/deploy/scm/git.rb:234:in `block in query_revision': undefined method `sub' for nil:NilClass (NoMethodError)

并导致如下:

  * 2013-08-26 12:12:30 executing `deploy'
  * 2013-08-26 12:12:30 executing `deploy:update'
 ** transaction: start
  * 2013-08-26 12:12:30 executing `deploy:update_code'
  * executing locally: "git ls-remote git@github.com:GIT_REPO GIT_BRANCH"
*** [deploy:update_code] rolling back
  * executing "rm -rf /u/apps/APP_NAME/releases/20130826161230; true"

我试图追溯这件事,但我似乎无法弄清楚是什么原因造成的。我的 deploy.rb 如下所示:

require "bundler/capistrano" 

set :application, "APP_NAME"
set :deply_to, "/the/server/path"
set :user, "SERVER_USER"

set :repository,  "git@github.com:GIT_REPO_PATH"
set :scm, :git
set :scm_username , "GIT_USER_NAME"
#this allows you to choose a branch in the command line or default to master with 'cap -S branch=branchname deploy'
set :branch, fetch(:branch, "master")

#tells is to do resuse a single remote git clone
set :deploy_via, :remote_cache

server "THE_SERVER_NAME", :app, :web, :db, :primary => true

after 'deploy:update_code', 'deploy:migrate'

# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
 task :start do ; end
 task :stop do ; end
 task :restart, :roles => :app, :except => { :no_release => true } do
  run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
 end
end

有没有其他人遇到过这个错误?我找到了this post,但遵循一个建议根本不会改变错误。

【问题讨论】:

    标签: ruby-on-rails git deployment capistrano


    【解决方案1】:

    问题似乎是在试运行模式下,run_locally 函数返回一个数组,而不是预期的字符串。

    https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/recipes/deploy.rb#L133

    不确定 git 配方是否有一种简单的方法可以确定它处于空运行模式。如果你只是破解这样的东西:

    # in recipes/deploy/scm/git.rb ~line 229
    result = yield(command)
    return "666" if result.class == Array  # better would be: dry_run?
    

    然后 -n 调用继续。

    【讨论】:

    【解决方案2】:

    查看引用错误的来源:

          command = scm('ls-remote', repository, revision)
          result = yield(command)
          revdata = result.split(/[\t\n]/)
          newrev = nil
          revdata.each_slice(2) do |refs|
            rev, ref = *refs
            if ref.sub(/refs\/.*?\//, '').strip == revision.to_s # Explosion!
            ...
          end
    

    似乎没有为选定的分支或存储库加载修订数据(当调用sub 时,ref 为零)。尝试自己运行指定的命令 (git ls-remote git@github.com:GIT_REPO GIT_BRANCH),这有望生成更具体的错误消息,可能涉及分支或存储库本身。

    【讨论】:

    • 运行该命令返回 0a6f2b064a09ff2963e970440a81cef976f94c5a refs/heads/development 所以它似乎获得了正确的修订信息
    猜你喜欢
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    相关资源
    最近更新 更多