# BEAM docker release GitHub action - a GitHub action to build a docker container from a BEAM (Elixir/Erlang) release

**URL:** <https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090>\
**Category:** Libraries\
**Tags:** elixir, beam, erlang, docker\
**Created:** [November 30, 2022, 11:40am UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090 "2022-11-30T11:40:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shortishly](https://erlangforums.com/user_avatar/erlangforums.com/shortishly/32/495_2.png) [@shortishly](https://erlangforums.com/u/shortishly)\
**Post date:** [November 30, 2022, 11:40am UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/1 "2022-11-30T11:40:39Z")

</div>

What is it?

The [BEAM docker release GitHub action](https://github.com/shortishly/beam-docker-release-action) builds a tiny [from scratch](https://docs.docker.com/engine/userguide/eng-image/baseimages/) container as part of your GitHub workflow. With a minimal attack surface, of tens rather than hundreds of megabytes. We are building containers not virtual machines here!

It supports:

- [Elixir](https://elixir-lang.org) with the [Phoenix Framework](https://www.phoenixframework.org) using [mix](https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html) to build;
- [Erlang/OTP](https://www.erlang.org) with [erlang.mk](https://erlang.mk);
- [Erlang/OTP](https://www.erlang.org) with [rebar3](https://rebar3.org).

Hello World! Simple examples for both Elixir and Erlang can be found at:

- [Elixir with Phoenix](https://github.com/shortishly/hello_world/tree/elixir-phx)
- [Erlang/OTP with erlang.mk](https://github.com/shortishly/hello_world/tree/erlang-mk)
- [Erlang/OTP with rebar3](https://github.com/shortishly/hello_world/tree/rebar3)

Only the release and required runtime shared libraries are present. There is no shell, or any executable other than those required to run the [BEAM](https://www.erlang.org/blog/a-brief-beam-primer/).

Some real examples:

- [Erlang/OTP memcached server and client](https://github.com/shortishly/mcd/blob/main/.github/workflows/release.yml) with some [background here](https://shortishly.com/blog/mcd-emulating-memcached-with-statem-and-socket/).
- [Erlang/OTP real-time in memory database replication cache, with a memcached and REST API](https://github.com/shortishly/pgec/blob/main/.github/workflows/release.yml) with some [background here](https://shortishly.com/blog/postgresql-edge-cache/).

The parameters used in the BEAM docker release GitHub action [can be found here](https://github.com/shortishly/beam-docker-release-action). Some of the ideas are described further in this [article](https://shortishly.com/blog/erlang-in-docker-from-scratch/) with the [dependency copying script](https://github.com/shortishly/beam-docker-release-action/blob/main/bin/mkimage) now written as an [escript](https://www.erlang.org/doc/man/escript.html) to support both [Erlang/OTP](https://www.erlang.org) and [Elixir](https://elixir-lang.org). This [article](https://shortishly.com/blog/elixir-beam-docker-release-action/) looks at using [Elixir](https://elixir-lang.org) with the BEAM docker release action.

What doesn’t work right now?

- Multi-platform. `linux/arm64` crashes and burns with a `qemu` uncaught signal. It should work, and I would really like it to work! I would appreciate any collaboration into why. Hoping that it is something simple that I’ve done wrong. `linux/arm/v7` works fine…
- Other BEAM languages should be reasonably simple to support providing they use [relx](https://github.com/erlware/relx), with some updates to the [dependency copying script](https://github.com/shortishly/beam-docker-release-action/blob/main/bin/mkimage).

Regards,  
Peter.

---

<div class="post-metadata">

**Author:** ![asabil](https://erlangforums.com/user_avatar/erlangforums.com/asabil/32/381_2.png) [@asabil](https://erlangforums.com/u/asabil)\
**Post date:** [November 30, 2022, 10:54pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/2 "2022-11-30T22:54:06Z")

</div>

This looks awesome, thanks for sharing!

> [@shortishly](#):
>
> Multi-platform. `linux/arm64` crashes and burns with a `qemu` uncaught signal. It should work, and I would really like it to work! I would appreciate any collaboration into why. Hoping that it is something simple that I’ve done wrong. `linux/arm/v7` works fine…

I think that this comes from the fact that qemu doesn’t handle dual mapping which the erlang JIT relies on. You can try exporting the env var `ERL_AFLAGS="+JPperf true"` during the build (enabling perf has a side effect of disabling the dual mapping), on master you could use `+JMsingle true` instead (see [https://github.com/erlang/otp/pull/6340](https://github.com/erlang/otp/pull/6340))

---

<div class="post-metadata">

**Author:** ![shortishly](https://erlangforums.com/user_avatar/erlangforums.com/shortishly/32/495_2.png) [@shortishly](https://erlangforums.com/u/shortishly)\
**Post date:** [December 1, 2022, 10:41am UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/3 "2022-12-01T10:41:46Z")

</div>

Thank you @asabil! That did it!

I’ve updated the build platform default to linux/amd64 and linux/arm64, so that a multi-platform build is created. I’ve updated the HelloWorlds on Elixir and Erlang with multi-platform builds.

I’ve run the HelloWorld container on an arm64 Raspberry PI. It would be great to hear whether it works on Apple Silicon too.

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [December 4, 2022, 1:44pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/4 "2022-12-04T13:44:08Z")

</div>

> [@shortishly](#):
>
> There is no shell, or any executable

this is very inconvenient for debugging. Do I understand you correctly that main idea of this inconvenience is reducing amount of things that can be attacked?

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [December 4, 2022, 1:46pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/5 "2022-12-04T13:46:51Z")

</div>

> [@shortishly](#):
>
> Multi-platform. `linux/arm64` crashes and burns with a `qemu` uncaught signal

very strange. Our flussonic is being built for arm64 with cross-compile mechanism and docker buildx for creating multiarch image.

What do you use qemu for?

---

<div class="post-metadata">

**Author:** ![shortishly](https://erlangforums.com/user_avatar/erlangforums.com/shortishly/32/495_2.png) [@shortishly](https://erlangforums.com/u/shortishly)\
**Post date:** [December 4, 2022, 3:51pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/6 "2022-12-04T15:51:50Z")

</div>

> [@maxlapshin](#):
>
> very strange. Our flussonic is being built for arm64 with cross-compile mechanism and docker buildx for creating multiarch image.

Are you building with OTP25?

OTP25 on a JIT supported platform you’ll need `+JPperf true` to use a cross compile docker build with QEMU.

For example with `erlang:25` as the build image:

```shell
docker build --platform linux/arm64 \
                    --progress plain \
                    --tag hwe \
                    --build-arg BUILD_IMAGE=erlang:25 \
                    --build-arg GITHUB_REPOSITORY=shortishly/hwe \
                    --build-arg BUILD_COMMAND="make app rel" .
...
#9 [build 5/6] RUN make app rel
#9 sha256:bd13b2e954c569265bb333ec5cd7edd9a16b0254be86eaa9fbfd55231c6507b2
#9 1.195 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#9 1.207 Segmentation fault
#9 1.377 DEP relx (main)

```

Confusingly (at least to me at the time), `linux/arm/v7` _will_ work, but that is because it isn’t supported by the JIT in OTP25.

Whereas with `erlang:24` no segmentation faults (but no JIT!):

```shell
docker build --platform linux/arm64 \
                    --progress plain \
                    --tag hwe \
                    --build-arg BUILD_IMAGE=erlang:24 \
                    --build-arg GITHUB_REPOSITORY=shortishly/hwe \
                    --build-arg BUILD_COMMAND="make app rel" .
#13 exporting to image
#13 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#13 exporting layers 0.1s done
#13 writing image sha256:a789234df44084f937d80832e615071ed198631a35c04747955159cff4376de5
#13 writing image sha256:a789234df44084f937d80832e615071ed198631a35c04747955159cff4376de5 done
#13 naming to docker.io/library/hwe done
#13 DONE 0.1s

```

---

<div class="post-metadata">

**Author:** ![shortishly](https://erlangforums.com/user_avatar/erlangforums.com/shortishly/32/495_2.png) [@shortishly](https://erlangforums.com/u/shortishly)\
**Post date:** [December 4, 2022, 5:02pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/7 "2022-12-04T17:02:12Z")

</div>

> [@maxlapshin](#):
>
> this is very inconvenient for debugging. Do I understand you correctly that main idea of this inconvenience is reducing amount of things that can be attacked?

What sort of debug do you need?

- You can use [nsenter](https://man7.org/linux/man-pages/man1/nsenter.1.html) to run _any_ OS command within the context of the container. They don’t have to be in the container to run them.

- If you want to run an interactive command line on the running BEAM, then I would look at running a [ssh daemon](https://www.erlang.org/doc/man/ssh.html) within your application. Or embedding (shameless plug!) something like [shelly](https://github.com/shortishly/shelly) with your OTP application. That is usually my goto, usually with [recon](https://ferd.github.io/recon/) also installed.

Obviously, you also need to instrument your application so that you know what “good” (normal) looks like.

If you are on AWS then [SSM](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html) integrated with [IAM](https://aws.amazon.com/iam/) might also make sense. Other cloud providers probably have something similar to SSM.

One man’s inconvenience, is another’s convenience! I generally get the phone call at 3am when [log4shell](https://en.wikipedia.org/wiki/Log4Shell) is discovered asking whether “Can you be sure it isn’'t present in the container?”. My motivation is:

- “right size” containers that can run on low memory/bandwidth/footprint systems
- no unnecessary dependencies outside of the application (patching, security, bloat… etc).
- good sleep at night 🙂

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [December 4, 2022, 6:35pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/8 "2022-12-04T18:35:00Z")

</div>

No, my team haven’t migrated to OTP25 yet =(

Will check it, thanks

---

<div class="post-metadata">

**Author:** ![Hentioe](https://erlangforums.com/user_avatar/erlangforums.com/hentioe/32/2166_2.png) [@Hentioe](https://erlangforums.com/u/Hentioe)\
**Post date:** [November 26, 2023, 5:31pm UTC](https://erlangforums.com/t/beam-docker-release-github-action-a-github-action-to-build-a-docker-container-from-a-beam-elixir-erlang-release/2090/9 "2023-11-26T17:31:37Z")

</div>

I added the `+JPperf true` flag to build the Elixir image for the arm64 architecture, and the image size will increase significantly. I deleted the `jit-*.dump` and `perf-*.map` files in the `/tmp` path to reduce the size. But this phenomenon seems to only exist when building Elixir, and does not happen when building Elixir apps.
