-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
147 lines (102 loc) · 3.36 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# syntax = docker/dockerfile:1.0-experimental
# This Dockerfile was generated by [dockerize](https://hex.pm/packages/dockerize)
# at 2021-09-26 07:45:19.368523Z
# with `mix dockerize.init --app phoenix_app`
# It leverages multi-stage-building of docker to build as fast as possible.
# How stages work together: https://user-images.githubusercontent.com/43009/84713978-e59a2700-af9e-11ea-9bbd-9dcf28d23da7.png
# You are free to edit this dockerfile.
# -----------------------------------
# Base Image #1: Elixir Builder
# - This is used for building later
# docker image, with a development
# toolset.
# -----------------------------------
FROM hexpm/elixir:1.12.2-erlang-24.1-debian-buster-20210902 AS elixir-builder
# If you're using a hex mirror:
# ENV HEX_MIRROR=https://my_hex_mirror
RUN mix local.hex --force
RUN mix local.rebar --force
RUN mkdir -p /root/.config/rebar3 && \
echo '{plugins, [rebar3_hex]}.' > /root/.config/rebar3/rebar.config
RUN /root/.mix/rebar3 plugins upgrade rebar3_hex
# -----------------------------------
# Base Image #2: Elixir Runner
# - Elixir Application Runner
# This is used as a simple operating
# system image to host your
# application
# -----------------------------------
FROM debian:buster as elixir-runner
# You can add any libraries required by your application
# here:
RUN apt-get update && \
apt-get install -y \
# If you're using `:crypto`, you'll need openssl installed \
libssl-dev \
locales
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
# -----------------------------------
# - stage: install
# - job: dependencies
# -----------------------------------
FROM elixir-builder AS deps
ENV MIX_ENV=prod
# If you're using a hex mirror:
# ENV HEX_MIRROR=https://my_hex_mirror
WORKDIR /src
COPY config /src/config
COPY mix.exs mix.lock /src/
# If inside an umbrella project, you also need to add all `mix.exs`
# e.g
# COPY apps/my_app_1/mix.exs /src/apps/my_app_1/mix.exs
# COPY apps/my_app_2/mix.exs /src/apps/my_app_2/mix.exs
# If you're using your own organization on hex.pm, uncomment the
# following lines:
# ENV HEX_AUTH_KEY
# RUN mix hex.organization auth my_org --key ${HEX_AUTH_KEY}
RUN mix deps.get --only $MIX_ENV
# -----------------------------------
# - stage: build
# - job: compile_deps
# -----------------------------------
FROM deps AS compile_deps
WORKDIR /src
ENV MIX_ENV=prod
RUN mix deps.compile
# -----------------------------------
# - stage: build
# - job: compile_app
# -----------------------------------
FROM compile_deps AS compile_app
WORKDIR /src
ENV MIX_ENV=prod
COPY lib/ ./lib
# You may add other directories crucial for compiling, for example:
# COPY priv/ ./priv
RUN mix compile
# -----------------------------------
# - stage: release
# - job: mix_release
# -----------------------------------
FROM compile_app AS mix_release
WORKDIR /src
ENV MIX_ENV=prod
RUN mix release --path /app --quiet
# -----------------------------------
# - stage: release
# - job: release_image
# -----------------------------------
FROM elixir-runner AS release_image
# If you need to inject the app revision into the container,
# uncomment below:
# ARG APP_REVISION=latest
ENV MIX_ENV=prod
USER nobody
COPY --from=mix_release --chown=nobody:nogroup /app /app
WORKDIR /app
ENTRYPOINT ["/app/bin/phoenix_app"]
CMD ["start"]