Capistrano deployment stuck at assets:precompile - ruby-on-rails

We are facing an issue with deploying our Rails app using Capistrano from a MacOS machine.
Capistrano runs inside a Docker container.
If I trigger the deployment from a Linux host machine (Capistrano running in Docker), it succeeds on all servers.
However, on MacOS, the deployment to production runs fine but not to the staging server.
The deployment is stuck at:
0:28 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
I can see on the server that the pre-compilation is running but Capistrano is stuck.
However, when it is run on a Linux machine or a CI server or to Production, it works fine.
00:09 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 yarn install v1.22.17
01 [1/4] Resolving packages...
01 [2/4] Fetching packages...
01 [3/4] Linking dependencies...
01 warning " > #rails/actiontext#6.1.7" has incorrect peer dependency "trix#^1.2.0".
01 [4/4] Building fresh packages...
01 Done in 22.10s.
01 yarn run v1.22.17
01 $ RAILS_ENV=${RAILS_ENV:-production} NODE_ENV=${NODE_ENV:-production} && webpack --config webpack.prod.js --env NODE_ENV=${NODE_ENV} --env RAILS_ENV=${RAILS_ENV} --progress
01 <s> [webpack.Progress] 0%
01
01 <s> [webpack.Progress] 1% setup before run
01 <s> [webpack.Progress] 1% setup before run NodeEnvironmentPlugin
01 <s> [webpack.Progress] 1% setup before run
In all scenarios, Capistrano is running from inside a Docker container.
The problem is only on MacOS and for only one server. Exact same Capistrano config and setup works for production deployments on MacOS.
I'm not sure on how to continue debugging this further and I would be very happy if someone could help and point me into the right direction.
Additionally, if I run Capistrano only for deploy:assets:precompile job, the job runs without any issues and print the output.
------ UPDATE --------
After restarting my development machine, everything seems to work now. It would be helpful to understand why this is the case. Others have also reported similar issues that got fixed after restart.

Related

Error when trying to deploy updated Rails app to Heroku - /bin/bundle: cannot execute binary file: Exec format error

I have a previously deployed Ruby on Rails API that I wanted to add some additional seed data to.
I am getting the following error when I deploy from either the Heroku CLI or from the web interface:
-----> Ruby app detected
-----> Installing bundler 2.0.2
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.5
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
Bundler Output: bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
I am not sure what the issue is. I have tried:
Deploying to a brand new Heroku application
Adding a Procfile
Adding a Ruby build pack
Resolving some outstanding security warnings from Github by running Bundle update locally and getting the new gemfile into my repo, prior to this there were no new Gem changes
None of these has changed the error I am getting.
If I clone the repo from github into a new folder on my Macbook I am able to get it up and running locally.
I have the following on my Macbook:
Ruby Version 2.6.5p114
Rails Version 6.0.3.2
Google does not seem to be turning up much, aside from some references to CPU architecture which I assume I have no control of in the Heroku environment.
My feeling is that it is related to bash being unable to execute bin/bundle but I've no idea why or how to resolve.
I vaguely recall having issues previously on this app, in that I was not able to run heroku run rake commands, possibly getting a similar error message, but to resolve I think I was able to simply run heroku run bin/rake
I believe the original rails new command was run on Windows 10 WSL environment in case that is relevant.
EDIT: I'm able to recreate a similar issue with rake, but the fix for rake does not work for bundle and I'm not even sure if it would help with the deployment issue.
➜ appbackend git:(master) heroku run rake
Running rake on ⬢ heroku-name-40049... up, run.8396 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/rake
Running bin/rake on ⬢ heroku-name-40049... up, run.5201 (Hobby)
Abort testing: Your Rails environment is running in production mode!
➜ appbackend git:(master)
➜ appbackend git:(master) heroku run bundle install
Running bundle install on ⬢ heroku-name-40049... up, run.7746 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/bundle install
Running bin/bundle install on ⬢ heroku-name-40049... up, run.4632 (Hobby)
bash: bin/bundle: cannot execute binary file: Exec format error
Turns out it was exactly as the error message stated Exec format error.
The bundle file in the bin directory was not the right format. Not sure how I managed to deploy in the first place (the history of this file has only 2 version in the repo, the first commit, and now the fix).
I was able to resolve by overwriting the bundle file from a different working rails install. Appreciated the help provided.

How to Deploy rails app to Digital Ocean without Asset precompile error

I am a Newbie trying to deploy a rails app to Digital Ocean.
Any time I change any of the CSS I get an error when running cap production deploy.
Here is the output:
01:04 deploy:assets:precompile
01 ls /home/studentloaniq/releases/20200208140055/assets_manifest_backup
01 ls:
01 cannot access '/home/studentloaniq/releases/20200208140055/assets_manifest_backup'
01 : No such file or directory
01
02 /usr/local/rvm/bin/rvm ruby-2.6.0 do bundle exec rake assets:precompile
02 Yarn executable was not detected in the system.
02 Download Yarn at https://yarnpkg.com/en/docs/install
02 rake aborted!
02 TypeError: no implicit conversion of Encoding into String

Rails Deploy Digitalocean ActiveSupport::MessageEncryptor::InvalidMessage:

