-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
121 lines (92 loc) · 2.56 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
# STEP 1 - BUILD RELEASE
FROM hexpm/elixir:1.11.3-erlang-23.2.7-alpine-3.13.2 AS deps-getter
# Install build dependencies
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
git \
build-base \
nodejs-current \
nodejs-npm \
python3 && \
mix local.rebar --force && \
mix local.hex --force && \
npm install --global yarn
RUN mkdir /app
WORKDIR /app
ENV MIX_ENV=prod
RUN mkdir \
/app/_build/ \
/app/config/ \
/app/lib/ \
/app/priv/ \
/app/deps/ \
/app/rel/ \
/app/assets
# Install elixir package dependencies
COPY mix.exs /app/mix.exs
COPY mix.lock /app/mix.lock
# install deps and compile deps
COPY mix.exs /app/mix.exs
COPY mix.lock /app/mix.lock
RUN mix do deps.get --only $MIX_ENV, deps.compile
RUN mix compile
# STEP 2 - ASSET BUILDER
FROM node:12 AS asset-builder
RUN mkdir /app
WORKDIR /app
# install latest version of yarn
RUN npm i -g yarn --force
COPY --from=deps-getter /app/assets /app/assets
COPY --from=deps-getter /app/priv /app/priv
COPY --from=deps-getter /app/deps /app/deps
# assets -- install javascript deps
COPY assets/package.json /app/assets/package.json
COPY assets/yarn.lock /app/assets/yarn.lock
RUN cd /app/assets && \
yarn install
# assets -- copy asset files so purgecss doesnt remove css files
COPY lib/hangman_web/ /app/lib/hangman_web/
# assets -- build assets
COPY assets /app/assets
RUN cd /app/assets && yarn deploy
################################################################################
# STEP 3 - RELEASE BUILDER
FROM hexpm/elixir:1.11.3-erlang-23.2.7-alpine-3.13.2 AS release-builder
ENV MIX_ENV=prod
RUN mkdir /app
WORKDIR /app
# need to install deps again to run mix phx.digest
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
git \
build-base && \
mix local.rebar --force && \
mix local.hex --force
# copy elixir deps
COPY --from=deps-getter /app /app
# copy config, priv and release directories
COPY config /app/config
COPY priv /app/priv
# copy built assets
COPY --from=asset-builder /app/priv/static /app/priv/static
RUN mix phx.digest
# copy application code
COPY lib /app/lib
# create release
RUN mkdir -p /opt/built &&\
mix release &&\
cp -r _build/prod/rel/hangman /opt/built
################################################################################
## STEP 4 - FINAL
FROM alpine:3.11.3
ENV MIX_ENV=prod
RUN apk update && \
apk add --no-cache \
bash \
openssl-dev
COPY --from=release-builder /opt/built /app
WORKDIR /app
EXPOSE 4000
CMD ["/app/hangman/bin/hangman", "start"]