0
votes

I've got a Ruby on Rails application using Ruby 2.6.5 (rbenv) and Rails 5.2

I've created installation scripts to provision an EC2 instance and deploy the application to the instance.

It works consistently with a t3a.micro instance, but fails consistently if I use the same deployment scripts configured to use a t3a.nano (also fails on t3.nano) instance. The error is:

/home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/spec_set.rb:91:in `block in materialize': Could not find nokogiri-1.10.9 in any of the sources (Bundler::GemNotFound)
    from /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `map!'
    from /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `materialize'
    ...

I can manually install the gem:

$ which gem
/home/ubuntu/.rbenv/shims/gem
$ gem install nokogiri
Fetching mini_portile2-2.4.0.gem
Fetching nokogiri-1.10.9.gem
Successfully installed mini_portile2-2.4.0
Building native extensions. This could take a while...
Successfully installed nokogiri-1.10.9
Parsing documentation for mini_portile2-2.4.0
Installing ri documentation for mini_portile2-2.4.0
Parsing documentation for nokogiri-1.10.9
Installing ri documentation for nokogiri-1.10.9
Done installing documentation for mini_portile2, nokogiri after 2 seconds
2 gems installed
$

But it fails if I bundle install the application:

...
Running 'compile' for libxml2 2.9.10...
To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/nokogiri-1.10.8/mkmf.log

extconf failed, uncaught signal 9

Gem files will remain installed in /home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.8 for
inspection.
Results logged to
/home/ubuntu/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/nokogiri-1.10.8/gem_make.out

An error occurred while installing nokogiri (1.10.8), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.10.8' --source 'https://rubygems.org/'` succeeds before bundling.

Any idea what's going on or how to fix it? Why would bundle install be different than gem install in a way that cares whether I'm on a micro or nano ec2 instance?

If you want to test yourself, the project is on github: https://github.com/mawise/simpleblog You'll have to change deploymentscripts/deploy-aws.rb to reference a different instance type.

(I know some logs refer to 1.10.8 and others 1.10.9, I saw another post that suggested something was broken with 1.10.9 so I tried the lower version with the same results.)

1

1 Answers

2
votes

I have encountered this problem. Most likely your EC2 instance is running out of memory when compiling the gems, and it is not able to install all of the gems. A t3a.nano instance has 0.5 GB of memory, while t3a.micro has 1.0 GB.

I solved it in my application by simply creating a swap file. It's an elastic beanstalk application, but you can probably adapt it to your application.

https://github.com/stefansundin/rssbox/blob/1e40fe60f888ad0143e5c4fb83c1471986032963/.ebextensions/01-swap.config

# run as root:
dd if=/dev/zero of=/var/swapfile bs=1M count=512
chmod 600 /var/swapfile
mkswap /var/swapfile
swapon /var/swapfile
echo "/var/swapfile none swap sw 0 0" >> /etc/fstab