Docker on Apple Silicon (M1) 中的 Ruby on Rails

Fre*_*rik 5 v8 ruby-on-rails docker libv8 apple-m1

我正在尝试让 Ruby on Rails 在 Apple Silicon (M1) Macbook 上的 Docker 中运行。我遇到的问题是 Javascript 运行时。gem mini_racer 依赖于未正确安装的 libv8。有类似问题的人似乎要么从源代码编译 V8,要么强制 libv8/mini_racer 使用系统版本。另一条路径似乎是改用 NodeJS。

有没有人在 M1 芯片上的 Docker 中启动并运行带有 Javascript 运行时的 RoR?

jmr*_*mrk 5

从V8的角度我可以说的是:

  • 在 M1 硬件上运行最新的 V8 版本(8.7 及更高版本)效果很好。
  • 尚不支持(但将会支持)在 M1 Mac 上编译 V8;现在您必须在 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.)


Kam*_*war 2

我记得似乎与 M1 无关,但 mini_racer 对 libv8 有一些问题,但通常在 mac 上我们用以下方法来解决问题

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
Run Code Online (Sandbox Code Playgroud)

但不确定为什么它会发生在你的 docker 上,另一种方法是检查 v8 的安装位置并使用该路径更改 --with url。

在 docker 中,在错误之前提交更多行,并让构建完成,然后您可以 ssh 进入,并尝试本地命令。有人提出了以下解决方案。

RUN gem install -N libv8 -v '3.16.14.13' -- --with-system-v8 \
 && bundle config --global build.libv8 --with-system-v8
Run Code Online (Sandbox Code Playgroud)

您可以分享您的 dockerfile,这样我们首先可以确认它在正常机器上运行,然后您可以尝试。但当然,M1 是不同的架构,有些程序还没有准备好。