I'm deploying an app on digitalocean following this guide: https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma#prerequisites
When I deploy with cap cap production deploy:initial --trace I keep getting this error
The deploy stops here: 01 ~/.rvm/bin/rvm default do bundle exec rake assets:precompile
01 rake aborted!
01
01 ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::Inva…
01
and when I run bundle exec rake assets:precompile locally I get yarn install v1.7.0
[1/4] 🔍 Resolving packages...
success Already up-to-date.
✨ Done in 0.05s.
I also installed yarn on the ubuntu server. I've made sure my ssh keys on the server are the same as my local ssh keys under ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa
I was thinking it was an SSH issue, but I think it might be something else since I've thoroughly followed online guides on digitalocean and elsewhere.
Any help would be appreciated!
This error was fixed by setting the secret keybase using export.
export SECRET_KEY_BASE="secret key"
To find or set your secret key in rails 5.2 use
rails credentials:edit
or if you haven't set your editor
EDITOR="vim --wait" rails credentials:edit
copy that secret key and then use the export line

Why is Puma unable to load Bundler when user who owns Puma process can?

For reasons beyond my control, I need to run a Rails 4 app on CentOS 7. Currently, it is running successfully on a Red Hat with rvm and Passenger. I'd like to migrate it over to rbenv and Puma but I am stuck with this issue.
I am trying to run a test installation on a VirtualBox virtual machine. I believe I've wired everything together correctly. I have disabled SELinux. When I run cap deploy, puma starts successfully:
04:03 puma:start
using conf file /var/www/rails-app/shared/puma.rb
01 bundle exec puma -C /var/www/rails-app/shared/puma.rb --daemon
01 * Pruning Bundler environment
01 [6464] Puma starting in cluster mode...
01 [6464] * Version 3.9.1 (ruby 2.1.10-p492), codename: Private Caller
01 [6464] * Min threads: 4, max threads: 16
01 [6464] * Environment: vm
01 [6464] * Process workers: 1
01 [6464] * Phased restart available
01 [6464] * Listening on unix:///var/www/rails-app/shared/tmp/sockets/puma.sock
01 [6464] * Daemonizing...
✔ 01 deploy#localhost 0.537s
But the Puma access log spins out this error in an infinite loop:
/home/deploy/.rbenv/versions/2.1.10/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
... stack trace clipped ...
Listing the processes associated with my Puma user shows:
$ ps aux | grep deploy
deploy 12645 0.0 0.2 115384 2084 pts/0 S 18:18 0:00 -bash
deploy 18517 0.7 1.7 271344 18076 ? Sl 18:27 0:00 puma 3.9.1 (unix:///var/www/rails-app/shared/tmp/sockets/puma.sock)
deploy 23279 7.0 0.0 0 0 ? Z 18:29 0:00 [ruby] <defunct>
deploy 23283 4.0 1.7 273400 17464 ? Rl 18:29 0:00 puma: cluster worker 0: 18517
I have confirmed that I can successfully run Bundler as the deploy user that owns the Rails application and the Puma process:
cd /var/www/rails-app/current && bundler --version
Bundler version 1.15.4
So I am not sure why am I seeing this error. After hours of research and troubleshooting, I'm stuck. I can provide config files if needed but they're pretty standard and I think would only clutter up this question at this point.
Does this issue look familiar to anyone?
Few steps to solve this type of issue:
Make sure that bundler is properly installed. Looks like yes in your case, but still a good thing to start by running a gem install bundler
Make sure that all your path is properly configured. Here is an example that looks similar to your case, where bundler was installed but path wasn't correct and bundler versions were mixed: cannot load such file -- bundler/setup (LoadError)
If you are using RVM you might want to take a look at: LoadError: cannot load such file -- bundler/setup

Capistrano deploy fails for repo that was moved from github to private git.. stil trying to contact github.. why?

I have a Rails 4 project that started at github and then it was moved to a private git repository. I can work perfectly with the repo (push, clone). I searched for references to the github repo somewhere in the code but none exists.. it must be something related to GIT and how the repository started..
Important: I was able to deploy with this configuration from my private repo until I removed the github one.
Of course I have updated config/deploy.rb
set :repo_url, '/srv/git/project.git'
Running "git remote -v":
origin git#git.server:/srv/git/project.git (fetch)
origin git#git.server:/srv/git/project.git (push)
Log of capistrano run "bundle exec cap production deploy":
00:00 git:wrapper
01 mkdir -p /tmp
server's password:
✔ 01 server 6.019s
00:07 git:check
01 git ls-remote --heads /srv/git/project.git
01 6b0c9f5ad2d8e768902c5da1509fd99915068295 refs/heads/master
✔ 01 server 0.356s
00:07 deploy:check:directories
01 mkdir -p /home/user/applications/project/shared /home/user/applications/project/releases
✔ 01 user#server 0.335s
00:08 deploy:check:linked_dirs
01 mkdir -p /home/user/applications/project/shared/public/assets
✔ 01 user#server 0.331s
00:09 git:clone
The repository mirror is at /home/user/applications/project/repo
00:10 git:update
01 git remote update --prune
01 Fetching origin
01 remote: Invalid username or password.
01 fatal: Authentication failed for 'https://github.com/user/project.git/'
01 error: Could not fetch origin
Moved from SVN to GIT not so much ago and a bit confused about this behaviour.. any help apreciated!
You have to change the origin on the server. The easiest way to accomplish this would probably be to SSH into the server, navigate to /home/user/applications/project/repo and:
git remote set-url origin /srv/git/project.git
I don't believe that capistrano will automatically update the remote.

Resources