forked from mirego/elixir-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
69 lines (51 loc) · 1.53 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
#
# Step 1 - build the OTP binary
#
FROM elixir:1.9-alpine AS builder
ARG APP_NAME
ARG APP_VERSION
ARG MIX_ENV=prod
ENV APP_NAME=${APP_NAME} \
APP_VERSION=${APP_VERSION} \
MIX_ENV=${MIX_ENV}
WORKDIR /build
# This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache nodejs~=10.14 npm~=10.14 git build-base
RUN mix local.rebar --force && \
mix local.hex --force
# This copies our app source code into the build container
COPY mix.* ./
RUN mix deps.get --only ${MIX_ENV}
COPY . .
RUN mix compile
RUN npm ci --prefix assets --no-audit --no-color --unsafe-perm
# Compile assets and generate digest filenames
RUN npm run --prefix assets deploy
RUN mix phx.digest
RUN mkdir -p /opt/build && \
mix release && \
cp -R _build/${MIX_ENV}/rel/${APP_NAME}/* /opt/build
#
# Step 2 - build a lean runtime container
#
FROM alpine:3.9
ARG APP_NAME
ENV APP_NAME=${APP_NAME}
# Update kernel and install runtime dependencies
RUN apk --no-cache update && \
apk --no-cache upgrade && \
apk --no-cache add bash openssl-dev erlang-crypto
WORKDIR /opt/elixir_boilerplate
# Copy the OTP binary from the build step
COPY --from=builder /opt/build .
# Copy the entrypoint script
COPY priv/scripts/docker-entrypoint.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh
# Create a non-root user
RUN adduser -D elixir_boilerplate && \
chown -R elixir_boilerplate: /opt/elixir_boilerplate
USER elixir_boilerplate
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["start"]