5
votes

I am deploying with Capistrano to my new VPS. After the first deploy(cap deploy) everything was OK (site was running), but the second deploy failed on assets:precompile error.

I am running rails 3.2.13, ruby 2.0.0, rvm.

error:

  * executing "cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile"
servers: ["IP"]
    [IP] executing command
*** [err :: IP] bash: line 1: 23406 Killed          RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
    command finished in 84187ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/rails/releases/20140116121250; true"
    servers: ["IP"]
    [IP] executing command
    command finished in 519ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile'" on IP

deploy.rb file:

set :application, "app_name"
set :repository,  "git_repository"

role :web, "IP"                 
role :app, "IP"                        
role :db,  "IP", :primary => true 

set :user, "rails"
set :password, "password"

set :use_sudo, false
set :deploy_to, "/home/rails/"
set :deploy_via, :copy

set :normalize_asset_timestamps, false

require 'bundler/capistrano'
require "rvm/capistrano"
set :rvm_type, :system

Capfile

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks

I am quite new to Capistrano, so please try to explain the solution clearly. Thank You for your support!

1
Can you run this command on the console rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile'Mindbreaker

1 Answers

3
votes

It seems as you have low operation memory size on your vpn server. (Vpn supplies without memory-swap for now) thus operation system kills your deploy process.
The solution is to compile assets locally (on your development machine)

Add deploy:assets:precompile task to your deploy.rb file (this is for Capistrano 2)

namespace :deploy do
  . . .
  namespace :assets do
      task :precompile, :roles => :web do
        from = source.next_revision(current_revision)
        if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
          run_locally("rake assets:clean && rake assets:precompile")
          run_locally "cd public && tar -jcf assets.tar.bz2 assets"
          top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
          run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
          run_locally "rm public/assets.tar.bz2"
          run_locally("rake assets:clean")
        else
          logger.info "Skipping asset precompilation because there were no asset changes"
        end
      end
    end
  end

Then just redeploy you app $ bundle exec cap deploy wish it helps