-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
91 lines (67 loc) · 2.33 KB
/
Copy pathDockerfile
File metadata and controls
91 lines (67 loc) · 2.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
# Production Dockerfile for Fly.io deployment
# Based on Phoenix 1.8 release template
#
# Uses official elixir images (same as devcontainer) for better compatibility
ARG NODE_IMAGE="node:22-slim"
ARG BUILDER_IMAGE="elixir:1.19-otp-27-slim"
ARG RUNNER_IMAGE="debian:bookworm-slim"
# Get Node.js from official image (avoids curl | bash supply chain risk)
FROM ${NODE_IMAGE} as node
FROM ${BUILDER_IMAGE} as builder
# Copy Node.js from official image (copy node_modules first, then create symlinks)
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node /usr/local/bin/node /usr/local/bin/node
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
# Install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# Prepare build dir
WORKDIR /app
# Install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# Set build ENV
ENV MIX_ENV="prod"
# Install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
# Copy compile-time config files
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
# Build assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci
COPY priv priv
COPY assets assets
COPY lib lib
# Compile assets
RUN npm --prefix ./assets run build
RUN mix assets.deploy
# Compile the release
COPY config/runtime.exs config/
RUN mix compile
# Build release
COPY rel rel
RUN mix release
# Runner stage
FROM ${RUNNER_IMAGE}
RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
WORKDIR "/app"
RUN chown nobody /app
# Set runner ENV
ENV MIX_ENV="prod"
# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/reify ./
USER nobody
# If using an environment that doesn't automatically reap zombie processes, it is
# advised to add an init system such as tini via `CMD ["/tini", "--", "bin/server"]`
CMD ["/app/bin/server"]