gpt4 book ai didi

ruby-on-rails - Capistrano::Configuration:Class 的未定义方法 `instance'

转载 作者:数据小太阳 更新时间:2023-10-29 06:38:51 25 4
gpt4 key购买 nike

我正在尝试在 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:checkcap production deploy:setup(这似乎已被弃用?)时,我得到以下信息错误信息:

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

    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,消除了错误。

最佳答案

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

同时阅读自述文件。<强> https://github.com/capistrano/capistrano/blob/master/README.md

Capistrano 3 已经将 bundler 集成到 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.

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

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

我会让你更容易回到 Capistrano v2。

关于ruby-on-rails - Capistrano::Configuration:Class 的未定义方法 `instance',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19370386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com