Capistrano killing assets:precompile

前端 未结 1 1642
温柔的废话
温柔的废话 2021-02-01 08:27

I\'m trying to deploy my application and I keep getting

*** [err :: xxx.xxx.xx.xxx] bash: line 1:  9953 Killed                  bundle exec rake RAILS_ENV=produc         


        
1条回答
  •  野性不改
    2021-02-01 09:04

    So I think our problem was that bootstrap-sass was part of the asset precompilation. So it was blowing up all the css, and then compiling it all down. When this is combined with lots of sass/css, the process uses tons of memory, and the OS kills it. After much research, I came across a pretty decent solution. Compile locally, compress it, upload it, decompress it on the server, symlink it on the server, and then delete all the extra files that were created (local assets/compressed files).

    Here's the script

    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("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} 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
    
        task :symlink, roles: :web do
          run ("rm -rf #{latest_release}/public/assets &&
                mkdir -p #{latest_release}/public &&
                mkdir -p #{shared_path}/assets &&
                ln -s #{shared_path}/assets #{latest_release}/public/assets")
        end
      end
    
      # other stuff...
    
    end
    

    Here's where I found the script. It provides a better explanation

    Edit:

    There was an issue with newer rails deployments. I'm not sure the exact version, but it seemed to affect rails 4. The assets need to specify what environment they are being compiled for, otherwise the production/staging environments won't find them.

    0 讨论(0)
提交回复
热议问题