Skip to content

Commit 4808827

Browse files
committed
Riskier: Try to save mzdata
1 parent c958337 commit 4808827

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

misc/images/materialized-base/Dockerfile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ RUN apt-get update \
2929
ca-certificates \
3030
curl \
3131
gettext-base \
32+
haveged \
3233
nginx \
3334
postgresql \
34-
postgresql-contrib \
3535
tini \
3636
ssh \
37+
zstd \
3738
&& if [ "$CI_SANITIZER" != "none" ]; then \
3839
TZ=UTC DEBIAN_FRONTEND=noninteractive apt-get -qy install --no-install-recommends llvm; \
3940
fi \
4041
&& rm -rf /var/lib/apt/lists/* \
4142
&& apt-get clean \
42-
&& mkdir -p /mzdata /scratch /var/lib/postgresql/data /var/run/postgresql /var/lib/nginx /var/log/nginx \
43+
&& mkdir -p /mzdata /scratch /var/lib/postgresql/data /var/run/postgresql /var/lib/nginx /var/log/nginx /archive \
4344
&& touch /run/nginx.pid \
44-
&& chown -R materialize /mzdata /scratch /var/lib/postgresql/data /var/run/postgresql /var/log/postgresql /var/lib/postgresql/16/main /var/lib/nginx /var/log/nginx /run/nginx.pid
45+
&& chown -R materialize /mzdata /scratch /var/lib/postgresql/data /var/run/postgresql /var/log/postgresql /var/lib/postgresql/16/main /var/lib/nginx /var/log/nginx /run/nginx.pid /archive
4546

47+
COPY postgresql.conf pg_hba.conf /var/lib/postgresql/16/main/
4648
COPY postgresql.conf pg_hba.conf /etc/postgresql/16/main/
4749

4850
COPY --from=console /usr/share/nginx/html /usr/share/nginx/html
@@ -57,12 +59,3 @@ RUN MZ_ENDPOINT=http://localhost:6876 \
5759
&& rm /etc/nginx/templates/default.conf.template
5860

5961
USER materialize
60-
61-
RUN PGUSER=postgres pg_ctlcluster 16 main start \
62-
&& psql -U postgres -c "CREATE ROLE root WITH LOGIN PASSWORD 'root'" \
63-
&& psql -U postgres -c "CREATE DATABASE root OWNER root" \
64-
&& psql -U root -c "CREATE SCHEMA consensus" \
65-
&& psql -U root -c "CREATE SCHEMA storage" \
66-
&& psql -U root -c "CREATE SCHEMA adapter" \
67-
&& psql -U root -c "CREATE SCHEMA tsoracle" \
68-
&& pg_ctlcluster 16 main stop

src/materialized/ci/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ COPY materialized entrypoint.sh /usr/local/bin/
1515
USER root
1616
RUN ln -s /usr/local/bin/materialized /usr/local/bin/environmentd \
1717
&& ln -s /usr/local/bin/materialized /usr/local/bin/clusterd
18+
1819
USER materialize
1920

21+
RUN bash -c '\
22+
set -euo pipefail; \
23+
tini -- entrypoint.sh & \
24+
tini_pid=$!; \
25+
until curl -sf localhost:6878/api/readyz; do sleep 0.1; done; \
26+
pg_pid=$(cat /var/run/postgresql/16-main.pid); \
27+
kill -TERM "$pg_pid"; \
28+
kill -TERM "$tini_pid"; \
29+
wait "$tini_pid" || true; \
30+
while kill -0 "$pg_pid" 2> /dev/null; do sleep 0.1; done; \
31+
tar --zstd -cf /archive/mzdata.tar.zst -C / mzdata scratch; \
32+
'
33+
2034
ENTRYPOINT ["tini", "--", "entrypoint.sh"]

src/materialized/ci/entrypoint.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ EOF
4242
# Start PostgreSQL, unless suppressed.
4343
if [ -z "${MZ_NO_BUILTIN_POSTGRES:-}" ]; then
4444
rm -f /var/run/postgresql/.s.PGSQL.26257.lock
45-
PGUSER=postgres pg_ctlcluster 16 main start &
45+
/usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main &
46+
until psql -U postgres -c "SELECT 1" > /dev/null; do
47+
sleep 0.1;
48+
done
49+
psql -U postgres -c "CREATE ROLE root WITH LOGIN PASSWORD 'root'" || true
50+
psql -U postgres -c "CREATE DATABASE root OWNER root" || true
51+
psql -U root -c "CREATE SCHEMA IF NOT EXISTS consensus; CREATE SCHEMA IF NOT EXISTS storage; CREATE SCHEMA IF NOT EXISTS adapter; CREATE SCHEMA IF NOT EXISTS tsoracle"
4652
fi
4753

4854
# Start nginx to serve the console.
@@ -207,6 +213,10 @@ if [ -z "${MZ_NO_TELEMETRY:-}" ]; then
207213
export MZ_SEGMENT_CLIENT_SIDE=${MZ_SEGMENT_CLIENT_SIDE:-true}
208214
fi
209215

216+
if [ -z "$(find /mzdata -mindepth 1 -print -quit)" ]; then
217+
tar --zstd -xf /archive/mzdata.tar.zst -C /
218+
fi
219+
210220
if [ -n "${MZ_RESTART_ON_FAILURE:-}" ]; then
211221
for ((i = 0; i < ${MZ_RESTART_LIMIT:-9999999999}; i++)); do
212222
# Run `environmentd` inside of an `if` to avoid tripping `set -e`

0 commit comments

Comments
 (0)