Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building in Docker fails for alpine/musl #272

Open
andyjeffries opened this issue Jan 8, 2024 · 7 comments
Open

Building in Docker fails for alpine/musl #272

andyjeffries opened this issue Jan 8, 2024 · 7 comments

Comments

@andyjeffries
Copy link

129.3 error: cannot produce cdylib for `commonmarker v1.0.0
129.3 (/usr/local/bundle/gems/commonmarker-1.0.4/ext/commonmarker)` as the target
129.3 `x86_64-unknown-linux-musl` does not support these crate types
129.3 make: *** [Makefile:566: target/release/libcommonmarker.so] Error 101
129.3 
129.3 make failed, exit code 2
129.3 
129.3 Gem files will remain installed in /usr/local/bundle/gems/commonmarker-1.0.4 for
129.3 inspection.
129.3 Results logged to
129.3 /usr/local/bundle/extensions/x86_64-linux-musl/3.3.0/commonmarker-1.0.4/gem_make.out
129.3 
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:125:in `run'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:51:in `block in make'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `each'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `make'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:193:in `build_extension'
129.3 /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:227:in `block in
129.3 build_extensions'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `each'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `build_extensions'
129.3   /usr/local/lib/ruby/3.3.0/rubygems/installer.rb:852:in `build_extensions'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/rubygems_gem_installer.rb:76:in
129.3 `build_extensions'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/rubygems_gem_installer.rb:28:in
129.3 `install'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/source/rubygems.rb:205:in
129.3 `install'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/installer/gem_installer.rb:54:in
129.3 `install'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/installer/gem_installer.rb:16:in
129.3 `install_from_spec'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/installer/parallel_installer.rb:132:in
129.3 `do_install'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/installer/parallel_installer.rb:123:in
129.3 `block in worker_pool'
129.3   /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/worker.rb:62:in `apply_func'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/worker.rb:57:in `block in
129.3 process_queue'
129.3   <internal:kernel>:187:in `loop'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/worker.rb:54:in
129.3 `process_queue'
129.3 /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/worker.rb:90:in `block (2
129.3 levels) in create_threads'
129.3 
129.3 An error occurred while installing commonmarker (1.0.4), and Bundler cannot
129.3 continue.
129.3 
129.3 In Gemfile:
129.3   commonmarker
------
ERROR: failed to solve: executor failed running [/bin/sh -c apk add --update --no-cache build-base make gcc musl-dev     && bundle install     && rm -rf /usr/local/bundle/cache/*.gem     && find /usr/local/bundle/gems/ -name "*.c" -delete     && find /usr/local/bundle/gems/ -name "*.o" -delete     && apk del make gcc musl-dev build-base]: exit code: 5

Exited with code exit status 1

This is a Ruby 3.3 (ruby:3.3.0-alpine) based image, that is simply doing a bundle install

@gjtorikian gjtorikian changed the title Building in Docker fails Building in Docker fails for alpine/musl Jan 8, 2024
@gjtorikian
Copy link
Owner

Ah yeah I don't support musl, it says so right in the first few lines:

129.3 error: cannot produce cdylib for `commonmarker v1.0.0
129.3 (/usr/local/bundle/gems/commonmarker-1.0.4/ext/commonmarker)` as the target
129.3 `x86_64-unknown-linux-musl` does not support these crate types

I am not sure if I ever will tbh. Bluntly, it's more work to figure out how to get it working in this environment. I have heard too many tales of alpine being "different" enough to not investigate it. I'd consider PRs that support it, though.

@gjtorikian
Copy link
Owner

Hi, I had a chance to look into this. I can adjust the project to build for x86_64-linux-musl:

cd pkg/commonmarker-1.1.1-x86_64-linux-musl
  Successfully built RubyGem
  Name: commonmarker
  Version: 1.1.1
  File: commonmarker-1.1.1-x86_64-linux-musl.gem

But, I don't know enough about musl to understand what your platform is. The build system I use doesn't recognize it:

❌ Platform x86_64-unknown-linux-musl is not supported

Would support for x86_64-linux-musl be enough for you? What exactly is unknown-linux-musl?

@andyjeffries
Copy link
Author

To be honest, we've just pinned the version to 0.23.10 and it works for us. So don't stress too much for now about it (at least from my perspective)

It was being built on an alpine base on CircleCI. So I don't know what CPUs they use or why it comes as "unknown".

@RubenSmit
Copy link

We ran into the same problem when building a ruby:3.3.0-alpine based docker container with bundle install. The error it threw was (for reference):

LoadError: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/local/bundle/gems/commonmarker-1.1.5-x86_64-linux/lib/commonmarker/3.3/commonmarker.so) - /usr/local/bundle/gems/commonmarker-1.1.5-x86_64-linux/lib/commonmarker/3.3/commonmarker.so (LoadError)

This is probably caused by trying to run glibc programs in Alpine Linux that uses musl. According to the Alpine linux documentation there are multiple options to do this. We used the gcompat compatibility layer and added this to our Dockerfile:

RUN apk add gcompat

This solved it for us.

@andyjeffries
Copy link
Author

We still get an error even after adding gcompat:

#18 109.4 error: cannot produce cdylib for `commonmarker v1.0.0
#18 109.4 (/usr/local/bundle/gems/commonmarker-1.1.5/ext/commonmarker)` as the target
#18 109.4 `aarch64-unknown-linux-musl` does not support these crate types
#18 109.4 make: *** [Makefile:566: target/release/libcommonmarker.so] Error 101
#18 109.4
#18 109.4 make failed, exit code 2

(that was using Docker 4.7.1 on a Mac Sonoma 14.6.1, built using ruby:3.3.0-alpine as a base image)

@RubenSmit
Copy link

I can't say what's going wrong without looking at your Dockerfile and docker-compose.yml. We are using ruby:3.3.0-alpine3.19 specifically on docker engine 26.1.4 on several different linux distro's and AWS fargate.

@Ksm125
Copy link

Ksm125 commented Nov 7, 2024

Hello, i also have the same error in my docker build using ruby:3.2.2-alpine3.19

 /usr/local/bundle/gems/commonmarker-1.1.5-aarch64-linux/lib/commonmarker/extension.rb:7:in `require_relative': Error relocating /usr/local/bundle/gems/commonmarker-1.1.5-aarch64-linux/lib/commonmarker/3.2/commonmarker.so: __snprintf_chk: symbol not found - /usr/local/bundle/gems/commonmarker-1.1.5-aarch64-linux/lib/commonmarker/3.2/commonmarker.so (LoadError)

here is a sample of my Dockerfile

FROM ruby:3.2.2-alpine3.19

ENV BUNDLER_VERSION=2.4.19

RUN apk upgrade && apk add --no-cache --update build-base \
    curl \
    linux-headers \
    git \
    postgresql-dev \
    postgresql-client \
    vips \
    libheif \
    python3 \
    gcompat

RUN gem install bundler --default -v ${BUNDLER_VERSION}

COPY Gemfile .
COPY Gemfile.lock .

RUN bundle install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants