anuaralfetahe

anuaralfetahe

Hi,

I’m trying to build a multi-platform Docker image based on elixir:1.17-otp-27. However, I’ve encountered an issue: the jason library fails to compile on arm64 because my host machine is running on amd64 architecture. I’ve also tried building the image on an arm64 machine, but then the build step for amd64 fails.

Does anyone have any suggestions on how to resolve this issue? I prefer not to create separate image tags, as the elixir:1.17-otp-27 base image already seems to supports both architectures.

Steps to reproduce:

  • Create new project: mix new myapp
  • Add jasonas dependency in the mix.exs file: {:jason, "~> 1.4"}
  • Create Dockerfile with the following contents:
FROM elixir:1.17-otp-27

WORKDIR /app

COPY . .

RUN MIX_ENV=prod mix deps.get
RUN MIX_ENV=prod mix compile
RUN MIX_ENV=prod mix release
  • Build the image: docker buildx build --platform linux/amd64,linux/arm64 -t myapp_test .

This is the output:

 => ERROR [linux/arm64 5/6] RUN MIX_ENV=prod mix compile                                                                21.1s
------
 > [linux/arm64 5/6] RUN MIX_ENV=prod mix compile:
6.777 ==> jason
6.779 Compiling 10 files (.ex)
17.80 Compiling lib/encode.ex (it's taking more than 10s)
19.47 Compiling lib/decoder.ex (it's taking more than 10s)
20.03 Generated jason app
20.07 could not compile dependency :jason, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile jason --force", update it with "mix deps.update jason" or clean it with "mix deps.clean jason"
20.84 Segmentation fault (core dumped)
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:9
--------------------
   7 |     
   8 |     RUN MIX_ENV=prod mix deps.get
   9 | >>> RUN MIX_ENV=prod mix compile
  10 |     RUN MIX_ENV=prod mix release
--------------------
ERROR: failed to solve: process "/bin/sh -c MIX_ENV=prod mix compile" did not complete successfully: exit code: 139

Is there anything else I could do to build the same tag for both architectures? Thanks in advance :slight_smile:

Showing Posts 1 to 4

dimitarvp

dimitarvp

A shot in the dark, maybe installing build-essential with the distro’s package manager could help? Though I don’t think jason has any native dependencies…

garazdawi

garazdawi

Erlang Core Team

Is it specifically jason? Does it work for other libraries?

There have been issues in the past with qemu and the Erlang JIT, though they usually manifest earlier. Try setting ERL_FLAGS="+JMsingle true" and see if that helps.

anuaralfetahe

anuaralfetahe OP

Actually jason library had nothing to do with the problem. It was just the first library on my dependency list which failed with the error message.

Adding RUN ERL_FLAGS="+JMsingle true" MIX_ENV=prod mix compile fixed the issue for multi arch build, thank you!

I’m wondering if this flag is only used during the compilation step it has no negative effect on the runtime?

garazdawi

garazdawi

Erlang Core Team

It does not effect runtime if you only enable it during compilation. The flag disables some safeguards put in place that limits what an attacker can do if they find a vulnerability in the JIT.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews