91 lines
2.4 kB
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-20230612-slim - for the release image
11
# - https://pkgs.org/ - resource for finding needed packages
12
# - Ex: hexpm/elixir:1.15.7-erlang-26.0.2-debian-bullseye-20230612-slim
13
#
14
ARG ELIXIR_VERSION=1.15.7
15
ARG OTP_VERSION=26.0.2
16
ARG DEBIAN_VERSION=bullseye-20230612-slim
17
18
ARG BUILDER_IMAGE="hexpm/elixir:1.15.7-erlang-26.1.2-debian-bullseye-20231009-slim"
19
ARG RUNNER_IMAGE="debian:bullseye-20231009-slim"
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 && apt-get install -y libstdc++6 openssl libncurses5 locales imagemagick \
71
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
72
73
# Set the locale
74
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
75
76
ENV LANG en_US.UTF-8
77
ENV LANGUAGE en_US:en
78
ENV LC_ALL en_US.UTF-8
79
80
WORKDIR "/app"
81
RUN chown nobody /app
82
83
# Set runner ENV
84
ENV MIX_ENV="prod"
85
86
# Only copy the final release from the build stage
87
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/blog ./
88
89
USER nobody
90
91
CMD ["/app/bin/server"]