capistrano fails to deploy Sprockets::FileNotFound submodule file - ruby-on-rails

I've got a Rails 3.2 app with capistrano 2 installed and I have a number of submodules. I just moved vendor/assets/javascripts/ui-utils to a submodule.
[submodule "app/assets/javascripts/jquery.autotab"]
path = app/assets/javascripts/jquery.autotab
url = git#github.com:map7/jquery.autotab.git
[submodule "app/assets/javascripts/jquery.overdrive"]
path = app/assets/javascripts/jquery.overdrive
url = git#github.com:map7/jquery.overdrive.git
[submodule "app/assets/javascripts/jquery.validationEngine"]
path = app/assets/javascripts/jquery.validationEngine
url = https://github.com/posabsolute/jQuery-Validation-Engine.git
[submodule "app/assets/javascripts/keymaster"]
path = app/assets/javascripts/keymaster
url = git#github.com:map7/keymaster.git
[submodule "vendor/assets/javascripts/ui-utils"]
path = vendor/assets/javascripts/ui-utils
url = github.com:/map7/ui-utils.git
It's only the bottom submodule which I'm having trouble with. Could this be because it's in the vendor/assets area?
Now when I do a cap deploy I get the following error
* executing "cd -- /srv/pais/releases/20140630042430 && RAILS_ENV=production RAILS_GROUPS=assets env RBENV_ROOT=\"/usr/local/rbenv\" PATH=\"/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH\" RBENV_VERSION=\"2.1.1\" /usr/local/rbenv/bin/rbenv exec bundle exec rake assets:precompile"
** [out :: staging.pais.com.au] rake aborted!
** [out :: staging.pais.com.au] Sprockets::FileNotFound: couldn't find file 'ui-utils/modules/keypress/keypress.js'
** [out :: staging.pais.com.au] (in /srv/pais/releases/20140630042430/app/assets/javascripts/application.js:42)
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:102:in `resolve'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:142:in `require_asset'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:215:in `process_require_directive'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:165:in `block in process_directives'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:163:in `each'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:163:in `process_directives'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/directive_processor.rb:97:in `evaluate'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:12:in `initialize'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `new'
** [out :: staging.pais.com.au] /srv/pais/shared/bundle/ruby/2.1.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `block in build_asset'
On my development machine this file does exist and works.
I've tried putting the following into my deploy.rb with no luck
set :git_enable_submodules, 1 # Get submodules
set :git_submodules_recursive, true
namespace :git do
desc "Init & update submodules"
task :update_submodules, :roles => :app do
run("cd #{release_path} && git submodule init && git submodule update")
end
end
before "deploy:assets:precompile", "git:update_submodules"
Update 30/06/14
Noticed that if I go to any of the other submodules and type git status then I get the following;
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
nothing to commit, working directory clean
If I go to my ui-utils submodule and type git status I get
# HEAD detached at 4e86ac7
nothing to commit, working directory clean
I'm running git version 1.9.1, if I run the following
git submodule deinit -f vendor/assets/javascripts/ui-utils
Then try adding it again using
git submodule add git#github.com:map7/ui-utils.git vendor/assets/javascripts/ui-utils
I get the following error
A git directory for 'vendor/assets/javascripts/ui-utils' is found locally with remote(s):
origin https://github.com/map7/ui-utils.git
If you want to reuse this local git directory instead of cloning again from
git#github.com:map7/ui-utils.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.
Update
I managed to remove the vendor/assets/javascripts/ui-utils from git completely by following
How do I remove a submodule?
I've now added it again through submodule and now it's like the other submodules but I still get the deploy problem.
Update
If I use cap --debug deploy and stop it just before the error, then I ssh over to my server and do a git status I can see some problems with the submodule and capistrano on the server;
git status
# On branch deploy
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# deleted: log/searchd.test.pid
# modified: vendor/assets/javascripts/ui-utils (modified content)
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# REVISION
# app/assets/javascripts/jquery.autotab/
# log
no changes added to commit (use "git add" and/or "git commit -a")

I found the solution and might keep this here. It was multiple things
I had to completely remove my submodule and add it again correctly
Had to remove set :deploy_via, :remote_cache from my deploy.rb file
cap --debug deploy helped a lot here.

Related

application.css has already been required

Dont know what happened. i have deployed code to my server 3 times today and now i get this error.
* ←[33mexecuting "cd -- /home/deployer/loadmax/releases/20140404020322 && bund
le exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp --
/home/deployer/loadmax/shared/assets/manifest.yml /home/deployer/loadmax/releas
es/20140404020322/assets_manifest.yml"←[0m
servers: ["108.235.52.160"]
[108.235.52.160] executing command
** [out :: 108.235.52.160] rake aborted!
** [out :: 108.235.52.160] /home/deployer/loadmax/releases/20140404020322/app/a
ssets/stylesheets/application.css has already been required
** [out :: 108.235.52.160]
** [out :: 108.235.52.160] Tasks: TOP => assets:precompile:primary
** [out :: 108.235.52.160] (See full trace by running task with --trace)
←[2;37mcommand finished in 51582ms←[0m
*** [←[34mdeploy:update_code←[0m] ←[34mrolling back←[0m
* ←[33mexecuting "rm -rf /home/deployer/loadmax/releases/20140404020322; true"
←[0m
servers: ["108.235.52.160"]
[108.235.52.160] executing command
←[2;37mcommand finished in 838ms←[0m
failed: "sh -c 'cd -- /home/deployer/loadmax/releases/20140404020322 && bundle e
xec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp -- /ho
me/deployer/loadmax/shared/assets/manifest.yml /home/deployer/loadmax/releases/2
0140404020322/assets_manifest.yml'" on 108.235.52.160
Here is the line assets_manifest.yml file
---
application.css: application-cbe5df2fd54e4a120dc4a78c89b723d3.css
Apparently Ruby mines added in several files that it thought i was missing

rails capistrano having problems with rake db:migrate

I just ran rake db:migrate directly on my server with no problems:
$ pwd
/var/www/vhosts/example.com/current
$ rake db:migrate
Then i tried to run it via a capistrano task and i get an error. The task and output are below. Why does rake db:migrate not work via my capistrano task?
task
namespace :deploy do
# run the db migrations
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env}"
end
end
cap deploy:run_migrations
$ cap deploy:run_migrations
* executing `deploy:run_migrations'
RUNNING DB MIGRATIONS
* executing "cd /var/www/vhosts/example.com/current; rake db:migrate"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] (in /var/www/vhosts/example.com/releases/20121122011144)
** [out :: example.com] rake aborted!
** [out :: example.com] no such file to load -- rubygems
** [out :: example.com] /var/www/vhosts/example.com/releases/20121122011144/Rakefile:5:in `require'
** [out :: example.com] (See full trace by running task with --trace)
command finished in 390ms
failed: "sh -c 'cd /var/www/vhosts/example.com/current; rake db:migrate'" on example.com
EDIT
$ ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby
$ which rails
/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rails
EDIT
When i added --trace to the db migrations, it looks like it's using /usr/lib/ruby/site_ruby/1.8/rake.rb, but from the looks of this:
$ which rake
/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake
i would have expected it to use rake at /usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake rather than /usr/lib/ruby/site_ruby/1.8/rake.rb.
cap deploy's output from the deploy:run_migrations task
* executing `deploy:run_migrations'
RUNNING DB MIGRATIONS
* executing "cd /var/www/vhosts/example.com/current; rake db:migrate RAILS_ENV=production --trace"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] (in /var/www/vhosts/example.com/releases/20121123184358)
** [out :: example.com] rake aborted!
** [out :: example.com] no such file to load -- rubygems
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/boot.rb:1:in `require'
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/boot.rb:1
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/application.rb:1:in `require'
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/application.rb:1
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/Rakefile:5:in `require'
** [out :: example.com] /var/www/vhosts/famnfo.com/releases/20121123184358/Rakefile:5
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1828:in `load'
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1828:in `load_rakefile'
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1900:in `run'
** [out :: example.com] /usr/bin/rake:8
command finished in 422ms
failed: "sh -c 'cd /var/www/vhosts/example.com/current; rake db:migrate RAILS_ENV=production --trace'" on example.com
EDIT
output after adding #Super Engineers code
* executing `bundle:install'
* executing "ls -x /var/www/vhosts/example.com/releases"
servers: ["example.com"]
[example.com] executing command
command finished in 572ms
* executing "cd /var/www/vhosts/example.com/releases/20121124160218 && bundle install --gemfile /var/www/vhosts/example.com/releases/20121124160218/Gemfile --path /var/www/vhosts/example.com/shared/bundle --deployment --quiet --without development test"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] You are trying to install in deployment mode after changing
** [out :: example.com] your Gemfile. Run `bundle install` elsewhere and add the
** [out :: example.com] updated Gemfile.lock to version control.
** [out :: example.com]
** [out :: example.com] You have added to the Gemfile:
** [out :: example.com] * mysql2
** [out :: example.com] * therubyracer
** [out :: example.com] * rvm-capistrano
** [out :: example.com] * passenger
** [out :: example.com]
** [out :: example.com] You have deleted from the Gemfile:
** [out :: example.com] * mysql
command finished in 999ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/vhosts/example.com/releases/20121124160218; true"
servers: ["example.com"]
[example.com] executing command
command finished in 826ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.3-p125' -c 'cd /var/www/vhosts/example.com/releases/20121124160218 && bundle install --gemfile /var/www/vhosts/example.com/releases/20121124160218/Gemfile --path /var/www/vhosts/example.com/shared/bundle --deployment --quiet --without development test'" on example.com
EDIT
Entire deploy.rb file
require 'bundler/capistrano'
require 'rvm/capistrano'
# set environment
set :rails_env, "production"
# set the ruby version
set :rvm_ruby_string, 'ruby-1.9.3-p125'
set :rvm_type, 'webadmin'
# server username and password
set :user, 'super'
set :password, 'secret'
# subversion repo username and password
set :scm, :subversion
set :scm_username, "super"
set :scm_password, 'secret'
set :svnserver, "myreposerver"
set :repository, "myrepo"
# project info
set :server, ''
set :application, "FamNFo"
set :applicationdir, '/Volumes/Macintosh HD/Users/myname/Sites/example'
role :web, "example.com"
role :app, "example.com"
role :db, "example.com", :primary => true
set :use_sudo, true
# database config
#set :migrate_env, "#{rails_env}"
# specify the rvm type. We just want to use the system wide one since we're not currently specifying gemsets for each project
set :rvm_type, :system
# where to put the files
set :deploy_to, "/var/www/vhosts/example.com"
# fixes the "sorry, you must have a tty to run sudo" issue
default_run_options[:pty] = true
# precompiles the assets
load 'deploy/assets'
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
# restart the server
task :restart, :roles => :app do
run "/etc/init.d/http restart graceful"
end
# chmod the files
task :after_update_code, :roles => [:web, :db, :app] do
run "chmod 755 #{release_path}/public -R"
end
# install new gems
desc "run bundle install and ensure all gem requirements are met"
task :install do
run "cd #{current_path} && bundle install --without=test --no-update-sources --trace"
end
# run the db migrations
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env} --trace"
end
# precompile assets
task :precompile_assets do
run "cd #{release_path}; bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
end
task :start do ; end
task :stop do ; end
# restart the server
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{sudo} /etc/init.d/httpd restart graceful"
end
end
# hook to run db migrations after code update
after("deploy:update", "deploy:run_migrations")
#after("deploy:update", "deploy:precompile_assets")
after "deploy:update", "deploy:install"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup" # leave the last 5 releases only
Its because of ruby conflict. I've faced same error. You will need to use rvm/capistrano gem. I'll paste some code from my cap file which will give you some idea about how to set the ruby version while deploying.
install the gem
gem install rvm-capistrano
in you deploy.rb file add these lines
require 'bundler/capistrano'
require 'rvm/capistrano'
set :rvm_ruby_string, "ruby-1.9.3-p125"
set :rvm_type, 'webadmin'
For more information you can visit this link rvm/capistrano
The relevant error here seems to be no such file to load -- rubygems.
Quite likely it is because of multiple ruby installations on the production server.
Check out this previous solution for a similar problem : https://stackoverflow.com/a/2896596/429758
Also, this thread on the capistrano mailing list is helpful: https://groups.google.com/forum/?fromgroups=#!topic/capistrano/JzVPRbQclY4
Are you using rvm/capistrano? With that you can specify the ruby version that you want to use on the server in your capistrano recipes. I suspect that when you run capistrano it's not using your rvm setup, when you login and run the rake task, your user is setup to use the rvm ruby version.

Deploying Rails app with Capistrano

I just acquired a Media Temple (dv) 4.0 server to deploy a Rails app I created via a git repository. I'm new to Rails but Capistrano deployment seemed pretty straightforward. Nonetheless, I've been working all day on getting my first Rails project deployed. Here's the error I'm getting when I execute "cap production deploy -v" after setup and check:
** [out :: 64.207.184.51] rake aborted!
** [out :: 64.207.184.51] no such file to load -- rubygems
I have been installing gems all day on the server, so I don't think rubygems isn't installed. This is after hours of debugging why it was telling me my public key is invalid.
Here are my configuration files:
Capfile:
require 'capistrano/ext/multistage'
load 'deploy'
load 'deploy/assets'
load 'config/deploy'
set :application, 'snippet'
set :domain, '[server IP address]'
set :user, 'root'
config/deploy.rb
require 'capistrano/ext/multistage'
default_run_options[:pty] = true
set :stages, ["production"]
set :default_stage, "production"
set :application, "[app name]"
set :scm, :git
set :repository, "git#github.com:[github.com repository]"
set :branch, "master"
set :user, "root"
set :use_sudo, false
set :deploy_via, :remote_cache
set :scm_passphrase, "[public ssh key passphrase]"
config/deploy/production.rb
server "[server IP]", :app, :web, :db, :primary => true
set :deploy_to, "/var/www/vhosts/[domain]/httpdocs"
output of error:
vespertine:snippet nporteschaikin$ cap production deploy -v
** transaction: start
/Users/nporteschaikin/.rvm/gems/ruby-1.9.2-p320/gems/capistrano-2.13.4/lib/capistrano/recipes/deploy.rb:107: warning: Insecure world writable dir /Users/nporteschaikin/.rvm/gems/ruby-1.9.2-p320/bin in PATH, mode 040777
Password:
** [IP-ADDRESS :: out] Enter passphrase for key '/root/.ssh/id_rsa':
** [IP-ADDRESS :: out]
** [IP-ADDRESS :: out] Enter passphrase for key '/root/.ssh/id_rsa':
** [IP-ADDRESS :: out]
** [out :: IP-ADDRESS] (in /var/www/vhosts/[domain.com]/httpdocs/releases/20121021210706)
** [out :: IP-ADDRESS] rake aborted!
** [out :: IP-ADDRESS] no such file to load -- rubygems
** [out :: IP-ADDRESS] /var/www/vhosts/[domain.com]/httpdocs/releases/20121021210706/Rakefile:5:in `require'
** [out :: IP-ADDRESS] (See full trace by running task with --trace)
*** [deploy:update_code] rolling back
failed: "sh -c 'cd /var/www/vhosts/[domain.com]/httpdocs/releases/20121021210706 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on IP-ADDRESS
Please help! I installed RVM, Ruby, Passenger, and Rails on the server.

