forked from mbta/dotcom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
85 lines (58 loc) · 2.41 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
###
# Three-stage Dockerfile
###
# 1.) Get the Elixir dependencies within an Elixir container
FROM hexpm/elixir:1.16.2-erlang-26.2.5-debian-buster-20240423-slim as elixir-builder
ENV LANG="C.UTF-8" MIX_ENV="prod"
WORKDIR /root
# Debian dependencies
RUN apt-get update --allow-releaseinfo-change && apt-get install -y curl git make build-essential
# Configure Git to use HTTPS in order to avoid issues with the internal MBTA network
RUN git config --global url.https://github.com/.insteadOf git://github.com/
# Install Hex+Rebar
RUN mix local.hex --force && \
mix local.rebar --force
ADD . .
RUN mix deps.get --only prod
# 2) Build the frontend assets within a node.js container instead of installing node/npm
FROM node:18.17.1-buster as assets-builder
# Stop cypress from downloading it's massive binary.
ENV CYPRESS_INSTALL_BINARY=0
ARG SENTRY_DSN=""
# copy in Elixir deps required to build node modules for Phoenix
COPY --from=elixir-builder /root/deps /root/deps
# copy in static assets
ADD ./priv/static/icon-svg /root/priv/static/icon-svg
ADD ./assets /root/assets
WORKDIR /root/assets
RUN npm ci --ignore-scripts
# Compile JS/CSS, copy images and fonts to priv/static
RUN npm run webpack:build -- --env SENTRY_DSN=$SENTRY_DSN
# Create react_renderer/dist/app.js
RUN npm run webpack:build:react
# 3) now, build the application back in the Elixir container
FROM elixir-builder as app-builder
WORKDIR /root
# Add frontend assets, required by phx.digest
COPY --from=assets-builder /root/priv/static ./priv/static
# re-compile the application after the assets are copied, since some of them
# are built into the application (SVG icons)
RUN mix do compile, phx.digest
RUN mix release
# 4) Use the nodejs container for the runtime environment
# Since we're server-rendering the React templates, we need a Javascript engine running inside the container.
FROM node:18.17.1-buster-slim
# Set exposed ports
EXPOSE 4000
ENV PORT=4000 MIX_ENV="prod" PHX_SERVER=true TERM=xterm LANG="C.UTF-8" REPLACE_OS_VARS=true
# erlang-crypto requires system library libssl1.1
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl1.1 libsctp1 curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /root
COPY --from=app-builder /root/_build/prod/rel /root/rel
COPY --from=assets-builder /root/react_renderer/dist/app.js /root/rel/dotcom/app.js
RUN mkdir /root/work
WORKDIR /root/work
# run the application
CMD ["/root/rel/dotcom/bin/dotcom", "start"]