Undefined method `namespace' in Capistrano ( Rails ) - ruby-on-rails

This is my first time to deploy a rails app in DigitalOcean, but I'm having a problem in deploying the application. When I tried to run the cap production deploy or bundle exec cap deploy:setup I got an error of :
/usr/local/rvm/gems/ruby-2.2.0/gems/capistrano-bundler-1.1.4/lib/capistrano/tasks/bundler.cap:1:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError)
this is my deploy.rb
set :application, "myapp.com"
set :repository, "git#heroku.com:myapp.git"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :user, 'user'
set :use_sudo, false
set :deploy_to, "/home/user/video-benta"
set :deploy_via, :remote_cache
role :web, "myapp.com" # Your HTTP server, Apache/etc
role :app, "myapp.com" # This may be the same as your `Web` server
role :db, "myapp", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && bundle install vendor/gems"
end
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
Capfile ( Update )
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
require 'capistrano/bundler'
require 'capistrano/rails'
# If you are using rvm add these lines:
require 'capistrano/rvm'
set :rvm_type, :user
set :rvm_ruby_version, '2.2.0p0'

You are trying to use different Capistrano extensions incompatible with your Capistrano version. Your Capistrano version is 2.x (detected by format of your Capfile), but capistrano/bundler for example is a extension for Capistrano 3.x.
Just use Capistrano 3 (if possible) and compatible extensions.

Related

Adding a rake action to a capistrano deployment

I have a rake task named : at_deployment:shops_assets_compile
Is it possible to call this task every time cap deploy is called? It needs to work for production and staging without adding new command line params to cap #{env} deploy.
EDIT : added the following to capistrano, but it does not seems to be executed :
task :special_assets,:roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake at_deployment:shops_assets_compile"
end
Ful deploy.rb :
####Added for multiple environnements
set :stages, %w(prodtest production)
set :default_stage, "prodtest"
require "capistrano/ext/multistage"
require "rvm/capistrano"
require "bundler/capistrano"
load "deploy/assets"
# require 'capistrano/rails'
set :repodomain,"***"
set :user,"***"
set :application, "***"
set :repository,"#{user}##{repodomain}:/srv/outils/repos/#{application}"
set :scm, 'git'
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
set :ssh_options, {:forward_agent => true}
set :use_sudo, false
default_run_options[:pty] = true
set :keep_releases, 5
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:key => "value",
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
task :special_assets,:roles => :app do
run "cd #{current_path}; RAILS_ENV= #{rails_env}bundle exec rake at_deployment:shops_assets_compile"
end
after "deploy:restart", "deploy:cleanup"

Capistrano deploy fails with "Cannot read username"

i wonder why my cap deployment fails.
I am using capistrano.
Here's my deploy.rb:
set :application, "gppb"
set :repository, "git#github.com:AppSource/gppb.git"
set :scm, :git
set :user, "gppb.com"
set :deploy_to, "/home/gppb.com/apps/#{application}"
set :use_sudo, false
set :keep_releases, 5
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "test.gppb.appsource.biz" # Your HTTP server, Apache/etc
role :app, "test.gppb.appsource.biz" # This may be the same as your `Web` server
role :db, "test.gppb.appsource.biz", :primary => true # This is where Rails migrations will run
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
And here is the error:
To see the full image click here-> http://d.pr/i/wnIb
Looks like you should set your :user to "gppbv2". That's the parameter for the remote user on the server. Also, Unix usernames can't have periods in them.

Deploying on a VPS using the Capistrano gem

I'm trying to deploy a Rails app on a VPS using the capistrano gem. I want to deploy it from my local machine to the VPS. I'm not using any repositories like Github or SVN.
So, I've installed the capistrano gem and ran 'bundle'. And added the following lines:
Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, 'ruby-1.9.3-p194#gemset'
deploy.rb
set :user, 'deploy'
set :application, "my_app"
set :scm, :none
set :deploy_via, :copy
set :deploy_to, "/home/#{user}/#{application}"
set :use_sudo, false
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
role :web, '1.2.3.4'
role :app, '1.2.3.4'
role :db, '1.2.3.4', :primary => true
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
However, after running 'cap deploy:setup' on local, I get the following error:
RVM - Capistrano integration was extracted to a separate gem, install: `gem install rvm-capistrano` and remove the `$LOAD_PATH.unshift` line, note also the 'set :rvm_type, :user' is now the default (instead of :system). (RuntimeError)
I'm not sure if I should use the rvm-capistrano gem. I'm a total newbie in deployments, detailed or step by step instructions would really help. Thanks.
Seems like you need to add
gem "rvm/capistrano"
to your Gemfile and then remove the unshift line (comment out)

rails / capistrano - error compiling assets

When I deploy with capistrano I get an error (and rollback) when capistrano attempts to run assets:precompile.
I'm using rails 3.2.1, bundler 1.0.22, capistrano 2.11.2
If I run rake assets:precompile from /webapps/myapp/current it runs successfully.
error:
failed: "sh -c 'cd /webapps/myapp/releases/20120304160347 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
deploy.rb
require "bundler/capistrano"
load 'deploy/assets'
set :application, "myapp"
set :domain, '24.17.71.95'
set :repository, "."
set :deploy_via, :copy
set :local_repository, '/home/me/myapp/.git'
set :deploy_to, '/webapps/myapp/'
set :scm, :none #:git
set :user, 'me'
set :password, 'me$pw'
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
default_run_options[:pty] = true
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
set :branch, 'master'
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
before "deploy:assets:precompile", "bundle:install"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
As far as I know, the asset precompiling task should be one of the last (or even the last one) tasks that are beeing executed.
So please try to move
load 'deploy/assets'
out of deploy.rb into Capfile (root folder of your Rails app) and paste it as the last line of the file.
See my answer to this Stackoverflow question.
If that fails, try the advice in http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/

Deploying with Capistrano... file not found (Asset pipeline)

When trying to deploy with Capistrano I am getting a ton of these errors:
[err :: localhost] tar: 20120220182722/app/assets/images/assets/Thumbs.db: Cannot open: No such file or directory
Every asset I have can't be found and capistrano errors out (doing a deploy:cold)
I've uncommented this line in the capfile:
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
but it still says the same thing.
The above line is actually in my Capfile here is the rest of my deploy.rb (note that I am using vagrant and trying to deploy to a VM created with vagrant)
require 'bundler/capistrano'
set :application, "testdeploy"
set :scm, :git
set :repository, "."
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
server "localhost", :app, :db, :primary => true
ssh_options[:port] = 2222
ssh_options[:keys] = "~/.rvm/gems/ruby-1.9.3-p125#testdeploy/gems/vagrant-0.9.4/keys/vagrant"
set :user, "vagrant"
set :group, "vagrant"
set :deploy_to, "/var/testdeploy"
set :use_sudo, true
set :deploy_via, :copy
set :copy_strategy, :export
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end

Resources