本文介绍了Capistrano部署 - 资产预编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Capistrano部署到我的新VPS。在第一次部署(上限部署)之后,一切都OK(站点正在运行),但第二次部署在资产上失败:预编译错误。



我正在运行rails 3.2.13 ,ruby 2.0.0,rvm。



错误:

  *执行cd  -  / home / rails / releases / 20140116121250&& RAILS_ENV = production RAILS_GROUPS = assets bundle exec rake assets:precompile
servers:[IP]
[IP]
*** [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]
*执行rm -rf / home / rails / releases / 20140116121250; true
服务器:[IP]
[IP]执行命令
完成519ms
失败:rvm_path = / usr / local / rvm / usr / local / rvm / bin / rvm-shell'默认'-c'cd - / home / rails / releases / 20140116121250& amp ; RAILS_ENV =生产RAILS_GROUPS =资产b onle exec rake assets:precompile'on IP

deploy.rb文件:

  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'
requirervm / capistrano
set:rvm_type,:system

Capfile

 加载'部署'
#如果您使用Rails的资产管道,则取消注释
加载'部署/资产'
加载' config / deploy'#删除此行以跳过加载任何默认任务

我很新Capistrano,所以请尽量解释解决方案。感谢您的支持!

解决方案

似乎您的vpn服务器上的操作内存不足。 ( Vpn 现在没有内存交换供应),因此操作系统会使您的部署过程失效。

解决方案是在本地(在开发机器上)编译资源



添加 deploy:assets:precompile 任务到您的 deploy.rb 文件(这是为Capistrano 2)

 code>命名空间:deploy do 
。 。 。
命名空间:assets do
任务:precompile,:roles => :web do
from = source.next_revision(current_revision)
如果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_locallycd public&&&tar-jcf assets.tar.bz2 assets
top。上传public / assets.tar.bz2,#{shared_pa​​th},:via => :scp
运行cd#{shared_pa​​th}&& rx assets.tar.bz2& rm assets.tar.bz2
run_locallyrm public / assets.tar.bz2
run_locally(rake assets:clean)
else
logger.info由于没有资产更改而跳过资产预编译
end
end
end
end

然后只需重新部署你的应用程序
$ bundle exec cap deploy
希望它有助于


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!

解决方案

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 deploywish it helps

这篇关于Capistrano部署 - 资产预编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:47