Max Kirsch
Max Kirsch

Reputation: 461

Rails 6 Capistrano Deployment Failure - Webpacker assets:precompile

currently I'm trying to bring my Rails 6 app to production on an Ubuntu Server, and for that, I'm using Capistrano. I spent one day to prepare the project and it works quite well, but I can't get around one error. I followed the instructions on webpacker to link the dependencies in the linked_dirs and running yarn install before the assets: precompile, that's when I get this error:

00:47 deploy:assets:precompile
      01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
      01 [Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
      01 I, [2019-10-10T11:01:27.724567 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/pdf-9124940acc21064e2797d4fc331490b7dd2616867e513e126f2a163025a71bc7.css
      01 I, [2019-10-10T11:01:27.725085 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/pdf-9124940acc21064e2797d4fc331490b7dd2616867e513e126f2a163025a71bc7.css.gz
      01 I, [2019-10-10T11:01:27.728319 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/MultiFactor-ec7b30855ff129ef43275ce9047d6b28196613335a7fde0aa2b9b937c7e7b0e6.png
      01 I, [2019-10-10T11:01:27.733297 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/logo-d3cf944e7b444e9265ffc5708b91386900a04c498681b2ee8b4537e92ce93757.jpg
      01 I, [2019-10-10T11:01:27.737513 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/top-1b883a805cfc1445462e1accd2d4f9db4062476e1d0ca24842f2691e8ca72231.png        
      01 I, [2019-10-10T11:01:28.315834 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/express/lib/application-9232ebdb20ad39572e70fb9e29810e63dbb63b58f5f18617c7c2bc8…
      01 I, [2019-10-10T11:01:28.316656 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/express/lib/application-9232ebdb20ad39572e70fb9e29810e63dbb63b58f5f18617c7c2bc8…
      01 Compiling…
      01 Compilation failed:
      01
#<Thread:0x00000000031d6db8@C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as [email protected]: rake exit status: 1 (SSHKit::Runner::ExecuteError)

In a StackOverflow thread, someone said it could because I'm using the 5$ DigitalOcean Server with just 1GB RAM? Could that be the issue? Cause webpacker seems to work!

Any suggestions?

Thanks!

Upvotes: 2

Views: 1794

Answers (1)

Max Kirsch
Max Kirsch

Reputation: 461

Okay after some looking into the documentation of webpacker I was able to fix the issue. For everyone who might run into that issue later, I'll try to explain what the problem was:

I run a server on DigitalOcean with just 1GB ram (the cheapest one for 5$) and the compiling for the webpacker stuff was just too much for the server. So I decided to do the compilation before uploading stuff to the server with this task I found:

# lib/capistrano/precompile.rake (create this file)

namespace :assets do
    desc 'Precompile assets locally and then rsync to web servers'
    task :precompile do
      run_locally do
        with rails_env: stage_of_env do
          execute :bundle, 'exec rake assets:precompile'
        end
      end

      on roles(:web), in: :parallel do |server|
        run_locally do
          execute :rsync,
            "-a --delete ./public/packs/ #{fetch(:user)}@#{server.hostname}:#{shared_path}/public/packs/"
          execute :rsync,
            "-a --delete ./public/assets/ #{fetch(:user)}@#{server.hostname}:#{shared_path}/public/assets/"
        end
      end

      run_locally do
        execute :rm, '-rf public/assets'
        execute :rm, '-rf public/packs'
      end
    end
  end

That fixed the issue in my case! I hope it will help someone in the future!

Upvotes: 4

Related Questions