Rails 5.1 capistrano is stuck at webpacker compiling assets - ruby-on-rails

I'm trying to deploy a rails 5.1 app with capistrano and it seems to be stuck at compiling assets:
02:38 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 yarn install v0.27.5
01 [1/4] Resolving packages...
01 [2/4] Fetching packages...
01 warning fsevents#1.1.1: The platform "linux" is incompatible with this module.
01 info "fsevents#1.1.1" is an optional dependency and failed compatibility check. Excluding it from installation.
01 [3/4] Linking dependencies...
01 [4/4] Building fresh packages...
01 Done in 48.92s.
01 Webpacker is installed πŸŽ‰ 🍰
01 Using /project_name/releases/20170807195158/config/webpack/paths.yml file for setting up webpack paths
01 Compiling webpacker assets πŸŽ‰
There are no errors, it just stays there for hours. If i inspect the node process doing this on the remote server it says that it uses 100% of the cpu for about 5 minutes and then the process seems to get killed but it still says "Compiling assets".

It seems that executing bundle exec rake assets:precompile on remote when there are more than a few assets fails.
The solution was to compile the assets locally and then rsync them to the remote server.

Related

Rails deploy fails, as SSHKit command failed

The latest in rails 6 deployment problems when compiling javascript assets. The error points to
1: from /Users/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in
'rescue in block (2 levels) in execute': Exception while executing as deploy#16.17.18.2: rake exit status: 1
(SSHKit::Runner::ExecuteError)
[...]
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: yarn install v1.22.17
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 25.51s.
Compiling...
Compilation failed:
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy#16.17.18.2: rake exit status: 1
rake stdout: yarn install v1.22.17
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 25.51s.
Compiling...
Compilation failed:
rake stderr: Nothing written
I have no clue what is going on here. How should this be addressed?
If asset precompilation is working on the remote server directly then it’s time to look at what conditions SSHKit sets up when capistrano connects to the server:
Is there a timeout on the ssh connection?
What environment variables are set when you SSH directly vs in the SSHKit session?
There is a Capistrano β€”-trace option that can help you reveal more info.

Ruby on Rails project not compilation assets without show errors, Heroku

Preparing app for Rails asset pipeline
Running: rake assets:precompile
yarn install v1.22.17
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
warning " > react-dom#17.0.2" has incorrect peer dependency "react#17.0.2".
[5/5] Building fresh packages...
Done in 27.74s.
Compiling...
Compilation failed:
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app.
! Push failed
On local machine RAILS_ENV=production rails assets:precompile compile without errors.

How to deploy an app with my fork of a package via Yarn and Capistrano?

