Capistrano :: Configuration:Class的未定义方法`instance'

时间:2013-10-14 22:34:41

标签: ruby-on-rails ruby ruby-on-rails-3 rubygems capistrano

我正试图让Capistrano第一次在rails应用程序中运行。我有一个运行Ubuntu 12.04,nginx,unicorn和rails的linux服务器,但是,我似乎遇到了一些问题。我也使用Capistrano 3.0.0,rails 3.2.14,bundler 1.4.0&使用RVM的ruby 1.9.3p448。

我只设置了一个制作阶段,此时我只关心Capistrano与我的服务器通信并从github推送我的代码(暂时没有迁移和捆绑等)。

当我使用下面的设置尝试命令cap production deploy:checkcap production deploy:setup(似乎已被弃用?)时,我收到以下错误消息:

我不确定从哪里开始这个错误,谷歌并没有多少建议。我尝试添加rvm-capistrano宝石,但无济于事。如何修改我的代码以解决此错误?

    cap aborted!
undefined method `instance' for Capistrano::Configuration:Class
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.4.0.rc.1/lib/bundler/capistrano.rb:11:in `<top (required)>'
config/deploy.rb:1:in `<top (required)>'
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.0/lib/capistrano/setup.rb:12:in `load'
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.0/lib/capistrano/setup.rb:12:in `block (2 levels) in <top (required)>'
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.0/lib/capistrano/application.rb:12:in `run'
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.0/bin/cap:3:in `<top (required)>'
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/bin/cap:23:in `load'
/Users/andrew/.rvm/gems/ruby-1.9.3-p448/bin/cap:23:in `<main>'
Tasks: TOP => production
(See full trace by running task with --trace)

deploy.rb

require "bundler/capistrano"

set :stages, %w(staging production)
set :default_stage, "production"

set :application, "my_app"
set :user, "andrew"
set :scm, "git"
set :repository, "https://github.com/my_repo/#{application}"
set :branch, "master"

set :deploy_to, "/home/rails/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  task :restart, roles: :app do
      run "touch #{current_path}tmp/restart.txt"
    end
  end
  after :finishing, 'deploy:cleanup'

部署/ production.rb

#Real IP ommitted 
server "10.2.32.68", :web, :app, :db, primary: true

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

编辑在Bundler中查看capistrano.rb中有问题的行之后,它提到要向deploy.rb添加require'bundler / deployment',这似乎已经摆脱了capistrano实例错误。

注意降级为capistrano 2.15.5,摆脱了错误。

3 个答案:

答案 0 :(得分:21)

首先,在capistrano 3中进行了一些更改。 请参阅发行说明: http://www.capistranorb.com/2013/06/01/release-announcement.html

另请阅读自述文件。 的 https://github.com/capistrano/capistrano/blob/master/README.md

Capistrano 3已将捆绑器集成移植到gem中。要解决您的问题:

 1. Uncomment require 'capistrano/bundler' from capify. 
 2. add gem 'capistrano-bundler' to your gemfile.
 3. Go through the comments in capify file and uncomment whichever module you require.

哦,如果您还不想使用捆绑包,请删除第一行:require“bundler / capistrano”。这很简单。

此外,你现在不能像以前那样使用变量。而不是直接读取它,使用fetch(:application)来读取变量。

我会更容易回到capistrano v2。

答案 1 :(得分:3)

我怀疑这个问题是因为Bundler 1.3.5与最新版本的Capistrano不兼容。尝试升级到Bundler预发行版:gem install bundler --pre


我还注意到你正在使用一个非常旧版本的Rails 3.2,它可能容易受到一些安全漏洞的攻击。我强烈建议将该版本的Rails升级到更新的版本,例如Rails 3.2.14。

答案 2 :(得分:3)

对于Capistrano 3,他们建议使用http://github.com/capistrano/bundler

这里提到https://github.com/bundler/bundler/blob/master/lib/bundler/capistrano.rb