Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method `instance' for Capistrano::Configuration:Class

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.

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).

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:

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)

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'

deploy/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 }

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.

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

like image 811
dodgerogers747 Avatar asked Oct 14 '13 22:10

dodgerogers747


3 Answers

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

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

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.

Oh and if you don't wanna use bundler as of yet, remove the first line : require "bundler/capistrano". easy as that.

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

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

like image 185
Anidhya Ahuja Avatar answered Nov 12 '22 11:11

Anidhya Ahuja


I suspect this problem is because Bundler 1.3.5 is not compatible with the latest version of Capistrano. Try upgrading to the Bundler pre-releases: gem install bundler --pre.


I noticed also that you're using a very old version of Rails 3.2, which is probably vulnerable to some security exploits. I would really strongly recommend upgrading that version of Rails to something more recent, like Rails 3.2.14.

like image 3
Ryan Bigg Avatar answered Nov 12 '22 10:11

Ryan Bigg


For Capistrano 3, they recommend using http://github.com/capistrano/bundler

Its mentioned here https://github.com/bundler/bundler/blob/master/lib/bundler/capistrano.rb

like image 3
Pratik Khadloya Avatar answered Nov 12 '22 10:11

Pratik Khadloya