Ruby on Rails in Docker on Apple Silicon (M1)
Asked Answered
Z

2

9

I'm trying to get Ruby on Rails running in a Docker on an Apple Silicon (M1) Macbook. The problem I'm having is the Javascript runtime. The gem mini_racer depends on libv8 which does not install properly. People having similar issues seems to either compile V8 from source and force libv8/mini_racer to use the system version. The other path seem to be to use NodeJS instead.

Has anyone gotten RoR with Javascript runtime up and running in Docker on a M1 chip?

Zak answered 16/2, 2021 at 14:15 Comment(2)
I'm a little surprised by the lack of information on this subject. There has to be more people doing Rails dev with Docker on a M1 Mac. What are you guys using?Zak
No one has Rails up and running in Docker on an M1 yet?Zak
H
5

What I can say from a V8 perspective is:

  • Running recent V8 versions (8.7 and later branches) on M1 hardware works just fine.
  • Compiling V8 on M1 Macs is not yet supported (but will be); for now you have to cross-compile on an Intel Mac.
  • In a comment, you say you're "running this in a Docker container using Ubuntu". In that case, take a look at https://bugs.chromium.org/p/v8/issues/detail?id=6458#c7. Compiling V8 on Linux-arm64 should work, generally.
  • V8 3.16 is practically from the stone age (8 years ago) and didn't even have an arm64 port at the time, so if you're stuck with that version you'll have to use a 32-bit arm build, and you may have to use old compilers and generally do some manual work to get the right (old) versions of a few dependencies. I've heard recently that building 32-bit arm on arm64 machines doesn't work (because historically, nobody has had a reason to ever do that), so you'd again be looking at cross-compiling on an x86 machine (32 or 64 bits).
  • Different V8 branches are generally not ABI-compatible; so if your mini_racer version needs V8 3.16, then a bunch of work will be required to update it to work with V8 8.7 (or the current stable version, 8.9). Even swapping 3.15 and 3.16 is dubious at best and may well not work.

(I'm not familiar with RoR or Docker, so I can't help with the specifics regarding those.)

Hauler answered 4/3, 2021 at 10:59 Comment(0)
C
2

As I remember seem it is not about M1 but mini_racer has some issues with libv8, but it usualy on mac we use to do following to solve issue

brew tap homebrew/versions
brew install v8-315

gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315

bundle install

but not sure why it is happening on your docker, another way is check where is v8 installed and change the --with url with that path.

In docker before error commit further lines, and let build done, then you can ssh in, and try to local command. Someone suggested following solution.

RUN gem install -N libv8 -v '3.16.14.13' -- --with-system-v8 \
 && bundle config --global build.libv8 --with-system-v8

You may share your dockerfile so first we can confirm it is working on normal machine and then you can try out. But of course M1 is different architecture and some programmes are not ready for it yet.

Canales answered 16/2, 2021 at 17:18 Comment(4)
Thanks for the response. However, since I'm running this in a Docker container using Ubuntu, Homebrew won't do the trick.Zak
well I updated response just try, or share your Dockerfile so can check on normal macbook! at least share it is not about file/system but about processor M1 architecture issue.Canales
The issue seems to be V8 on the M1. I'm running the same Docker-file on an Intel MacBook Pro without any issues.Zak
oh ok, yes I feel M1 is going to be mess for developers.Canales

© 2022 - 2024 — McMap. All rights reserved.