Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails in Docker on Apple Silicon (M1)

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?

like image 543
Fredrik Avatar asked Nov 06 '22 02:11

Fredrik


2 Answers

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.

like image 27
Kamal Panhwar Avatar answered Nov 14 '22 21:11

Kamal Panhwar


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.)

like image 63
jmrk Avatar answered Nov 14 '22 23:11

jmrk