Deploying with Capistrano... file not found (Asset pipeline) - ruby-on-rails

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

Related

Undefined method `namespace' in Capistrano ( 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.

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 rails app using Capistrano

I'm trying to deploy my rails app called Blog to my website through Capistrano. I have created a Rails App in cPanel at /rails_app/Blog/ and have deleted the skeleton code that was generated.
When i type this command in the terminal
cap deploy:setup
I get this error message
USER#USER-PC ~/documents/Aptana Studio 3 Workspace/Blog
$ cap deploy:setup
* executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /rails_app/Blog/ /rails_app/Bl
og/releases /rails_app/Blog/shared /rails_app/Blog/shared/system /rails_app/Blog
/shared/log /rails_app/Blog/shared/pids"
servers: ["mydomain.co.nz"]
connection failed for: mydomain.co.nz (Errno::ETIMEDOUT: A connection attempt fail
ed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond. -
connect(2))
Here is my deploy.rb file config settings
set :application, "mydomain.co.nz"
set :repository, "set your repository location here"
set :scm, :subversion
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
# These are not not part of the defaults
set :port, 12002
set :deploy_to, "/rails_app/Blog/"
#
role :web, application # Your HTTP server, Apache/etc
role :app, application # This may be the same as your `Web` server
role :db, application, :primary => true # This is where Rails migrations will run
role :db, application
try this, this is example of deploy.rb file that work for me
require "bundler/capistrano"
set :application, "testcapistrano"
set :rvm_ruby_string, "ruby-1.9.3-p194#testcapistrano"
require "rvm/capistrano"
set :rvm_type, :user
set :rvm_install_ruby, :install
set :repository, "xyz"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "testcapistrano.dipak.cs" # Your HTTP server, Apache/etc
role :app, "testcapistrano.dipak.cs" # This may be the same as your `Web` server
role :db, "testcapistrano.dipak.cs", :primary => true # This is where Rails migrations will run
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_to, "/dipak/capistron/"
set :deploy_via, :remote_cache
set :user, "your username"
set :password, "password"
set :use_sudo, false
set :keep_releases, 5
before 'deploy:setup', 'rvm:install_ruby'
# tasks
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
end

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/

Resources