ElasticBeanstalk - Rails Nokogiri Deployment Issue - ruby-on-rails

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.

Related

How to fix "bundler: command not found: rails" when deploying using Google Cloud App Engine

I am trying to deploy my Rails app to Google Cloud using App Engine Flexible Environment. Everything works fine when I run gcloud app deploy, but at the very end, when App Engine tries to run my application using bundle exec rails server -p $PORT, as specified in my app.yaml file, it crashes and gives the following error message:
Error Response: [9] Application startup error: 'bundler: command not
found: rails Install missing gem executables with bundle install
I tried changing the entrypoint value, running bundle install again and again, and installing all my gem files locally, but none of that worked. I also tried installing rack and changing the endpoint to run the app using rackup command, but that didn't work either. I am also skipping my gemfile.lock in my app.yaml file due to a previous error that was solved on SO.
I think you'd also want to install bundler in your container instance.
gem install bundler
The reason I was getting this error is because I was skipping the Gemfile.lock due to a previous error that I thought was solved here. The aforementioned 'solution' led to this error. The solution that I found is to make some edits to Gemfile.lock that solved the issue instead of avoiding it. The edits can be seen here.

Why does Elastic Beanstalk keep asking me to change from a root user for Bundler in a Rails app after I've changed it?

I'm trying to deploy a Ruby on Rails app online using Elastic Beanstalk from AWS as part of a project. I'm using the AWS and EB CLI and I can run eb init without a problem. However, when I try to run eb create myproject-env it leads to this warning:
{DATE} ERROR [Instance: myInstance] Command failed on instance. Return code: 20 Output: (TRUNCATED)...dor/cache ']'
+ bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
You must use Bundler 2 or greater with this lockfile.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
I've tried googling the problem and I keep being lead back to this link, which makes sense as far as I can tell. The thing is, I can't figure out how to get past this error. I've tried making new IAM users and using --profile myProfile, I've changed the user in Command Prompt, and I've uninstalled and reinstalled Bundler, awscli, and awsebcli. I'd like to keep this in the CLI just because I want to be able to use eb deploy in the future. And I can run the app locally using Puma with no problem, so I feel like I just haven't configured something correctly with AWS.
I also can't figure out the error about using a version of Bundler 2 or higher, because I am using a higher version on my computer right now.
I'm using Rails 5.2.2, Ruby 2.4.4, and Bundler 2.0.1 and I'm using Windows Command Prompt.
Any help would be appreciated!

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

Issue with Deploying Ruby on Rails on my Hosting Service

So I am trying to deploy a Rails app on my web hosting service. I have developed an app locally, but this is the first time I have tried to get it to work on another server. My service provider is Blue Host and I am on their most basic shared hosting plan. Just as a test, I created a fresh application on the server, and everything ran fine. However, whenever I add any gem to the Gemfile and run 'bundle install', I get this error:
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
Gem::Exception: Cannot load gem at [/usr/lib64/ruby/gems/1.9.3/cache/rake-10.4.2.gem] in /home/user/application
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.
Whenever I run gem install rake -v '10.4.2' the gem installs fine.
I get similar errors that mention 'sudo' when i try to run other commands as well.
I am not quite sure what this error means. Do I not have the required permissions on my server?
Always use a continuous deployment/integration.
Capistrano does part of the job. It is very simple, you develop you application offline, push to a remote repository, like BitBucket or Github, and then Capistrano takes care of cloning the remote repository to your server (you can also have many), restarting services etc.
If you want to go a step forward you can use continuous integration, so when you push to remote tests will automatically be performed and if they pass your application will be deployed.
This is a basic introduction on how deployment works, you can check online, there are plenty of resources about how to deploy rails.
Go with root user
su root
root$ /etc/

Bundle install in production on AWS fails with broken pipe

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.

Resources