1

I'm attempting to deploy a Rails 7 app (Ruby 3.0.4) to Elastic Beanstalk which uses Amazon Linux 2. Possibly could be an issue with installing dependencies for nokogiri?

Could not find nokogiri-1.13.7-x86_64-linux in any of the sources

2022/07/17 13:57:15.371714 [ERROR] An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Gemfile failed with error Command /bin/sh -c bundle 2.3.15 install --local failed with error exit status 7. Stderr: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. Could not find nokogiri-1.13.7-x86_64-linux in any of the sources

I'm using Bundler 2.3.18 on my mac, I see Elastic Beanstalk is using Bundler 2.3.15, I'm not sure if that will cause issues?

I tried removing all my gems and reinstalling, then deploying to AWS EB.

  1. I deleted gemfile.lock
  2. I commented out the Gemfile and ran bundle clean --force then uncommented the Gemfile afterwards.
  3. rm -rf vendor/cache to remove cached gems
  4. ran bundle (re-installed gems again)

Initially I couldn't use bin/dev due to a foreman error so I reinstalled foreman with rbenv local 3.0.4 && gem install foreman

After reading https://nokogiri.org/tutorials/installing_nokogiri.html I ran bundle lock --add-platform x86_64-linux

I tried this a fallback solution https://nokogiri.org/tutorials/installing_nokogiri.html#solution_1

rm -rf vendor/cache
bundle config set force_ruby_platform true
bundle install

I will get an error about the pg gem if I don't cache the gem files under vendor/cache

bundle package --all 

in my gemfile.lock I see the x86_64-linux entries.

PLATFORMS
  ruby
  x86_64-linux

and

nokogiri (1.13.7)
  mini_portile2 (~> 2.8.0)
  racc (~> 1.4)
nokogiri (1.13.7-x86_64-linux)
  racc (~> 1.4)
pg (1.4.1)

I have a .ebextensions/options.config file with the below. I tried what was in this SO answer but it didn't work for me.

packages:
  yum:
    amazon-linux-extras: []
    git: []
    patch: []
    gcc: []
    libxml2: []
    libxml2-devel: []
    libxslt: []
    libxslt-devel: []

commands:
  01_A:
    command: sudo amazon-linux-extras enable postgresql13
  02_B:
    command: sudo yum install -y postgresql-devel

At the elastic beanstalk CLI I ran:

eb create staging-env -db.engine postgres --database.instance db.t3.micro  --database.username my_user --database.password my_pass --database.size 5 --database.version 13.4 --instance_type t3.micro --single

It always fails at the EC2 instance step and the eb-engine.log file will reference nokogiri as the cause.

Update

In cfn-init.cmd.log I'm seeing entries like below which indicate that the dependencies for nokogiri are being installed. Possibly there is a dependency that I missed still?

[INFO] yum list installed libxml2
[INFO] Completed successfully.

In eb-engine.log the bundle command is being run with the --local option by elastic beanstalk. So it's only looking at vendor/cache and the x86_64-linux nokogiri isn't there.

error **Command /bin/sh -c bundle _2.3.15_ install --local** failed with error exit status 7. Could not find nokogiri-1.13.7-x86_64-linux in any of the sources

I tried passing bundle install in the ebextensions/options.config file but it fails.

  04_bundle:
    command: 'bundle install' 
random_user_0891
  • 1,863
  • 3
  • 15
  • 39

1 Answers1

4

This is what finally ended up working for me. I created .ebextensions/ruby.config with the below package dependencies for nokogiri.

packages:
  yum:
    amazon-linux-extras: []
    git: []
    patch: []
    gcc: []
    libxml2: []
    libxml2-devel: []
    libxslt: []
    libxslt-devel: []

commands:
  01_postgresql13:
    command: sudo amazon-linux-extras enable postgresql13
  02_postgresql-devel:
    command: sudo yum install -y postgresql-devel

I ran bundle lock --add-platform x86_64-linux (there is also an aarch64\arm64 version if you need it) and checked that nokogiri had the new linux version listed in my gemfile.lock

I deleted all of my cached gems under vendor/cache with rm -rf vendor/cache

Make sure everything is committed in git. The important part was to delete the gem cache so that elastic beanstalks bundler doesn't look at the cache and is forced to fetch the linux version of the gem.

Fetching nokogiri 1.13.7 (x86_64-linux)
Installing nokogiri 1.13.7 (x86_64-linux)
random_user_0891
  • 1,863
  • 3
  • 15
  • 39