Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
111 lines (91 loc) · 3.83 KB
/
Copy pathDockerfile
File metadata and controls
111 lines (91 loc) · 3.83 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
ARG ELIXIR_VERSION=1.18
ARG OTP_VERSION=27.3
ARG DEBIAN_VERSION=bookworm-20250929-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
# Robusta: reuse the prebuilt pgdelta + libpg-query artifacts from the
# upstream supabase/realtime image instead of running the heavy
# pgdelta-builder stage (saves ~2GB peak RAM during the build).
FROM supabase/realtime:v2.96.0 AS pgdelta-source
FROM ${BUILDER_IMAGE} AS builder
ENV MIX_ENV="prod"
RUN apt-get update -y \
&& apt-get install curl -y \
&& apt-get install -y build-essential git \
&& apt-get clean
RUN set -uex; \
apt-get update; \
apt-get install -y ca-certificates curl 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; \
NODE_MAJOR=24; \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" \
> /etc/apt/sources.list.d/nodesource.list; \
apt-get -qy update; \
apt-get -qy install nodejs;
# prepare build dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# install mix dependencies
COPY mix.exs mix.lock ./
COPY beacon beacon
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
COPY priv priv
COPY lib lib
COPY assets assets
# compile assets with esbuild and npm
RUN cd assets \
&& npm install \
&& cd .. \
&& mix assets.deploy
# Compile the release
RUN mix compile
# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
COPY rel rel
RUN mix release
# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}
ARG SLOT_NAME_SUFFIX
ENV SLOT_NAME_SUFFIX="${SLOT_NAME_SUFFIX}" \
LANG="en_US.UTF-8" \
LANGUAGE="en_US:en" \
LC_ALL="en_US.UTF-8" \
MIX_ENV="prod" \
ECTO_IPV6="true" \
ERL_AFLAGS="-proto_dist inet6_tcp"
# Robusta: upgrade base packages so security fixes published after the
# pinned debian snapshot are included (e.g. gnutls, openssl, python3.11).
RUN apt-get update -y && \
apt-get upgrade -y --no-install-recommends && \
apt-get install -y --no-install-recommends \
libstdc++6 openssl libncurses5 locales iptables sudo tini curl awscli jq xz-utils && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Robusta: pgdelta artifacts copied from the upstream realtime image.
COPY --from=pgdelta-source /usr/local/share/pgdelta/pgdelta.xz /usr/local/share/pgdelta/pgdelta.xz
COPY --from=pgdelta-source /usr/local/bin/pgdelta /usr/local/bin/pgdelta
COPY --from=pgdelta-source /build/node_modules/.bun/@libpg-query+parser@17.6.3/node_modules/@libpg-query/parser/wasm/libpg-query.wasm /build/node_modules/.bun/@libpg-query+parser@17.6.3/node_modules/@libpg-query/parser/wasm/libpg-query.wasm
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
WORKDIR "/app"
RUN chown nobody:root /app && chmod g=u /app && \
mkdir -p /app/.pgdelta-cache && chown nobody:root /app/.pgdelta-cache && chmod g=u /app/.pgdelta-cache
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/realtime ./
COPY run.sh run.sh
# Robusta fork: make everything under /app group-accessible so OpenShift's
# arbitrary-UID model (random UID + supplemental gid 0) can read/execute
# the release and write to pgdelta-cache.
RUN chgrp -R 0 /app && chmod -R g=u /app
RUN ls -la /app
ENTRYPOINT ["/usr/bin/tini", "-s", "-g", "--", "/app/run.sh"]
CMD ["/app/bin/server"]