+96
Dockerfile
+96
Dockerfile
···
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-20210902-slim - for the release image
11
+
# - https://pkgs.org/ - resource for finding needed packages
12
+
# - Ex: hexpm/elixir:1.14.0-erlang-25.0.4-debian-bullseye-20210902-slim
13
+
#
14
+
ARG ELIXIR_VERSION=1.16.0
15
+
ARG OTP_VERSION=26.2.1
16
+
ARG DEBIAN_VERSION=bullseye-20231009-slim
17
+
18
+
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
19
+
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
20
+
21
+
FROM ${BUILDER_IMAGE} as builder
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
28
+
WORKDIR /app
29
+
30
+
# install hex + rebar
31
+
RUN mix local.hex --force && \
32
+
mix local.rebar --force
33
+
34
+
# set build ENV
35
+
ENV MIX_ENV="prod"
36
+
37
+
# install mix dependencies
38
+
COPY mix.exs mix.lock ./
39
+
RUN mix deps.get --only $MIX_ENV
40
+
RUN mkdir config
41
+
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.
45
+
COPY config/config.exs config/${MIX_ENV}.exs config/
46
+
RUN mix deps.compile
47
+
48
+
COPY priv priv
49
+
50
+
COPY lib lib
51
+
52
+
COPY assets assets
53
+
54
+
# compile assets
55
+
RUN mix assets.deploy
56
+
57
+
# Compile the release
58
+
RUN mix compile
59
+
60
+
# Changes to config/runtime.exs don't require recompiling the code
61
+
COPY config/runtime.exs config/
62
+
63
+
COPY rel rel
64
+
RUN mix release
65
+
66
+
# start a new build stage so that the final image will only contain
67
+
# the compiled release and other runtime necessities
68
+
FROM ${RUNNER_IMAGE}
69
+
70
+
RUN apt-get update -y && \
71
+
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
72
+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
73
+
74
+
# Set the locale
75
+
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
76
+
77
+
ENV LANG en_US.UTF-8
78
+
ENV LANGUAGE en_US:en
79
+
ENV LC_ALL en_US.UTF-8
80
+
81
+
WORKDIR "/app"
82
+
RUN chown nobody /app
83
+
84
+
# set runner ENV
85
+
ENV MIX_ENV="prod"
86
+
87
+
# Only copy the final release from the build stage
88
+
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/elixir_blonk ./
89
+
90
+
USER nobody
91
+
92
+
# If using a startup script, copy it over
93
+
# COPY --from=builder --chown=nobody:root /app/bin/server /app/bin/migrate ./bin/
94
+
95
+
CMD ["/app/bin/server"]
96
+