Capistrano::Configuration:Class 的未定义方法“实例" [英] Undefined method `instance' for Capistrano::Configuration:Class

查看:21
本文介绍了Capistrano::Configuration:Class 的未定义方法“实例"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Rails 应用程序中首次启动并运行 Capistrano.我有一个运行 Ubuntu 12.04、nginx、unicorn 和 rails 的 linux 服务器,但是,我似乎遇到了一些问题.我也在使用 Capistrano 3.0.0、rails 3.2.14、bundler 1.4.0 &使用 RVM 的 ruby​​ 1.9.3p448.

I am trying to get Capistrano up and running for the first time in a rails app. I have a linux server running Ubuntu 12.04, nginx, unicorn and rails, however, I seem to be running into a few issues. I am also using Capistrano 3.0.0, rails 3.2.14, bundler 1.4.0 & ruby 1.9.3p448 using RVM.

我现在只设置了一个生产阶段,我只关心 Capistrano 与我的服务器通信并从 github 推送我的代码(目前还没有迁移和捆绑等).

I only have a production stage set up and at this point in time and I'm only concerned with Capistrano communicating with my server and pushing my code from github ( No migrations and bundling etc just yet).

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

When I try the command cap production deploy:check or cap production deploy:setup ( which seems to be deprecated?) with the setup below, I get the following error msg:

我不确定从哪里开始处理这个错误,而且谷歌也没有给出太多建议.我尝试添加 rvm-capistrano gem 但无济于事.如何修改我的代码以解决此错误?

I'm not really sure where to start on this error, and google doesn't suggest much. I have tried adding the rvm-capistrano gem but to no avail. How can I amend my code to address this error?

    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)

部署.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'

部署/生产.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 中的违规行后,它提到将 require 'bundler/deployment' 添加到 deploy.rb,这似乎消除了 capistrano 实例错误.

EDIT After looking at the offending line in capistrano.rb within bundler it mentions to add require 'bundler/deployment' to deploy.rb, which has seemed to get rid of the capistrano instance error.

注意降级到 capistrano 2.15.5 消除了错误.

NOTE Downgraded to capistrano 2.15.5 which got rid of the errors.

推荐答案

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

First of all, there were a couple of changes made in capistrano 3. See the release notes : http://www.capistranorb.com/2013/06/01/release-announcement.html

同时阅读自述文件.https://github.com/capistrano/capistrano/blob/master/自述文件.md

Also go through the readme. https://github.com/capistrano/capistrano/blob/master/README.md

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

Capistrano 3 has moved out bundler integration into a gem.To solve your problem :

 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.

哦,如果你还不想使用 bundler,请删除第一行:require "bundler/capistrano".就这么简单.

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

Also you can't use variables like the previous way now.Instead of directly reading it, use fetch(:application) to read a variable.

我会更容易让你回到 capistrano v2.

I would be easier for you to move back to capistrano v2.

这篇关于Capistrano::Configuration:Class 的未定义方法“实例"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