Capistrano Rails Asset Precompile Error - capistrano

I have a Capistrano script which is deploying my app to an Amazon EC2 machine. It is failing when compiling assets:
* executing "cd -- /home/ec2-user/uc_social_server/releases/20130731161645 && RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile"
servers: ["ec2-23-22-188-11.compute-1.amazonaws.com"]
[ec2-23-22-188-11.compute-1.amazonaws.com] executing command
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com] Could not find thread_safe-0.1.0 in any of the sources
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com]
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com] Run `bundle install` to install missing gems.
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com]
command finished in 591ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/ec2-user/uc_social_server/releases/20130731161645; true"
servers: ["ec2-23-22-188-11.compute-1.amazonaws.com"]
[ec2-23-22-188-11.compute-1.amazonaws.com] executing command
command finished in 201ms
failed: "sh -c 'cd -- /home/ec2-user/uc_social_server/releases/20130731161645 && RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile'" on ec2-23-22-188-11.compute-1.amazonaws.com

Adding following to deploy.rb
require "bundler/capistrano"
require "rvm/capistrano"
before "deploy:assets:precompile", "bundle:install"
and following to Capfile
load 'deploy/assets'
and following to Gemfile
gem 'rvm-capistrano'
resolved the issue for me. If you are not using rvm, maybe you will not need to require rvm/capistrano or the rvm-capistrano gem.

Add this line to your Capfile
require 'capistrano/bundler'

Related

Can’t cd to /var/www/discourse/current

I'm following instruction deploying-discourse-with-capistrano
When I'm doing cap deploy:setup I get:
executing "cd /var/www/discourse/current && bundle install"
...
** [out :: ...] sh: 1: cd: can't cd to /var/www/discourse/current
The command cap deploy:check says that everything is ok
What might be a problem here?
Try this.
cd /var/www/discourse
./discourse-setup
Reference article: https://www.digitalocean.com/community/tutorials/how-to-install-discourse-on-ubuntu-16-04

Capistrano RBENV path production error: failed: "env PATH=/home/user_with_rbenv/.rben

