-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
57 lines (54 loc) · 1.71 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
ARG VERSION_ELIXIR=1.15.4
ARG VERSION_ERLANG=26.0.2
ARG VERSION_OS=3.18.2
ARG IMAGE_BUILDER="hexpm/elixir:${VERSION_ELIXIR}-erlang-${VERSION_ERLANG}-alpine-${VERSION_OS}"
ARG IMAGE_RUNNER="alpine:${VERSION_OS}"
# loosely based off https://blog.logrocket.com/run-phoenix-application-docker/
# =============================================================================
# Build the Alpine-based image
# =============================================================================
FROM ${IMAGE_BUILDER} as builder
# Install NodeJS 18, and NPM
RUN apk -U upgrade && \
apk add alpine-sdk argon2-dev nodejs npm
WORKDIR /app
# Install Hex and Rebar3
RUN mix local.hex --force && \
mix local.rebar --force
# Start building the prod environment
ENV MIX_ENV="prod"
# Packages and lockfile
COPY mix.exs mix.lock ./
# Only get production dependencies
RUN mix deps.get --only $MIX_ENV
# Copy over config
RUN mkdir config
COPY config/config.exs config/${MIX_ENV}.exs config/
# Compile dependencies
RUN mix deps.compile
# Copy priv/, lib/, and assets/
COPY priv priv
COPY lib lib
COPY assets assets
# Deploy assets, compile main codebase
RUN mix assets.deploy
RUN mix compile
# Release prepare and build
COPY config/runtime.exs config/
COPY rel rel
RUN mix release
# =============================================================================
# Runnner image
# =============================================================================
FROM ${IMAGE_RUNNER}
RUN apk -U upgrade && \
apk add libstdc++ ncurses openssl
WORKDIR /app
RUN chown nobody /app
# Set to prod again
ENV MIX_ENV="prod"
# Copy /app as nobody
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/exfwghtblog ./
USER nobody
# Run
CMD ["/app/bin/exfwghtblog"]