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
+ #
1
14
ARG 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
4
17
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 }"
7
20
8
21
FROM ${BUILDER_IMAGE} as builder
9
- ENV MIX_ENV="prod"
10
22
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
11
28
WORKDIR /app
12
29
13
- # install build tools
30
+ # install hex + rebar
14
31
RUN mix local.hex --force && \
15
32
mix local.rebar --force
16
33
34
+ # set build ENV
35
+ ENV MIX_ENV="prod"
36
+
17
37
# install mix dependencies
18
38
COPY mix.exs mix.lock ./
19
39
RUN mix deps.get --only $MIX_ENV
20
40
RUN mkdir config
21
41
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.
23
45
COPY config/config.exs config/${MIX_ENV}.exs config/
46
+ RUN mix deps.compile
47
+
24
48
COPY priv priv
49
+
25
50
COPY lib lib
26
51
27
- # Compile then create binary
52
+ # Compile the release
28
53
RUN mix compile
29
- RUN mix release
30
54
55
+ # Changes to config/runtime.exs don't require recompiling the code
31
56
COPY config/runtime.exs config/
32
57
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
33
63
FROM ${RUNNER_IMAGE}
34
64
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
+
35
69
# Set the locale
70
+ RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
71
+
36
72
ENV LANG en_US.UTF-8
37
73
ENV LANGUAGE en_US:en
38
74
ENV LC_ALL en_US.UTF-8
@@ -48,4 +84,9 @@ COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/timecopsync_p
48
84
49
85
USER nobody
50
86
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