Bundle install in production on AWS fails with broken pipe - ruby-on-rails

I'm deploying a rails application to a production server on AWS. When running 'bundle install' I am getting the error
Gem::RemoteFetcher::FetchError: IOError: Broken pipe (https://rubygems.org/gems/random.gem)
Every 'bundle install' installs one or two more gems, but ends up failing. I am using a m1.medium sized server. Do I need a larger instance or is there some other problem?

I actually had two problems. The first was that my bundler was outdated. I fixed that by running
gem update bundler
and the second problem was that I needed to bundle install as the root user since bundler was trying to install gems in a root owned location.
Hope this helps someone in the future.

Related

Trying to create a rails app but keeps failing to setup

I'm trying to create my first rails app. I'm on a Macbook Pro, so macOS.
I've been following this guide setting up rbenv, rails etc.
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-macos
Then I'm following a crash course on YouTube. In the terminal I try to create a new rails app
rails new foodlog
It starts to set up in the folder I made for it, but the following happens during setup
Bundler::PermissionError: There was an error whle trying to create
'/Users/myusername/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0/racc-1.6.0'.
It is likely that you need to grand executable permissions for all parent directories and write permissions for
/Users/myusername/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0'
This error continues repeating the same thing with things such as "strscan".
Then after it says
In gemfile:
rails was resolved to 7.0.3.1, which depends on
actionmailbox was resolved to 7.0.3.1, which depends on
net-imp was resolved to 0.2.3, which depends on
stscan
run bundle binstubs bundler
Could not find gem 'sprockets-rails' in locally installed gems.
rails importmap:install
Could not find gem 'sprockets-rails' in locally installed gems.
Run 'bundle install' to install missing gems.
rails turbo:install stimulus:install
Could not find gem 'sprockets-rails' in locally installed gems.
Run 'bundle install' to install missing gems
I've tried looking online, coming across similar but not exact issues. For example, one solution suggested doing bundle install in this directory, versus where the guide says do it in the home directory. So I do that and get
Bundle complete! 0 gemfile dependencies, 1 gem now installed.
Still doesn't do anything. I think the main culprit is the permissions error it mentions above? This is my first time trying to really do any development on the macOS and I'm sure there's just a misunderstanding somewhere regarding permissions, so if anyone can help that would be appreciated!
It is likely that you need to grand executable permissions for all parent directories and write permissions for
/Users/myusername/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0'
Your question does not mention, so I think you might have missed this suggestion. Make sure all directories have the executable permission

Ruby on rails error Could not find rake-13.0.3 in any of the sources

What is happening with rails? A couple of days ago I everything was running smoothly and now trying to spin up the server I'm getting this error
Could not find rake-13.0.3 in any of the sources
Run `bundle install` to install missing gems.
running bundle install will create a massive cache folder under vendor and I'm able to spin up the server. However, deleting this cache folder everything breaks again. I'm running rails 6.0 and ruby 2.6.1.
I had this error when I had Ruby installed via rbenv, but rails via apt-get.
Installing rails with 'gem install' instead of 'apt' made it work for me.

Rails bundle error when pushing to Elastic Beanstalk

I had an app deployed on Heroku and I am currently trying to create the same app on AWS.
I've copied my folder, created a complete separated repo on Github and installed ebcli, the setup looks fine.
When I try to run eb deploy, I have this error:
[Instance: i-03051e2a022886184] Command failed on instance. Return code: 1 Output: (TRUNCATED)...:in find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems.rb:308:inactivate_bin_path'
from /opt/rubies/ruby-2.5.3/bin/bundle:23:in `'.
I've looked online and it says it comes from incompatibility between your gemlock file bundler version and actual bundler version.
I've tried to change my bundler version to this one, but I gave up and came back to 2.0.1 because I had to install too many dependencies otherwise.
I removed the gemlock, bundle again, but I still got the same error when trying to deploy.
With my heroku version, it always worked.
Any idea how to solve that?
Thanks a lot
We moved from Heroku to AWS a few months back as well and it will likely take some some custom scripting to get things to work.
It would help to know more about your EB environment, but I am assuming you are using Ruby 2.5 with Puma on Amazon Linux 2.9.0 (?)
Not sure what bundle version comes with that, But I don’t think it’s 2.x. so you have to add an .ebextensions file too install your preferred bundled version.
# .ebextensions/01_install_bundler.config
container_commands:
install_bundler:
command: “gem install bundler —-version 2.0.0”
More info on AWS Linux customizations
End of the day, we are much happier with our AWS environment (lower cost, better performance), but requires more work to get it set up
Actually the problem exists because the bundler version in the eb env is older than the one being used in the project source.
So the solution is to use a bundler version less or equal the eb env installed version.
First uninstalled the current bundler:
gem uninstall bundle
and then install the desired one:
gem install bundler -v 1.16.6
See more details

ElasticBeanstalk - Rails Nokogiri Deployment Issue

I have a working rails application deployed to EC2 through ElasticBeanstalk. I update the website every few weeks without issue. Today I'm running into a problem after committing changes and running "eb deploy":
An error occurred while installing nokogiri (1.7.0.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.7.0.1'` succeeds before bundling.
I haven't changed anything aside from a few views. The host is the same and the Gemfile is the same. On my local machine, I can run that command and then bundle install/update without issue. I can SSH to the EC2 host and successfully run that command to install that version of Nokogiri, too.
When I deploy, I get that error message (with no other details). I'm stuck - Any idea what I should look into next? Note that this started happening to a working setup, so I don't think it's the host missing libxml or another dependency.
Found it. There was a line in the log file that I was missing.
"Cannot allocate memory"
Rails was using a lot more memory than I thought. Just sitting there it was using 1.7GB out of 2.0GB. I temporarily added 1GB of swap and the deployment succeeded.

Ruby on Rails, bundle deployment dreamhost

I ran into some problem with passenger on Dreamhost after installing refinerycms with its blog plugin. The rack just failed without any information about the
problem, It only said "... please check the server log ... " and a stack trace
without any message about the error.
After a while trying to reinstall but failed, running in the same problem. I finally have it work by doing 2 steps:
1) bundle install --deployment
==> It now shows the error about the differences in Rack version, my required 1.2.4 but it's 1.2.1 configured.
( I did 'bundle install' before but not solve the problem of rack )
2) I googled and update my Gemfile.lock to 1.2.4
AND IT WORKS ... LIKE MAGIC...
Can someone explain to me :
what did "bundle install --deployment" do differently from
"bundle install" ?
What's "Gemfile" and "Gemfile.lock" different ?
Any idea why It would work if I do like above ?
Thanks a lot
Rails 3's "bundle install" and "bundle install --deployment" both work well except the 2nd one just uses more disk space?
Gemfile keeps track of what gems are necessary and Gemfile.lock also keeps track of all your gems' dependencies
Regarding #3, Dreamhost basically requires rack 1.2.1, which you would normally set by having a line like this in your Gemfile:
gem "rack", "=1.2.1"
I assume that hacking the version into Gemfile.lock works because it is installed on the system already, so your app is able to load it without any problems. But it would certainly be better to just specify it in your Gemfile.
Getting rack-based apps running on Dreamhost can be a bit of a trial. If you continue to have problems, you will probably need to post some more details about your config and any specific errors you're getting.

Resources