2022-08-23 13:10:29 +02:00
|
|
|
#syntax=docker/dockerfile:1.2
|
|
|
|
|
2024-08-02 08:35:38 +02:00
|
|
|
FROM golang:1.22-bookworm as build
|
2022-02-11 13:35:47 +01:00
|
|
|
RUN apt-get update && apt-get install -y postgresql
|
|
|
|
WORKDIR /build
|
|
|
|
|
2024-08-02 08:35:38 +02:00
|
|
|
# No password when connecting to Postgres
|
|
|
|
RUN sed -i "s%peer%trust%g" /etc/postgresql/15/main/pg_hba.conf && \
|
2022-02-11 13:35:47 +01:00
|
|
|
# Bump up max conns for moar concurrency
|
2024-08-02 08:35:38 +02:00
|
|
|
sed -i 's/max_connections = 100/max_connections = 2000/g' /etc/postgresql/15/main/postgresql.conf
|
2022-02-11 13:35:47 +01:00
|
|
|
|
|
|
|
# This entry script starts postgres, waits for it to be up then starts dendrite
|
|
|
|
RUN echo '\
|
2022-07-11 15:31:31 +02:00
|
|
|
#!/bin/bash -eu \n\
|
|
|
|
pg_lsclusters \n\
|
2024-08-02 08:35:38 +02:00
|
|
|
pg_ctlcluster 15 main start \n\
|
2022-07-11 15:31:31 +02:00
|
|
|
\n\
|
|
|
|
until pg_isready \n\
|
|
|
|
do \n\
|
|
|
|
echo "Waiting for postgres"; \n\
|
|
|
|
sleep 1; \n\
|
|
|
|
done \n\
|
|
|
|
' > run_postgres.sh && chmod +x run_postgres.sh
|
2022-02-11 13:35:47 +01:00
|
|
|
|
|
|
|
# we will dump the binaries and config file to this location to ensure any local untracked files
|
|
|
|
# that come from the COPY . . file don't contaminate the build
|
|
|
|
RUN mkdir /dendrite
|
|
|
|
|
|
|
|
# Utilise Docker caching when downloading dependencies, this stops us needlessly
|
|
|
|
# downloading dependencies every time.
|
2022-11-14 13:06:41 +01:00
|
|
|
ARG CGO
|
2022-08-23 13:10:29 +02:00
|
|
|
RUN --mount=target=. \
|
|
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
2022-11-14 13:06:41 +01:00
|
|
|
CGO_ENABLED=${CGO} go build -o /dendrite ./cmd/generate-config && \
|
|
|
|
CGO_ENABLED=${CGO} go build -o /dendrite ./cmd/generate-keys && \
|
2023-02-14 12:47:47 +01:00
|
|
|
CGO_ENABLED=${CGO} go build -o /dendrite/dendrite ./cmd/dendrite && \
|
2023-03-22 14:12:06 +01:00
|
|
|
CGO_ENABLED=${CGO} go build -cover -covermode=atomic -o /dendrite/dendrite-cover -coverpkg "github.com/matrix-org/..." ./cmd/dendrite && \
|
2022-12-23 14:28:15 +01:00
|
|
|
cp build/scripts/complement-cmd.sh /complement-cmd.sh
|
2022-02-11 13:35:47 +01:00
|
|
|
|
|
|
|
WORKDIR /dendrite
|
|
|
|
RUN ./generate-keys --private-key matrix_key.pem
|
|
|
|
|
|
|
|
ENV SERVER_NAME=localhost
|
2022-03-24 12:52:51 +01:00
|
|
|
ENV API=0
|
2022-12-23 14:28:15 +01:00
|
|
|
ENV COVER=0
|
2022-02-11 13:35:47 +01:00
|
|
|
EXPOSE 8008 8448
|
|
|
|
|
|
|
|
|
|
|
|
# At runtime, generate TLS cert based on the CA now mounted at /ca
|
|
|
|
# At runtime, replace the SERVER_NAME with what we are told
|
2022-08-23 13:10:29 +02:00
|
|
|
CMD /build/run_postgres.sh && ./generate-keys --keysize 1024 --server $SERVER_NAME --tls-cert server.crt --tls-key server.key --tls-authority-cert /complement/ca/ca.crt --tls-authority-key /complement/ca/ca.key && \
|
2024-08-02 08:35:38 +02:00
|
|
|
./generate-config -server $SERVER_NAME --ci --db "user=postgres database=postgres host=/var/run/postgresql/" > dendrite.yaml && \
|
2022-09-01 15:15:41 +02:00
|
|
|
# Bump max_open_conns up here in the global database config
|
|
|
|
sed -i 's/max_open_conns:.*$/max_open_conns: 1990/g' dendrite.yaml && \
|
2022-07-11 15:31:31 +02:00
|
|
|
cp /complement/ca/ca.crt /usr/local/share/ca-certificates/ && update-ca-certificates && \
|
2022-12-23 14:28:15 +01:00
|
|
|
exec /complement-cmd.sh
|