1+ # Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
2+ # instead of Alpine to avoid DNS resolution issues in production.
3+ #
4+ # https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
5+ # https://hub.docker.com/_/ubuntu?tab=tags
6+ #
7+ # This file is based on these images:
8+ #
9+ # - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
10+ # - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240904-slim - for the release image
11+ # - https://pkgs.org/ - resource for finding needed packages
12+ # - Ex: hexpm/elixir:1.17.3-erlang-27.0.1-debian-bullseye-20240904-slim
13+ #
114ARG ELIXIR_VERSION=1.17.3
2- ARG OTP_VERSION=27.1
3- ARG ALPINE_VERSION=3.19.3
15+ ARG OTP_VERSION=27.0. 1
16+ ARG DEBIAN_VERSION=bullseye-20240904-slim
417
5- ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-alpine -${ALPINE_VERSION }"
6- ARG RUNNER_IMAGE="alpine :${ALPINE_VERSION }"
18+ ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian -${DEBIAN_VERSION }"
19+ ARG RUNNER_IMAGE="debian :${DEBIAN_VERSION }"
720
821FROM ${BUILDER_IMAGE} as builder
9- ENV MIX_ENV="prod"
1022
23+ # install build dependencies
24+ RUN apt-get update -y && apt-get install -y build-essential git \
25+ && apt-get clean && rm -f /var/lib/apt/lists/*_*
26+
27+ # prepare build dir
1128WORKDIR /app
1229
13- # install build tools
30+ # install hex + rebar
1431RUN mix local.hex --force && \
1532 mix local.rebar --force
1633
34+ # set build ENV
35+ ENV MIX_ENV="prod"
36+
1737# install mix dependencies
1838COPY mix.exs mix.lock ./
1939RUN mix deps.get --only $MIX_ENV
2040RUN mkdir config
2141
22- # Copy files
42+ # copy compile-time config files before we compile dependencies
43+ # to ensure any relevant config change will trigger the dependencies
44+ # to be re-compiled.
2345COPY config/config.exs config/${MIX_ENV}.exs config/
46+ RUN mix deps.compile
47+
2448COPY priv priv
49+
2550COPY lib lib
2651
27- # Compile then create binary
52+ # Compile the release
2853RUN mix compile
29- RUN mix release
3054
55+ # Changes to config/runtime.exs don't require recompiling the code
3156COPY config/runtime.exs config/
3257
58+ COPY rel rel
59+ RUN mix release
60+
61+ # start a new build stage so that the final image will only contain
62+ # the compiled release and other runtime necessities
3363FROM ${RUNNER_IMAGE}
3464
65+ RUN apt-get update -y && \
66+ apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
67+ && apt-get clean && rm -f /var/lib/apt/lists/*_*
68+
3569# Set the locale
70+ RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
71+
3672ENV LANG en_US.UTF-8
3773ENV LANGUAGE en_US:en
3874ENV LC_ALL en_US.UTF-8
@@ -48,4 +84,9 @@ COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/timecopsync_p
4884
4985USER nobody
5086
51- CMD ["/app/bin/server" ]
87+ # If using an environment that doesn't automatically reap zombie processes, it is
88+ # advised to add an init process such as tini via `apt-get install`
89+ # above and adding an entrypoint. See https://github.com/krallin/tini for details
90+ # ENTRYPOINT ["/tini", "--"]
91+
92+ CMD ["/app/bin/server" ]
0 commit comments