I have 2 SSH users. 1 which have rbenv installed.
I have watched the railscast about deploying to a VPS and some users have solved the problem with added the rbenv path.
set :default_environment, {
'PATH' => "/home/user_with_rbenv/.rbenv/shims:/home/user_with_rbenv/.rbenv/bin:$PATH"
}
I am deploying from the user that does not have .rbenv included in its /home/user folder.
I get the following error:
←[2;37mcommand finished in 117ms←[0m
failed: "env PATH=/home/user_with_rbenv/.rbenv/shims:/home/user_with_rbenv/.rbenv/bin:$PATH sh -
c 'cd -- /var/www/user_with_rbenv/releases/20130215102746 && bundle exec rake RAILS_ENV=
production RAILS_GROUPS=assets assets:precompile && cp -- /var/www/app/share
d/assets/manifest.yml /var/www/app/releases/20130215102746/assets_manifest.y
/home/user_with_rbenv/.rbenv is the absolute path to the rbenv
And path is:
$ $PATH
-sh: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: not found

Capistrano deploy:setup works but not deploy:check

Testing capistrano with a simple recipe.
$ cap deploy:setup
* executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /u/apps/ [..]
[..]
deploy:setup works as exprected.
However
$ cap deploy:check
* executing `deploy:check'
* executing "test -d /u/apps/[..]
[..]
When running deploy:check I get the following error:
The following dependencies failed. Please check them and try again:
--> You do not have permissions to write to `/u/apps/
[..]
--> `/u/apps/app/shared is not writable [..]
It seems that capistrano is not using sudo while in deploy:check mode.
I don't get it!
While in deploy:setup the whole directory structure was created by capistrano without any issue?
Why capistrano doesn't use sudo as in deploy:check?
I also ran into this issue and it turned out capistrano was creating all of the folders under the <user> group except for the shared folder. SSH onto your server and do a long listing ls -l. If you see - root - root - for the shared folder, you'll just need to update the permissions on the folder:
sudo chown <user> shared
sudo chgrp <user> shared
I ran into the same issue: the trick is to explicitly configure Capistrano not to use sudo.
You can turn that off in your deploy.rb file with:
set :use_sudo, false
If you need to use sudo, how about using the sudo DSL Action Invocation in your commands:
run "#{sudo} apachectl restart"

Problems Deploying to Linode with Capistrano

I`m looking for any guidance on deploying to Linode with Capistrano.
Everything seems fine until the point below:
[example.com :: out] Password: Password: ** [example.com :: out] ** [example.com :: out] HEAD is now at dc70d86 Fixed bugs from Webmaster Tools.
command finished in 9912ms
copying the cached version to /home/deploy/example.com/releases/20121024201633 * executing "cp
-RPp /home/deploy/example.com/shared/cached-copy /home/deploy/example.com/releases/20121024201633 && (echo dc70d867e1b01427a776ef23b59ddd375d39a34b > /home/deploy/example.com/releases/20121024201633/REVISION)"
servers: ["example.com"]
[example.com] executing command ** [out :: example.com] cp: cannot create directory `/home/deploy/example.com/releases/20121024201633' ** [out :: example.com] : No such file or directory
command finished in 661ms
*** [deploy:update_code] rolling back * executing "rm -rf /home/deploy/example.com/releases/20121024201633; true"
servers: ["example.com"]
[example.com] executing command
command finished in 623ms failed: "sh -c 'cp -RPp /home/deploy/example.com/shared/cached-copy /home/deploy/example.com/releases/20121024201633 && (echo dc70d867e1b01427a776ef23b59ddd375d39a34b > /home/deploy/example.com/releases/20121024201633/REVISION)'" on example.com
Any clues to why the directory doesn`t get created or what can I do to fix it?
All answers are appreciated.
It seems that some of the directories in this /home/deploy/example.com/releases/ path do not exist.
Try to run cap deploy:setup and to make sure also mkdir -p /home/deploy/example.com/releases on the servers shell.

Capistrano Deployment: a Task before `deploy:finalize_update` Is not Executed

I'm using Capistrano v2.13.4 for deployment.
A Capistrano task (deploy:special_treats) before deploy:finalize_update is not executed.
The task deploy:special_treats does some preparation (setup the internet access) for bundle:install, otherwise, bundle:install will not be able to reach the Internet ([out :: servername] Could not reach https://rubygems.org/
In config/deploy.rb
before 'deploy:finalize_update', 'deploy:special_treats'
and
namespace :deploy do
task :special_treats do
run "echo 'something special treats: setup the Internet access'"
end
end
The result for cap deploy:update
$ cap deploy:update
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "svn info https://svnlinks --username username --password password --no-auth-cache -rHEAD"
command finished in 10336ms
* getting (via export) revision 33268 to /tmp/20120927171608
executing locally: svn export -q --username username --password password --no-auth-cache -r33268 https://svnlinks /tmp/20120927171608
command finished in 79314ms
* processing exclusions...
* Compressing /tmp/20120927171608 to /tmp/20120927171608.tar.gz
executing locally: tar czf 20120927171608.tar.gz 20120927171608
command finished in 1401ms
servers: ["servername"]
** sftp upload /tmp/20120927171608.tar.gz -> /tmp/20120927171608.tar.gz
[servername] /tmp/20120927171608.tar.gz
[servername] done
* sftp upload complete
* executing "cd /usr/website/rr/releases && tar xzf /tmp/20120927171608.tar.gz && rm /tmp/20120927171608.tar.gz"
servers: ["servername"]
[servername] executing command
command finished in 774ms
* executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* executing `bundle:install'
* executing "cd /usr/website/rr/releases/20120927171608 && bundle install --gemfile /usr/website/rr/releases/20120927171608/Gemfile --path /usr/website/rr/shared/bundle --deployment --quiet --without development
test"
servers: ["servername"]
[servername] executing command
** [out :: servername] Could not reach https://rubygems.org/
command finished in 1403ms
*** [deploy:update_code] rolling back
* executing "rm -rf /usr/website/rr/releases/20120927171608; true"
servers: ["servername"]
[servername] executing command
command finished in 344ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3-p194' -c 'cd /usr/website/rr/releases/20120927171608 && bundle install --gemfile /usr/website/rr/releases/20120927171608/Gemfile --path
/usr/website/rr/shared/bundle --deployment --quiet --without development test'" on servername
I just had the same issue but in the after deploy:finalize_update trigger. The difference is that my script works in another machine for a long time.
I don't have capistrano locked as a gem in the Gemfile, so I tried reverting to the same version of the working machine which is 2.6.0 but that did not fix it.
After some research and several trials, I have found some issues at the github project like this that leads to that but looks like folks can't fully reproduce it.
I have then headed to the docs and browsing I found that Capistrano behaviors have been affected by recent changes on the 0.9.x versions of rake that have to do with namespace conflicts as you can see in this brief and tiny note that can be found at the deploy:create_symlink section of Capistrano Tasks wiki page
I did not have time to fix the script to work with latest versions of both rake and capistrano but I was able to have it back working on a different machine by reverting rake to version 0.8.7.
I hope this can get you going and provide some clues towards the solution.