Rails deploy fails, as SSHKit command failed - ruby-on-rails

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.

Related

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.

Rails 6.0 w/Webpacker: Heroku Push Fail: error: RPC failed; curl 18 transfer closed with outstanding read data remaining

When pushing to Heroku, I'm encountering a timeout while compiling, as in the trace below:
...
remote: -----> Installing node-v10.14.1-linux-x64
remote: -----> Installing yarn-v1.12.3
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: yarn install v1.12.3
remote: [1/4] Resolving packages...
remote: [2/4] Fetching packages...
remote: info fsevents#1.2.9: The platform "linux" is incompatible with this module.
remote: info "fsevents#1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
remote: [3/4] Linking dependencies...
remote: warning "#rails/webpacker > pnp-webpack-plugin > ts-pnp#1.1.2" has unmet peer dependency "typescript#*".
remote: warning " > rails-erb-loader#5.5.2" has unmet peer dependency "webpack#^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
remote: warning " > webpack-dev-server#3.3.1" has unmet peer dependency "webpack#^4.0.0".
remote: warning "webpack-dev-server > webpack-dev-middleware#3.6.2" has unmet peer dependency "webpack#^4.0.0".
remote: [4/4] Building fresh packages...
remote: Done in 24.78s.
remote: Compiling…
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: el remoto se colgó de manera inesperada
fatal: el remoto se colgó de manera inesperada
I've tried several times with same result.
I haven't changed anything that to my mind mey be causing this issue.
The last commited changes were mainly in JS files, and as it hangs while compiling, I guess it has something to do with JS assets.
Thanks for any help you can give.
Well, after all I found the problem myself. It was an import of a file that had been removed. Webpacker wasn't throwing any errors, which had been hidding the issue.
Thanks!

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?

webpacker is not installed successfully on rails 4.2

Terminal: bash on Ubuntu on windows 10
Rails: 4.2.8
npm: 5.5.1
node: v8.9.1
yarn: 1.3.2
After rake webpacker:install, the console shows as follows. Although it shows "successfully installed" at the very end, some errors appear in the log. Is it normal?
create config/webpacker.yml
Copying webpack core config and loaders
create config/webpack
create config/webpack/development.js
create config/webpack/environment.js
create config/webpack/production.js
create config/webpack/test.js
Copying .postcssrc.yml to app root directory
create .postcssrc.yml
Copying .babelrc to app root directory
create .babelrc
Creating javascript app source directory
exist app/javascript
identical app/javascript/packs/application.js
Installing binstubs
run bundle binstubs webpacker from "."
append .gitignore
Installing all JavaScript dependencies
run yarn add #rails/webpacker coffeescript#1.12.7 from "."
yarn add v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "linux" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "#rails/webpacker > postcss-cssnext#3.0.2" has unmet peer dependency "caniuse-lite#^1.0.30000697".
error An unexpected error occurred: "EINVAL: invalid argument, lstat '/mnt/d/Github/cfegame/node_modules/babel-core/package-lock.json'".
info If you think this is a bug, please open a bug report with the information provided in "/mnt/d/Github/cfegame/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Installing dev server for live reloading
run yarn add --dev webpack-dev-server from "."
yarn add v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "linux" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "webpack-dev-server > webpack-dev-middleware#1.12.1" has unmet peer dependency "webpack#^1.0.0 || ^2.0.0 || ^3.0.0".
warning " > webpack-dev-server#2.9.4" has unmet peer dependency "webpack#^2.2.0 || ^3.0.0".
error An unexpected error occurred: "EINVAL: invalid argument, lstat '/mnt/d/Github/cfegame/node_modules/camelcase-keys/node_modules/camelcase/license'".
info If you think this is a bug, please open a bug report with the information provided in "/mnt/d/Github/cfegame/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Webpacker successfully installed 🎉 🍰
When I "successfully installed" webpacker and I want to check if webpack-dev-server worked properly, the console shows as follows. Did it mean I don't install webpacker properly?
(home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:47:in `exec': No such file or directory - (project_dir)/node_modules/.bin/webpack-dev-server (Errno::ENOENT)
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:47:in `block in execute_cmd'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:46:in `chdir'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:46:in `execute_cmd'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:11:in `run'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/runner.rb:6:in `run'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/exe/webpack-dev-server:8:in `<top (required)>'
from bin/webpack-dev-server:17:in `load'
from bin/webpack-dev-server:17:in `<main>'
basically yarn is managing your packages. He is trying to install the webpack-dev-server- with yarn add --dev webpack-dev-server from "." but it fails. This is the documentation about that yarn add command
npm is the alternative for using yarn for installing packages so in your server terminal run
npm install webpack-dev-server
and it should install the dependencies
When I "successfully installed" webpacker and I want to check if webpack-dev-server worked properly, the console shows as follows. Did it mean I don't install webpacker properly?
(home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:47:in `exec': No such file or directory - (project_dir)/node_modules/.bin/webpack-dev-server (Errno::ENOENT)
You either did not install it or your are searching the wrong path, maybe the gem is installed in .rvm/gems/ruby-2.3.3somethingelse
Some discussion you may want to read
https://github.com/Microsoft/WSL/issues/2448
https://github.com/yarnpkg/yarn/issues/4188

Rails 5.1 capistrano is stuck at webpacker compiling assets

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.

Resources