I've setup my Linode VPS properly with nginx, passenger, ruby 1.9.3-p194, and rails 3.2.6. I've built a simple Cap recipe (see below) which passes deploy:setup and deploy:check but fails on the assets precompile phase. I would try to run the precompile by hand on the remote server but Cap rollsback so I can't do it.
The error looks like a PG error however I've tested a connection manually to the server based off my database.yml settings and it works perfect. Any idea what this could be?
deploy.rb
require "bundler/capistrano"
server "50.116.25.145", :web, :app, :db, primary: true
set :application, "exigencad"
set :user, "deploy"
set :deploy_to, "/home/#{user}/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#github.com:teknull/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
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 :after_update_code do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
after :deploy, "assets:precompile"
Error from Capistrano:
executing `deploy:assets:precompile'
* executing "cd /home/deploy/exigencad/releases/20120621170601 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["50.116.25.145"]
[50.116.25.145] executing command
** [out :: 50.116.25.145] rake aborted!
** [out :: 50.116.25.145] FATAL: Peer authentication failed for user "exigen"
** [out :: 50.116.25.145]
** [out :: 50.116.25.145] Tasks: TOP => environment
** [out :: 50.116.25.145]
** [out :: 50.116.25.145] (See full trace by running task with --trace)
command finished in 6433ms
*** [deploy:update_code] rolling back
might be totally unrelated to your problem, but since i just hit the same error while running cap deploy:migrate i'll mention it.
did you set host: localhost for your production db in database.yml?
adding that line fixed the problem for me.
Try add config.assets.initialize_on_precompile = false to your application.rb file,that help me.
Related
I am new to Capistrano and trying to precompile the assets. after entering command cap production deploy my code is successfully deployed on the server,but my assets are not compiled.below is my deploy.rb file.
#SSHKit.config.command_map[:rake] = "bundle exec rake"
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'woi'
set :repo_url, 'git#github.com:sanjay-salunkhe/cap.git'
set :branch, "master"
set :deploy_via, :remote_cache
set :stages, ["production"]
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/webuser/apps/cap/'
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
desc 'precompiling assets..............'
task :composer_install do
on roles(:web) do
within release_path do
execute :rake, "assets:precompile RAILS_ENV=production"
end
end
end
after :publishing, 'deploy:composer_install'
end
Below are my logs
DEBUG [cf204b99] /usr/bin/env:
DEBUG [cf204b99] rake
DEBUG [cf204b99] : No such file or directory
DEBUG [cf204b99]
cap aborted!
SSHKit::Command::Failed: rake stdout: Nothing written
rake stderr: Nothing written
/var/lib/gems/1.9.1/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='
/var/lib/gems/1.9.1/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _exe
also if possible then please send me the good documentation link for Capistrano 3.1.
Thanks,
You need to change directory and compile assets in one command.
I'm using this:
execute "cd #{release_path}/ && RAILS_ENV=production bundle exec rake assets:precompile"
Sometimes (it depends on server configuration) capistrano can raise an error that it can't find 'bundle', then You have to find where bundle is located on the server by using:
which bundleAnd add the full path to above line, in my configuration it was required to provide full path:
execute "cd #{release_path}/ && RAILS_ENV=production /usr/local/bin/bundle exec rake assets:precompile"
Finally i manged to deploy my app using capastrano 3.Actually i had not included below two lines in my capfile.
require 'capistrano/rvm'
require 'capistrano/rails'
After including these two lines my issue has been resolved.
I had to update node and install yarn on my server to get rake assets:precompile to work.
The frustrating part is that it was not producing any error or feedback. I only discovered this was the problem when I did rake assets:clobber
For Rails 4 and Capistrano 3, I find it unnecessary to write a Capistrano recipe to precompile assets for production.
Instead before I
cap production deploy
I just run
rake assets:precompile RAILS_ENV=production
from my local machine and then go on and deploy.
I've been trying to deploy to a VPS using Capistrano, and the following command is throwing me a lot of errors:
* executing "cd -- /home/work/for_linode/releases/20130317174830 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp -- /home/work/for_linode/shared/assets/manifest.yml /home/work/for_linode/releases/20130317174830/assets_manifest.yml"
Which results in the following:
servers: ["50.116.11.160"]
[50.116.11.160] executing command
*** [err :: 50.116.11.160] rake aborted!
*** [err :: 50.116.11.160] Could not find activesupport-3.2.11 in any of the sources
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/spec_set.rb:92:in `block in materialize'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/spec_set.rb:85:in `map!'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/spec_set.rb:85:in `materialize'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/definition.rb:114:in `specs'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/definition.rb:159:in `specs_for'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/definition.rb:148:in `requested_specs'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/environment.rb:18:in `requested_specs'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/runtime.rb:13:in `setup'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler.rb:120:in `setup'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/gems/bundler-1.3.4/lib/bundler/setup.rb:17:in `<top (required)>'
*** [err :: 50.116.11.160] /home/work/for_linode/releases/20130317174830/config/boot.rb:6:in `<top (required)>'
*** [err :: 50.116.11.160] /home/work/for_linode/releases/20130317174830/config/application.rb:1:in `<top (required)>'
*** [err :: 50.116.11.160] /home/work/for_linode/releases/20130317174830/Rakefile:5:in `<top (required)>'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
*** [err :: 50.116.11.160] /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'
*** [err :: 50.116.11.160] (See full trace by running task with --trace)
command finished in 1888ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/work/for_linode/releases/20130317174830; true"
servers: ["50.116.11.160"]
[50.116.11.160] executing command
command finished in 1591ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.3-p392' -c 'cd -- /home/work/for_linode/releases/20130317174830 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp -- /home/work/for_linode/shared/assets/manifest.yml /home/work/for_linode/releases/20130317174830/assets_manifest.yml'" on 50.116.11.160
I am by no means an expert using capistrano, and the similar questions around here, are related to a problem that's a bit different,
Could you guys please help figure out what's going on?
EDIT:
set :application, "for_linode"
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
set :bundle_without, [:development]
set :rvm_install_ruby_params, '--1.9.3-p194' # for jruby/rbx default to 1.9 mode
set :rvm_install_pkgs, %w[libyaml openssl] # package list from https://rvm.io/packages
set :rvm_install_ruby_params, '--with-opt-dir=/root/.rvm/usr' # package support
before 'deploy:setup', 'rvm:install_rvm' # install RVM
before 'deploy:setup', 'rvm:install_pkgs' # install RVM packages before Ruby
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, or:
before 'deploy:setup', 'rvm:create_gemset' # only create gemset
before 'deploy:setup', 'rvm:import_gemset' # import gemset from file
require "rvm/capistrano"
require "bundler/capistrano"
set :repository, "git://github.com/jlstr/for_linode.git"
# 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`
set :branch, "master"
set :scm, :git
set :user, "root"
set :scm_username, "joe"
set :use_sudo, true
set :deploy_to, '/home/work/for_linode'
#set :rvm_ruby_string, 'ruby-1.9.3-p392'
set :rvm_type, :system
role :web, "50.116.11.160" # Your HTTP server, Apache/etc
role :app, "50.116.11.160" # This may be the same as your `Web` server
#role :db, "", :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:
# 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
require "rvm/capistrano"
load 'deploy/assets'
use this piece of code for assets:
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
set :bundle_without, [:development]
require "rvm/capistrano"
require "bundler/capistrano"
load 'deploy/assets'
extracted from => https://github.com/mpapis/ad/blob/master/config/deploy.rb
I've been cap deploying my app all throughout it development, and this last time I tried to deploy it, it didn't work. Here's what happened:
* executing `deploy:assets:precompile'
* executing "cd /var/www/oneteam/releases/20121006153136 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["electricsasquatch.com"]
[electricsasquatch.com] executing command
** [out :: electricsasquatch.com] rake aborted!
** [out :: electricsasquatch.com] uninitialized constant OneTeam::Application::FactoryGirl
** [out :: electricsasquatch.com]
** [out :: electricsasquatch.com] (See full trace by running task with --trace)
It looks like it failed on the deploy:assets:precompile command. I don't get why that command would have tried to do anything with FactoryGirl, though. Any ideas?
It is not that something is wrong with deploy:assets:precompile task, but something is wrong with rake task that is using FactoryGirl. Even if you place a syntax error let us say in lib/tasks/first.rake and you execute task from lib/tasks/second.rake for instance rake second the rake will scream with rake aborted!. Even rake -T will not work. So there is rake task that is trying to use FactoryGirl but FactoryGirl is not included.
I had this in config/application.rb:
FactoryGirl.define do
sequence(:random_string) { |s| ('a'..'z').to_a.shuffle[0, 30].join }
end
I changed it to this:
if Rails.env != "production"
FactoryGirl.define do
sequence(:random_string) { |s| ('a'..'z').to_a.shuffle[0, 30].join }
end
end
The problem went away.
I am deploying rails project on heroku. When I use rake assets:precompile it gives following error -
rake aborted!
CScript Error: Execution of the Windows Script Host failed. (0x800A0007)
(in c:/Rails Projects/sheets_vip_rails/app/assets/javascripts/application.js)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [c:/Ruby193/bin/ruby.exe c:/Ruby193/bin/rak...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Thanks for any help.
I have a problem with Capistrano deploying to a server with RVM and gemsets
executing `deploy:assets:precompile'
* executing "cd /var/app/releases/20111229233555 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
*** [err ::] rake aborted!
*** [err ::] Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
*** [deploy:update_code] rolling back
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2#mygemset' -c 'cd /var/app/releases/20111229234715 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
This is my Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_bin_path, "$HOME/.rvm/bin"
set :rvm_ruby_string, '1.9.2#mygemset'
set :rvm_type, :user
load 'deploy/assets'
When I log in as the very same user which is used by Capistrano the failing command is executed without any problems.
It seems that Capistrano is using some other environment.
Here is my ~/.rvmrc file:
rvm_gemset_create_on_use_flag=1 rvm_trust_rvmrcs_flag=1
Is there a way how to check which ruby and gemset is used at the execution time?
node.js is and V8 are installed on the system, and all needed gems are in Gemfile:
here is my rvm info:
ruby:
interpreter: "ruby"
version: "1.9.2p290"
date: "2011-07-09"
platform: "x86_64-linux"
patchlevel: "2011-07-09 revision 32553"
full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]"
homes:
gem: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset"
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290"
binaries:
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
irb: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
gem: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
rake: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset/bin/rake"
setting up PATH in the deploy.rb solved this issue:
default_environment['PATH'] = "/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH"
it's a Gentoo distribution and the PATH var seems to be empty when using cap deploy, so I copied the content of server PATH and now it works
This issue went away for me when I installed nodejs (using apt-get) on my server. As I stated in this Stackoverflow answer, it's the most practical choice because you don't need to include any dependencies in your Gemfile.