Rails Webpacker seem to take eternity to compile - ruby-on-rails

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?

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.

Bundler Error when attempting Capistrano Deployment

I am attempting to deploy a ruby on rails web app to a staging server but continue to get the error: bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
I have attempted to install bundler on the server directly, and even after doing so it continues to fail with the same error. Full error log and deploy.rb below.
Full Log:
% cap staging deploy
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning, add the following to
your Capfile after `require "capistrano/deploy"`:
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
deploy#00.000.000.000's password:
rvm 1.29.10 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
ruby-2.7.0
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
00:00 git:wrapper
01 mkdir -p /home/deploy/tmp
βœ” 01 deploy#00.000.000.000 0.313s
Uploading /home/deploy/tmp/git-ssh-Myapp-staging-marcuselmer.sh 100.0%
02 chmod 700 /home/deploy/tmp/git-ssh-Myapp-staging-marcuselmer.sh
βœ” 02 deploy#00.000.000.000 0.276s
00:01 git:check
01 git ls-remote git#bitbucket.org:.../myApp.git HEAD
01 123abad2c0a3f9fa670259253608e11086661c6b HEAD
βœ” 01 deploy#00.000.000.000 1.653s
00:02 deploy:check:directories
01 mkdir -p /home/deploy/apps/MYAPP/shared /home/deploy/apps/MYAPP/releases
βœ” 01 deploy#00.000.000.000 0.278s
00:03 deploy:check:linked_dirs
01 mkdir -p /home/deploy/apps/MYAPP/shared/log /home/deploy/apps/MYAPP/shared/tmp/pids /home/deploy/apps/MYAPP/shared/tmp/cache /home/deploy/app…
βœ” 01 deploy#00.000.000.000 0.319s
00:03 deploy:check:make_linked_dirs
01 mkdir -p /home/deploy/apps/MYAPP/shared/config
βœ” 01 deploy#00.000.000.000 0.274s
00:04 git:clone
The repository mirror is at /home/deploy/apps/MYAPP/repo
00:05 git:update
01 git remote set-url origin git#bitbucket.org:.../myApp.git
βœ” 01 deploy#00.000.000.000 0.314s
02 git remote update --prune
02 Fetching origin
02 From bitbucket.org:.../myApp
02 01e45c6b..123abad2 master -> master
βœ” 02 deploy#00.000.000.000 1.901s
00:07 git:create_release
01 mkdir -p /home/deploy/apps/MYAPP/releases/20201230174246
βœ” 01 deploy#00.000.000.000 0.312s
02 git archive master | /usr/bin/env tar -x -f - -C /home/deploy/apps/MYAPP/releases/20201230174246
βœ” 02 deploy#00.000.000.000 0.924s
00:09 deploy:set_current_revision
01 echo "123abad2c0a3f9fa670259253608e11086661c6b" >> REVISION
βœ” 01 deploy#00.000.000.000 0.269s
00:09 deploy:symlink:linked_files
01 mkdir -p /home/deploy/apps/MYAPP/releases/20201230174246/config
βœ” 01 deploy#00.000.000.000 0.317s
02 ln -s /home/deploy/apps/MYAPP/shared/config/secrets.yml /home/deploy/apps/MYAPP/releases/20201230174246/config/secrets.yml
βœ” 02 deploy#00.000.000.000 0.277s
00:11 deploy:symlink:linked_dirs
01 mkdir -p /home/deploy/apps/MYAPP/releases/20201230174246 /home/deploy/apps/MYAPP/releases/20201230174246/tmp /home/deploy/apps/MYAPP/releases…
βœ” 01 deploy#00.000.000.000 0.307s
02 rm -rf /home/deploy/apps/MYAPP/releases/20201230174246/log
βœ” 02 deploy#00.000.000.000 0.269s
03 ln -s /home/deploy/apps/MYAPP/shared/log /home/deploy/apps/MYAPP/releases/20201230174246/log
βœ” 03 deploy#00.000.000.000 0.335s
04 ln -s /home/deploy/apps/MYAPP/shared/tmp/pids /home/deploy/apps/MYAPP/releases/20201230174246/tmp/pids
βœ” 04 deploy#00.000.000.000 0.272s
05 rm -rf /home/deploy/apps/MYAPP/releases/20201230174246/tmp/cache
βœ” 05 deploy#00.000.000.000 0.318s
06 ln -s /home/deploy/apps/MYAPP/shared/tmp/cache /home/deploy/apps/MYAPP/releases/20201230174246/tmp/cache
βœ” 06 deploy#00.000.000.000 0.283s
07 ln -s /home/deploy/apps/MYAPP/shared/tmp/sockets /home/deploy/apps/MYAPP/releases/20201230174246/tmp/sockets
βœ” 07 deploy#00.000.000.000 0.308s
08 ln -s /home/deploy/apps/MYAPP/shared/vendor/bundle /home/deploy/apps/MYAPP/releases/20201230174246/vendor/bundle
βœ” 08 deploy#00.000.000.000 0.277s
09 ln -s /home/deploy/apps/MYAPP/shared/public/system /home/deploy/apps/MYAPP/releases/20201230174246/public/system
βœ” 09 deploy#00.000.000.000 0.314s
10 ln -s /home/deploy/apps/MYAPP/shared/public/assets /home/deploy/apps/MYAPP/releases/20201230174246/public/assets
βœ” 10 deploy#00.000.000.000 0.268s
00:19 bundler:install
01 ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/MYAPP/shared/bundle --without development test --deployment --quiet
01 /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by y…
01 To update to the latest version installed on your system, run `bundle update --bundler`.
01 To install the missing version, run `gem install bundler:1.16.1`
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy#00.000.000.000: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Caused by:
SSHKit::Command::Failed: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy#00.000.000.000: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [9486807a] Finished in 0.308 seconds with exit status 0 (successful).
DEBUG [5d323bc9] Running ~/.rvm/bin/rvm default do bundle check --path /home/deploy/apps/MYAPP/shared/bundle as deploy#00.000.000.000
DEBUG [5d323bc9] Command: cd /home/deploy/apps/MYAPP/releases/20201230174246 && ~/.rvm/bin/rvm default do bundle check --path /home/deploy/apps/MYAPP/shared/bundle
DEBUG [5d323bc9] /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
DEBUG [5d323bc9] Finished in 0.648 seconds with exit status 1 (failed).
INFO [38f3d295] Running ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/MYAPP/shared/bundle --without development test --deployment --quiet as deploy#00.000.000.000
DEBUG [38f3d295] Command: cd /home/deploy/apps/MYAPP/releases/20201230174246 && ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/MYAPP/shared/bundle --without development test --deployment --quiet
DEBUG [38f3d295] /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Deploy.rb
# config valid only for current version of Capistrano
lock "3.10.1"
set :application, "Myapp"
set :repo_url, 'git#bitbucket.org:…/myApp.git'
set :deploy_to, '/home/deploy/apps/myApp
set :linked_files, %w{config/secrets.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :tmp_dir, "/home/deploy/tmp"
set :branch, ENV['BRANCH'] if ENV['BRANCH']
set :user, "deploy"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, "/var/www/my_app_name"
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# append :linked_files, "config/database.yml", "config/secrets.yml"
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
namespace :deploy do
task :start do
invoke 'bin/delayed_job:start'
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
Server Info:
Ubuntu 20.04
Bundler is confirmed to be installed on the server.
Gem Info
Do I perhaps need to change the default version of bundler?
I can see the release folders get generated, but because of the failure no current sym_link is ever created and deployment fails. Is there a server setup step I'm missing for the initial cap deploy to a new staging server? Do I need to have bundler installed in a specific server location in order for cap to "find" it?
I was able to get past this blocker. The ultimate issue is that I had to log into the correct shell and run gem install bundler:1.16.1.
In order to log into the bash I used this command:
/bin/bash --login
Then run gem install:
gem install bundler:1.16.1

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.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