我正在尝试在 Rails 应用程序中首次启动并运行 Capistrano。我有一个运行 Ubuntu 12.04、nginx、unicorn 和 rails 的 linux 服务器,但是,我似乎遇到了一些问题。我还使用 RVM 使用 Capistrano 3.0.0、rails 3.2.14、bundler 1.4.0 和 ruby 1.9.3p448。
我只设置了一个生产阶段,此时我只关心 Capistrano 与我的服务器通信并从 github 推送我的代码(还没有迁移和捆绑等)。
当我尝试使用以下设置的命令cap production deploy:check
或 cap 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)
部署.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
头文件
# 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 实例错误。
注意降级到 capistrano 2.15.5 消除了错误。