rails: Default Dockerfile is broken for arm64 builds on Ruby 3.3.6 due to a Bootsnap bug
I’m on an Intel mac and the Docker build works if I leave the architecture as default. When targeting arm64 with --platform linux/arm64 however, it hangs with no output from bootsnap.
If I use docker buildx build . then it works fine. Downgrading to Ruby 3.2.6 also works fine.
Same issue on Bootsnap GitHub: https://github.com/Shopify/bootsnap/issues/495
The problematic line in the dockerfile is:
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
Breaking it apart into this shows that it’s bootsnap, but gives no ouput:
RUN bundle install
RUN rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
RUN bundle exec bootsnap precompile --gemfile --verbose
Steps to reproduce
- Install Ruby 3.3.6
- install rails 8.0.1 gem with
gem install rails rails new docker_testcd docker_testdocker buildx build --platform linux/arm64 .
Expected behaviour:
The docker build completes with no errors.
Actual behaviour:
Docker build hangs with the output from bundle install as the last lines on the console.
System configuration
Rails version: 8.0.1
Ruby version: 3.3.6
System: Intel MacOS
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 15 (11 by maintainers)
Yes, that was my issue:
Still, the
Dockerfilenew out-of-box was broken…That’s because the base image changed without warning: https://github.com/rails/rails/pull/54237
Can’t believe we’re being blamed for this…
And yes that a totally different issue.
Fair enough. To summarize for anyone ending up here later:
The reasoning is that, since the issue is not reproducible on an M1 MacBook Pro, emulation is likely a contributing factor, potentially the primary one. Until this is better understood, there’s nothing that can be done here.
This kind of issue is beyond the expertise of most web developers. A practical workaround for now might be to rent a VPS with ARM CPUs for the image-building process.
By the way, mattgibson mentioned on the Bootsnap repository that he was able to sidestep the issue by downgrading Ruby to version 3.2.6.
There might, but in any case the issue can’t really be fixed on the Rails side, and probably not even in bootsnap, because it mostly just calls into Ruby APIs to store the bytecode.
The key to fix this is to find a proper reproduction, so we can figure out what the bug is exactly, assuming it’s not in QEMU itself (QEMU easily deadlock in various cases, so if it’s a QEMU limitation, there’s likely not much we can do).
The obvious workaround being to not use bootsnap, but it’s too useful to most people to justify removing it entirely from the default Dockerfile.
You can try this branch: https://github.com/iiewad/blog/tree/debug when i run
docker buildx build --platform linux/amd64 .on Apple M1 Pro It is hang up too.