I'm using Capistrano to deploy my Rails app.
assets:precompile fails because of using an old code. Why doesn't it use freshly installed yarn package?
I have forked #fancyapps/fancybox repo to solve this issue.
Touched one file.
Ran gulp task.
Pushed to my fork to the new branch called unquote-max-css-function
Now it's time to use it in my project.
Ran yarn upgrade git+ssh://git#github.com:light-flight/fancybox.git#unquote-max-css-function
Locally it works - all code bundles successfully. But in production it's using old assets during assets:precompile (see logs below).
I am sure Yarn bundled my repo because it had asked access rights before.
production error:
...
00:24 yarn:install
01 yarn install --production
01 yarn install v1.12.3
01 [1/4] Resolving packages...
01 [2/4] Fetching packages...
01 warning Pattern ["animate.css#latest"] is trying to unpack in the same destination "/home/deploy/.cache/yarn/v4/npm-animate-css-3.7.0-5de25d…
01 info fsevents#1.2.9: The platform "linux" is incompatible with this module.
01 info "fsevents#1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
01 [3/4] Linking dependencies...
01 warning "#rails/webpacker > pnp-webpack-plugin > ts-pnp#1.1.2" has unmet peer dependency "typescript#*".
01 warning " > webpack-dev-server#3.3.1" has unmet peer dependency "webpack#^4.0.0".
01 warning "webpack-dev-server > webpack-dev-middleware#3.6.2" has unmet peer dependency "webpack#^4.0.0".
01 [4/4] Building fresh packages...
01 Done in 15.13s.
00:41 deploy:assets:precompile
01 ~/.rvm/bin/rvm default do bundle exec rake assets:precompile
01 yarn install v1.12.3
01 [1/4] Resolving packages...
01 success Already up-to-date.
01 Done in 1.30s.
01 rake aborted!
01 SassC::SyntaxError: Error: "env(safe-area-inset-right)" is not a number for `max'
01 on line 11366 of stdin, in function `max`
01 from line 11366 of stdin
01 >> padding: 75px max(44px, env(safe-area-inset-right)) max(25px, env(safe-a
01 ------------------^
01 stdin:11366
01 /home/deploy/apps/app/shared/bundle/ruby/2.6.0/gems/sassc-2.0.1/lib/sassc/engine.rb:49:in `render'
01 /home/deploy/apps/app/shared/bundle/ruby/2.6.0/gems/sassc-rails-2.1.1/lib/sassc/rails/compressor.rb:29:in `call'
01 /home/deploy/apps/app/shared/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/sass_compressor.rb:28:in `call'
...
As you can see it tries to compile old code with unquoted max function.
Locally it compiles successfully:
$ rails assets:precompile
yarn install v1.15.2
[1/4] Resolving packages...
success Already up-to-date.
Done in 1.42s.
I, [2019-05-05T13:02:34.620408 #10872] INFO -- : Writing /home/user/apps/app/public/assets/application-6f331dc14f50de04a8e7dd5d4c4882ffbf78cefc5ac4d73294ea48912d74a2a5.css
I, [2019-05-05T13:02:34.620871 #10872] INFO -- : Writing /home/user/apps/app/public/assets/application-6f331dc14f50de04a8e7dd5d4c4882ffbf78cefc5ac4d73294ea48912d74a2a5.css.gz
I've tried to yarn cache clean but nothing changed. How to force rails to use my fork?

Rails 5 production assets precompile error

I'm working on Ubuntu 16.04 LTS server for deploying multiple RoR apps.
I'm using an Amazon EC2 machine with a Nginx webserver managing multiple RoR app on different domains. Some products are in development environment for testing and others in production environment.
I decided to update a site installing a HTTP certificate with certbot.
I followed the instructions below and everything was fine.
https://certbot.eff.org/#ubuntuxenial-nginx
After updating the production assets with:
`RAILS_ENV=production rake assets:precompile`
I have the following message instead of the list of assets files generated
Installing certbot I broke some dependencies for assets compiling flow?
`Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install`
I tried to install yarn with npm globally but after I have:
`yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Lockfile not saved, no dependencies.
Done in 0.09s.`
As i see, Yarn is a package. Please install that package via npm (on your production server):
npm install yarn -g
Hope this helps.

Rails Webpacker seem to take eternity to compile

Using Capistrano, I notice when there's a symlink created with current -> /var/www/myapp, it takes an eternity to compile. In fact, I waited for ~5 to 10 mins and canceled the process.
It hangs at this part:
00:09 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 yarn install v0.27.5
01 [1/4] Resolving packages...
01 [2/4] Fetching packages...
01 warning fsevents#1.1.2: The platform "linux" is incompatible with this module.
01 info "fsevents#1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
01 [3/4] Linking dependencies...
01 [4/4] Building fresh packages...
If I remove the current symlink, it still takes a while, but it finishes.
00:09 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 yarn install v0.27.5
01 [1/4] Resolving packages...
01 [2/4] Fetching packages...
01 warning fsevents#1.1.2: The platform "linux" is incompatible with this module.
01 info "fsevents#1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
01 [3/4] Linking dependencies...
01 [4/4] Building fresh packages...
01 Done in 134.00s.
01 Webpacker is installed πŸŽ‰ 🍰
01 Using /var/www/html/myapp/releases/20170713104316/config/webpacker.yml file for setting up webpack paths
01 [Webpacker] Compiling assets πŸŽ‰
01 [Webpacker] Compiled digests for all packs in /var/www/html/myapp/releases/20170713104316/app/javascript/packs:
01 {"application.css"=>"/packs/application.css", "application.css.map"=>"/packs/application.css.map", "application.js"=>"/packs/application-54a7cd537f4d8d13646…
Took about 134s.
First time using Capistrano and webpacker for deployment, is it normal or is there a solution to reduce the compilation time?

Resources