stelligent / cfn_nag

Linting tool for CloudFormation templates
MIT License
1.25k stars 209 forks source link

gem install on alpine3.16.1: ERROR: Failed to build gem native extension #606

Open Poweranimal opened 2 years ago

Poweranimal commented 2 years ago

Hi,

Installing the cfn-nag (v0.8.10) gem on alpine3.16.1 fails with the following error:

ERROR ```text Building native extensions. This could take a while... ERROR: Error installing cfn-nag: ERROR: Failed to build gem native extension. current directory: /usr/local/bundle/gems/psych-3.3.2/ext/psych /usr/local/bin/ruby -I /usr/local/lib/ruby/3.1.0 -r ./siteconf20220730-14-dy0ixb.rb extconf.rb checking for yaml.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/bin/$(RUBY_BASE_NAME) --with-libyaml-dir --without-libyaml-dir --with-libyaml-include --without-libyaml-include=${libyaml-dir}/include --with-libyaml-lib --without-libyaml-lib=${libyaml-dir}/lib --enable-bundled-libyaml --disable-bundled-libyaml /usr/local/lib/ruby/3.1.0/mkmf.rb:498:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /usr/local/lib/ruby/3.1.0/mkmf.rb:624:in `block in try_compile' from /usr/local/lib/ruby/3.1.0/mkmf.rb:573:in `with_werror' from /usr/local/lib/ruby/3.1.0/mkmf.rb:624:in `try_compile' from /usr/local/lib/ruby/3.1.0/mkmf.rb:1213:in `block in find_header' from /usr/local/lib/ruby/3.1.0/mkmf.rb:1007:in `block in checking_for' from /usr/local/lib/ruby/3.1.0/mkmf.rb:362:in `block (2 levels) in postpone' from /usr/local/lib/ruby/3.1.0/mkmf.rb:332:in `open' from /usr/local/lib/ruby/3.1.0/mkmf.rb:362:in `block in postpone' from /usr/local/lib/ruby/3.1.0/mkmf.rb:332:in `open' from /usr/local/lib/ruby/3.1.0/mkmf.rb:358:in `postpone' from /usr/local/lib/ruby/3.1.0/mkmf.rb:1006:in `checking_for' from /usr/local/lib/ruby/3.1.0/mkmf.rb:1212:in `find_header' from extconf.rb:10:in `
' To see why this extension failed to compile, please check the mkmf.log which can be found here: /usr/local/bundle/extensions/x86_64-linux-musl/3.1.0/psych-3.3.2/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /usr/local/bundle/gems/psych-3.3.2 for inspection. Results logged to /usr/local/bundle/extensions/x86_64-linux-musl/3.1.0/psych-3.3.2/gem_make.out ```

Steps to reproduce

Dockerfile:

FROM docker.io/alpine:3.16.1
RUN apk add --no-cache ruby-dev=3.1.2-r0 &&\
    gem install cfn-nag -v 0.8.10

Run docker build

manuelnucci commented 1 month ago

I got the same error today.

crise1929 commented 1 month ago

@Poweranimal @manuelnucci I had the same problem. To solve it, I had to install 3 packages before the command "gem install cfn-nag" Here is my Dockerfile from ruby 3.3 in Alpine 3.20. Try the apk add...

ARG RUBY_VERSION=3.3
FROM ruby:${RUBY_VERSION}-alpine

ARG PKG_LIST='gcc musl-dev make'
RUN apk add --no-cache ${PKG_LIST} \
 && gem update --system \
 && gem install cfn-nag \
 && apk del --purge --rdepends --no-cache ${PKG_LIST}

ENTRYPOINT ["cfn_nag"]
CMD ["--help"]