1+ ARG NODEJS_VERSION=22-bookworm-slim
2+ ARG ELIXIR_VERSION=1.18.1
3+ ARG OTP_VERSION=27.2
4+ ARG DEBIAN_VERSION=bookworm-20241223-slim
5+
6+ ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
7+ ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
8+
19# -----------------------------------------------
210# Stage: npm dependencies
311# -----------------------------------------------
4- FROM node:20.5-bookworm-slim AS npm-builder
12+ FROM node:${NODEJS_VERSION} AS npm-builder
513
614# Install Debian dependencies
715RUN apt-get update -y && \
@@ -16,44 +24,51 @@ COPY assets assets
1624RUN npm ci --prefix assets
1725
1826# -----------------------------------------------
19- # Stage: hex dependencies
27+ # Stage: hex dependencies + OTP release
2028# -----------------------------------------------
21- FROM hexpm/elixir:1.15.5-erlang-26.0.2-debian-bookworm-20230612-slim AS otp -builder
29+ FROM ${BUILDER_IMAGE} AS hex -builder
2230
23- # Install Debian dependencies
31+ # install build dependencies
2432RUN apt-get update -y && \
2533 apt-get install -y build-essential git && \
2634 apt-get clean && \
2735 rm -f /var/lib/apt/lists/*_*
2836
37+ # prepare build dir
2938WORKDIR /app
3039
31- # Install Erlang dependencies
32- RUN mix local.rebar --force && \
33- mix local.hex --force
40+ ENV MIX_ENV=prod
41+ ENV ERL_FLAGS="+JPperf true"
42+
43+ # install hex + rebar
44+ RUN mix local.hex --force && \
45+ mix local.rebar --force
3446
47+ # set build ENV
3548ENV MIX_ENV="prod"
3649
37- # Install mix dependencies
50+ # install mix dependencies
3851COPY mix.exs mix.lock ./
3952RUN mix deps.get --only $MIX_ENV
4053
41- # Copy compile-time config files before we compile dependencies
54+ # copy compile-time config files before we compile dependencies
4255# to ensure any relevant config change will trigger the dependencies
4356# to be re-compiled.
4457RUN mkdir config
4558COPY config/config.exs config/${MIX_ENV}.exs config/
46-
47- # Compile mix dependencies
4859RUN mix deps.compile
4960
50- # Compile assets
61+ # install Esbuild so it is cached
62+ RUN mix esbuild.install --if-missing
63+
64+ COPY lib lib
5165COPY --from=npm-builder /app/assets assets
5266COPY priv priv
67+
68+ # Compile assets
5369RUN mix assets.deploy
5470
55- # Compile code
56- COPY lib lib
71+ # Compile the release
5772RUN mix compile
5873
5974# Changes to config/runtime.exs don't require recompiling the code
@@ -65,25 +80,27 @@ RUN mix release
6580# -----------------------------------------------
6681# Stage: Bundle release in a docker image
6782# -----------------------------------------------
68- FROM debian:bookworm-20230612-slim
83+ FROM ${RUNNER_IMAGE}
6984
7085RUN apt-get update -y && \
71- apt-get install -y libstdc++6 openssl libncurses5 locales && \
72- apt-get clean && \
73- rm -f /var/lib/apt/lists/*_*
86+ apt-get install -y curl jq libstdc++6 openssl libncurses5 locales && \
87+ apt-get clean && \
88+ rm -f /var/lib/apt/lists/*_*
7489
7590# Set the locale
7691RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
7792
78- ENV LANG en_US.UTF-8
79- ENV LANGUAGE en_US:en
80- ENV LC_ALL en_US.UTF-8
81-
8293WORKDIR "/app"
8394RUN chown nobody /app
8495
96+ # set runner ENV
97+ ENV LANG=en_US.UTF-8
98+ ENV LANGUAGE=en_US:en
99+ ENV LC_ALL=en_US.UTF-8
100+ ENV MIX_ENV="prod"
101+
85102# Only copy the final release from the build stage
86- COPY --from=otp -builder --chown=nobody:root /app/_build/prod /rel/elixir_boilerplate ./
103+ COPY --from=hex -builder --chown=nobody:root /app/_build/${MIX_ENV} /rel/elixir_boilerplate ./
87104
88105USER nobody
89106
0 commit comments