-
-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathDockerfile
More file actions
133 lines (112 loc) · 4.32 KB
/
Dockerfile
File metadata and controls
133 lines (112 loc) · 4.32 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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}"
# @supabase/pg-delta@1.0.0-alpha.24
ARG PG_DELTA_COMMIT=102ef99ae5aabb29510d48b39fbb8ecee34f5458
FROM debian:${DEBIAN_VERSION} AS pgdelta-builder
ARG PG_DELTA_COMMIT
ARG BUN_VERSION=1.3.14
RUN set -eux; \
apt-get update -y; \
apt-get install -y --no-install-recommends curl ca-certificates unzip xz-utils; \
curl -fsSL https://bun.sh/install | bash -s "bun-v${BUN_VERSION}"; \
export PATH="/root/.bun/bin:${PATH}"; \
mkdir -p /build && cd /build; \
curl -fsSL "https://github.com/supabase/pg-toolbelt/archive/${PG_DELTA_COMMIT}.tar.gz" \
| tar xz --strip-components=1; \
bun install --frozen-lockfile --ignore-scripts; \
cd /build/packages/pg-delta; \
bun build --compile src/cli/bin/cli.ts --outfile /tmp/pgdelta; \
/tmp/pgdelta --help > /dev/null; \
xz -9 -e -T0 -c /tmp/pgdelta > /tmp/pgdelta.xz; \
cd / && find build -path '*/@libpg-query/parser/wasm/libpg-query.wasm' \
| tar -czf /tmp/libpg-query.tar.gz -T -; \
printf '%s\n' \
'#!/bin/sh' \
'set -e' \
'BIN=/app/.pgdelta-cache/pgdelta' \
'if [ ! -x "$BIN" ]; then' \
' mkdir -p "$(dirname "$BIN")"' \
' xz -dcT0 /usr/local/share/pgdelta/pgdelta.xz > "$BIN"' \
' chmod +x "$BIN"' \
'fi' \
'exec "$BIN" "$@"' \
> /tmp/pgdelta-wrapper; \
chmod +x /tmp/pgdelta-wrapper; \
rm -rf /tmp/pgdelta /build /root/.bun /var/lib/apt/lists/*
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"
RUN apt-get update -y && \
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/*
COPY --from=pgdelta-builder /tmp/pgdelta.xz /usr/local/share/pgdelta/pgdelta.xz
COPY --from=pgdelta-builder /tmp/pgdelta-wrapper /usr/local/bin/pgdelta
COPY --from=pgdelta-builder /tmp/libpg-query.tar.gz /tmp/libpg-query.tar.gz
RUN tar -C / -xzf /tmp/libpg-query.tar.gz && rm /tmp/libpg-query.tar.gz
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
WORKDIR "/app"
RUN chown nobody /app && mkdir -p /app/.pgdelta-cache && chown nobody /app/.pgdelta-cache
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/realtime ./
COPY run.sh run.sh
RUN ls -la /app
ENTRYPOINT ["/usr/bin/tini", "-s", "-g", "--", "/app/run.sh"]
CMD ["/app/bin/server"]