[AWS] $ docker build. * Error * Gem :: Ext :: BuildError: ERROR: Failed to build gem native extension.

Conclusion

It seems that there was not enough space in the Swap file.

◆ What is a Swap file?

Files prepared to temporarily increase the amount of memory. EC2 does not prepare Swap files by default, so it seems that processing errors will occur if you do large processing!

Error statement

Terminal.


[ec2-user@ip-10-0-0-180 app]$ docker build .
Sending build context to Docker daemon  889.9kB
Step 1/12 : FROM ruby:2.7
 ---> 7e58098089a4
~abridgement~

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/sassc-2.4.0/ext
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r
./siteconf20201228-6-fydanh.rb extconf.rb
creating Makefile

current directory: /usr/local/bundle/gems/sassc-2.4.0/ext
make "DESTDIR=" clean

current directory: /usr/local/bundle/gems/sassc-2.4.0/ext
make "DESTDIR="
compiling ./libsass/src/ast.cpp

~abridgement~

compiling ./libsass/src/parser.cpp
virtual memory exhausted: Cannot allocate memory
make: *** [Makefile:237: parser.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/bundle/gems/sassc-2.4.0 for
inspection.
Results logged to
/usr/local/bundle/extensions/x86_64-linux/2.7.0/sassc-2.4.0/gem_make.out

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

In Gemfile:
  sass-rails was resolved to 6.0.0, which depends on
    sassc-rails was resolved to 2.1.2, which depends on
      sassc
The command '/bin/sh -c bundle install' returned a non-zero code: 5

__ ** The following notable error points __ It seems that "gem native extension" could not be built due to lack of virtual memory.

//The gem native extension could not be built
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
//Virtual memory exhausted: Unable to allocate memory make:*** [Makefile:237:parser.o]Error 1
virtual memory exhausted: Cannot allocate memory
make: *** [Makefile:237: parser.o] Error 1

Increase the area of ​​Swap files

Terminal.


#Do it in your home directory
[ec2-user@ip-172-31-25-189 ~]$ cd
[ec2-user@ip-172-31-25-189 ~]$ sudo dd if=/dev/zero of=/swapfile1 bs=1M count=512

#The following contents will be displayed
512+0 Record input
512+0 record output
536870912 bytes(537 MB)Copied, 7.35077 seconds, 73.0 MB/Seconds

#Change permissions
[ec2-user@ip-172-31-25-189 ~]$ sudo chmod 600 /swapfile1

#Prepare Linux swap space on a device or file
[ec2-user@ip-172-31-25-189 ~]$ sudo mkswap /swapfile1

#It is displayed as follows
Set swap space version 1, size= 524284 KiB
No label, UUID=74a961ba-7a33-4c18-b1cd-9779bcda8ab1

#Probably enabled paging and swapping to devices and files
[ec2-user@ip-172-31-25-189 ~]$ sudo swapon /swapfile1

#The details are not yet known. If anyone knows it, I would appreciate it if you could write it in the comment section.
[ec2-user@ip-172-31-25-189 ~]$ sudo sh -c 'echo "/swapfile1  none        swap    sw              0   0" >> /etc/fstab'

__ In my case, when I expanded the area of ​​the Swap file, I was able to build without error! __ __ For your reference! __

Recommended Posts

[AWS] $ docker build. * Error * Gem :: Ext :: BuildError: ERROR: Failed to build gem native extension.
Gem :: Ext :: BuildError: ERROR: Failed to build gem native extension. Appears during gem install on debian distribution
[AWS] [docker] Internet connection failed during docker build
To beginners launching Docker on AWS
How to build CloudStack using Docker
Getting Started with Micronaut 2.x ~ Native Build and Deploy to AWS Lambda ~