-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile
More file actions
97 lines (72 loc) · 3.33 KB
/
Copy pathDockerfile
File metadata and controls
97 lines (72 loc) · 3.33 KB
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
# Multi-stage Dockerfile for the deflua.com website.
#
# Build context MUST be the lua/ repo root (parent of website/) so the
# `{:lua, path: ".."}` path dependency is reachable from inside the image.
#
# From the repo root:
# docker build -t deflua .
# fly deploy # fly.toml lives next to this Dockerfile
ARG ELIXIR_VERSION=1.19.4
ARG OTP_VERSION=28.3.3
ARG DEBIAN_VERSION=bookworm-20260518-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} AS builder
RUN apt-get update -y && apt-get install -y build-essential git curl ca-certificates gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -y && apt-get install -y nodejs \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# Mirror the on-disk layout so `{:lua, path: ".."}` in website/mix.exs
# resolves correctly: website lives at /app/website, lua at /app.
WORKDIR /app
ENV MIX_ENV="prod"
RUN mix local.hex --force && mix local.rebar --force
# Lua package: only the files mix needs to compile the dep.
# README.md is read at compile time by lib/lua.ex (@external_resource).
COPY mix.exs mix.lock README.md ./
COPY lib ./lib
# Website mix files first so deps.get is cached when only app code changes.
COPY website/mix.exs website/mix.lock ./website/
WORKDIR /app/website
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
COPY website/config/config.exs website/config/${MIX_ENV}.exs config/
RUN mix deps.compile
# Install npm deps separately from app code so they cache.
# package.json references `../deps/phoenix` etc., so deps/ must already exist
# (it does — `mix deps.get` ran above).
COPY website/assets/package.json website/assets/package-lock.json assets/
RUN cd assets && npm ci --no-audit --no-fund --progress=false
COPY website/priv priv
COPY website/lib lib
COPY website/assets assets
# Recorded benchmark results, read at compile time by lib/website/benchmarks.ex
# (@external_resource) to render /benchmarks. Compile fails loudly without it.
COPY bench_results /app/bench_results
# mix compile must run BEFORE assets.deploy because Phoenix's LiveView
# colocated-hooks compiler generates files under _build/ that esbuild
# resolves via NODE_PATH (`phoenix-colocated/website`).
RUN mix compile
RUN mix assets.deploy
COPY website/config/runtime.exs config/
COPY website/rel rel
# Belt-and-suspenders: ensure the overlay script is exec'able regardless of
# the source-tree mode it was checked out with.
RUN chmod +x rel/overlays/bin/server && mix release
# ---- Runtime image ----
FROM ${RUNNER_IMAGE}
RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses6 locales ca-certificates curl && \
apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
WORKDIR /app
RUN chown nobody /app
ENV MIX_ENV="prod"
COPY --from=builder --chown=nobody:root /app/website/_build/${MIX_ENV}/rel/website ./
USER nobody
CMD ["/app/bin/server"]