-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
128 lines (100 loc) · 2.77 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
# STEP 1 - DEPS GETTER
FROM elixir:1.9-alpine AS deps-getter
# setup up variables
ARG APP_NAME
ARG APP_VSN
ARG PHOENIX_SUBDIR=.
ENV APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN}
# make directory
RUN mkdir /app
WORKDIR /app
# This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
git \
build-base && \
mix local.rebar --force && \
mix local.hex --force
# elixir create diretories
ENV MIX_ENV=prod
RUN mkdir \
/app/_build/ \
/app/config/ \
/app/lib/ \
/app/priv/ \
/app/deps/ \
/app/rel/ \
/app/assets
# 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:10 AS asset-builder
RUN mkdir /app
WORKDIR /app
ENV NODE_ENV=production
# install latest version of yarn and bs-platform
RUN npm i -g yarn
RUN npm install -g bs-platform --unsafe-perm
RUN npm link bs-platform
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 -- build assets
COPY assets /app/assets
RUN cd /app/assets && bsb -make-world -clean-world
COPY lib/spyfall_web/templates/ /app/lib/spyfall_web/templates/
RUN cd /app/assets && yarn deploy
################################################################################
# STEP 3 - RELEASE BUILDER
FROM elixir:1.9-alpine AS release-builder
ENV MIX_ENV=prod
RUN mkdir /app
WORKDIR /app
# setup up variables
ARG APP_NAME
ARG APP_VSN
ENV APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN}
# 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 --from=deps-getter /app /app
COPY --from=asset-builder /app/priv/static /app/priv/static
# copy config, priv and release directories
COPY config /app/config
COPY priv /app/priv
COPY rel /app/rel
RUN mix phx.digest
# copy application code
COPY lib /app/lib
# create release
RUN mkdir -p /opt/built &&\
mix release ${APP_NAME} &&\
cp -r _build/prod/rel/${APP_NAME} /opt/built
################################################################################
## STEP 4 - FINAL
FROM alpine:3.9
ENV MIX_ENV=prod
RUN apk update && \
apk add --no-cache \
bash \
openssl-dev
COPY --from=release-builder /opt/built /app
WORKDIR /app
CMD ["/app/spyfall/bin/spyfall", "start"]