-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
113 lines (87 loc) · 2.68 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
ARG ELIXIR_VERSION="1.14.3"
ARG ERLANG_VERSION="25.3"
ARG ALPINE_VERSION="3.17.2"
# NOTE: "We use Ubuntu/Debian instead of Alpine to avoid DNS resolution issues in production."
# from generated Dockerfile by Phoenix.
# For the moment, let's try Alpine anyway.
# Check which version is available on https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=1.14.3-erlang-25.3-alpine.
#
# ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-debian-bullseye-20210902-slim"
# ARG RUNNER_IMAGE="debian:bullseye-20210902-slim"
#
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION}"
ARG RUNNER_IMAGE="alpine:${ALPINE_VERSION}"
############
### deps ###
############
FROM ${BUILDER_IMAGE} AS deps
WORKDIR /app
RUN apk add --no-cache --update --no-progress \
git build-base
ARG MIX_ENV="prod"
# install rebar & hex
RUN mix local.rebar --force && \
mix local.hex --force
# install elixir dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only ${MIX_ENV}
# compile elixir dependencies
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
####################
### build-elixir ###
####################
FROM deps AS build-elixir
COPY lib lib
ARG MIX_ENV="prod"
RUN mix compile
####################
### build-assets ###
####################
FROM deps AS build-assets
# install Nodejs
ARG NODE_VERSION="19.7.0"
RUN apk add --no-cache --update --no-progress \
nodejs-current=~${NODE_VERSION} npm && \
npm i -g npm
# install npm dependencies
COPY assets/package.json assets/package-lock.json assets/
RUN npm install --prefix assets --no-fund --no-audit
ARG MIX_ENV="prod"
# install Tailwind
RUN mix assets.setup
COPY priv priv
# NOTE: 'lib' is needed to see Tailwind classes usage in the code
COPY lib lib
COPY assets assets
RUN mix assets.deploy
###############
### release ###
###############
FROM build-elixir AS release
COPY rel rel
COPY --from=build-assets /app/priv priv
# NOTE: Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
ARG MIX_ENV="prod"
RUN mix release
############################
### runner (final image) ###
############################
FROM ${RUNNER_IMAGE}
WORKDIR /app
RUN chown nobody /app
RUN apk add --no-cache --update --no-progress \
libstdc++ openssl ncurses-libs
# NOTE: Set the locale
# RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ARG MIX_ENV="prod"
COPY --from=release --chown=nobody:root /app/_build/${MIX_ENV}/rel/svoenix .
USER nobody
CMD ["/app/bin/server"]
# Appended by flyctl
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"