elixir-lang / gen_stage

Producer and consumer actors with back-pressure for Elixir
http://hexdocs.pm/gen_stage
1.52k stars 192 forks source link

Failure when package is compiled in a Docker container #308

Closed tomciopp closed 3 months ago

tomciopp commented 3 months ago

ELIXIR_VERSION=1.17.2 OTP_VERSION=26.2.5.2 DEBIAN_VERSION=bookworm-20240812-slim

BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

When building the docker image locally I get the following error:

Step 17/38 : RUN mix deps.compile
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
 ---> Running in 8b580f0bb830
==> gen_stage
Compiling 10 files (.ex)
Generated gen_stage app
** (ArgumentError) errors were found at the given arguments:

  * 2nd argument: not a key that exists in the table

    (stdlib 5.2.3.1) :ets.lookup_element(:elixir_modules, GenStage.Dispatcher, 2)
    (elixir 1.17.2) lib/kernel/typespec.ex:116: Kernel.Typespec.deftypespec/6
    (elixir 1.17.2) Collectable.impl_for/1
    (elixir 1.17.2) lib/collectable.ex:1: Collectable.impl_for!/1
    (elixir 1.17.2) lib/collectable.ex:92: Collectable.into/1
    (elixir 1.17.2) lib/system.ex:1126: System.do_cmd/3
    (mix 1.17.2) lib/mix/shell.ex:132: Mix.Shell.cmd/3
The command '/bin/sh -c mix deps.compile' returned a non-zero code: 1

I've never had an issue before when compiling locally, not quite sure why this error is occurring. If you need any more info I will grab it for you. The issue persists if I run the build without a cache.

josevalim commented 3 months ago

Those errors are almost always because of Docker + QEMU. You are probably building the image on a host with a different architecture than the target architecture. You can try setting this flag:

# This flag disables JIT behaviour that causes a segfault under QEMU.
# Note that we set this runtime flag only during the build stage and
# it has no impact when running the final image. See [1] for more
# information.
#
# [1]: https://github.com/erlang/otp/pull/6340
ENV ERL_FLAGS="+JMsingle true"

Otherwise, make sure you build the image on the same machine/architecture you are deploying to.

tomciopp commented 3 months ago

@josevalim That did it! You're a life saver.