How do I fix a bad Capistrano deployment?

Made a large update last night and my site is currently down. I used cap deploy:rollback with no luck. The error logs aren't telling me much. The last error I saw when trying to deploy was:
** [out :: website.com] You are trying to install in deployment mode after changing
** [out :: website.com] your Gemfile. Run `bundle install` elsewhere and add the
** [out :: website.com] updated Gemfile.lock to version control.
** [out :: website.com]
** [out :: website.com] You have deleted from the Gemfile:
** [out :: website.com] * asset_sync
command finished in 934ms
My cap tail just says the following with no errors:
Migrating to AddSessionsTable (20120722094547)
Migrating to AddSlugToUserProjects (20120723204816)
Migrating to AddSlugIndexToUserProjects (20120723205558)
Migrating to CreateFriendlyIdSlugs (20120723210904)
Migrating to AddNameToUsers (20120723221700)
Migrating to AddSlugToUsers (20120723222456)
Migrating to CreateComments (20120724203252)
Any help?
Run bundle install on your development server, then cap deploy. Another possible solution: add asset_sync back to your Gemfile.
As last resort, you can run cap -d deploy. It will run deployment step-by-step, asking you for continue on each step. Login to production server in separate shell and do some adjustments between steps manually.
It looks like the Gemfile change didn't go well. How it was fixed:
logged into server, there were 6 ruby processes that were taking all available things. This is almost certainly the unicorn processes trying to start and couldn't… killall -9 ruby
cd into the app's current directory
RAILS_ENV=production bundle exec rake assets:precompile
service unicorn_whimseybox start
It looks like (in the unicorn.log), the error was:
E, [2012-07-26T17:27:10.552912 #24818] ERROR -- : uninitialized constant AssetSync (NameError)
I had the same error after converting some Gemfile source lines into blocks.
The error was due an old Bundler version on production (1.7.3) vs 1.8.3 on development.

Why am I getting Permission denied error in deployment on files generated by capistrano?

I was having a failed: "sh -c 'cd /var/www error. Then fixed it by adding the following in deploy.rb...
set :default_environment, {
'PATH' => "/var/lib/gems/1.9.1/bin:$PATH"
}
Now I'm getting this new error.
** [out :: ip.address] Rails Error: Unable to access log file. Please ensure that /var/www/releases/20111208152807/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
** [out :: ip.address]
** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
** [out :: ip.address]
** [out :: ip.address] rake aborted!
** [out :: ip.address]
** [out :: ip.address] Permission denied - /var/www/releases/20111208152807/public/assets/manifest.yml
So I checked the permissions on manifest.yml and production.log with ls -lha and yes, they're owned by root.
The capistrano deployment is being done by a linux user (not root) that owns the /var/www directory. I'm guessing it's because whatever command is creating those files is giving them root ownership.
CLARIFICATION:
I know that probably just deploying using root will fix the problem but I don't want to use root.
You should never have web application files owned by root, They should be owned by a non privileged user. While the user varies between web servers and how your web server is set up generally the user is www-data (for Apache) or nobody (for Nginx).
And to remove your error you want to run the command mentioned in the error:
chmod 0666 /var/www/releases/20111208152807/log/production.log will set the file to read write permissions for every user.
Those permissions may be a bit permissive so you can restrict them if you feel the need.

Resources