Stranger6667 / css-inline

High-performance library for inlining CSS into HTML 'style' attributes
https://css-inline.org/
MIT License
243 stars 29 forks source link

Ruby gem fails to install on Alpine #394

Open wkirby opened 4 hours ago

wkirby commented 4 hours ago

I'm running a ruby alpine docker container (ruby:3.3-alpine3.19). I have installed the packages alpine-sdk, ruby-dev and gcompat, which are usually enough to build any gem that does not have pre-built binaries.

Running gem install css_inline results in the following output:

Building native extensions. This could take a while...
ERROR:  Error installing css_inline:
    ERROR: Failed to build gem native extension.

    current directory: /bundle/gems/css_inline-0.14.1/ext/css_inline
/usr/local/bin/ruby extconf.rb
*** 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=${opt-dir}/include
    --without-opt-include
    --with-opt-lib=${opt-dir}/lib
    --without-opt-lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/$(RUBY_BASE_NAME)
<internal:/usr/local/lib/ruby/site_ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require': cannot load such file -- rb_sys/mkmf (LoadError)
    from <internal:/usr/local/lib/ruby/site_ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
    from extconf.rb:2:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /bundle/gems/css_inline-0.14.1 for inspection.
Results logged to /bundle/extensions/aarch64-linux-musl/3.3.0/css_inline-0.14.1/gem_make.out

Any guidance on missing dependencies would be appreciated, as would prebuilt binaries aarch64-linux-musl.

Stranger6667 commented 4 hours ago

Hi! I think a Rust compiler might be missing there. I am going to take a look at magnus docs in this regard, maybe I've missed something. I'd be happy to build aarch64-linux-musl for Ruby as a part of the release artifact set.

wkirby commented 1 hour ago

@Stranger6667 thanks for the fast response!

Tried isntalling clang & lld, then installing rust itself. cargo --version now outputs:

cargo 1.82.0 (8f40fc59f 2024-08-21)

Unfortunately, this still results in the same error message as above.

Here's a minimal Dockerfile which allows a repro of the issue:

FROM public.ecr.aws/docker/library/ruby:3.3-alpine3.19 AS runner

ENV APP_HOME="/app"
ENV BUNDLE_BIN="/bundle/bin"
ENV DEBIAN_FRONTEND="noninteractive"
ENV BUNDLE_BUILD__SASSC="--disable-march-tune-native"
ENV BUNDLE_JOBS="5"
ENV BUNDLE_PATH="/bundle"
ENV GEM_HOME="/bundle"
ENV BUNDLE_GEMFILE="$APP_HOME/Gemfile"
ENV PATH="${BUNDLE_BIN}:${PATH}"

WORKDIR $APP_HOME

# Update Gems first...only re-do this when bundler version changes.
# If we need to force a gem update we'll have to `--no-cache` or add a file we can copy in
RUN gem update --system && gem install bundler:2.5.21

RUN apk add --update --no-cache \
    alpine-sdk \
    curl \
    bash \
    gcompat

If you save that to a directory as Dockerfile, then you should be able to run:

docker run -it $(docker build -q .) bash

That should drop you into the container in a minimal reproduction of my environment.

Then

gem install css_inline

And observe the error I'm getting.

Ultimately, though, it shouldn't really matter. If you're able to build/distribute the binaries for aarch64-linux-musl the whole thing is probably moot.