2022-08-23 06:10:29 -05:00
#syntax=docker/dockerfile:1.2
2022-02-15 11:40:48 -06:00
# A local development Complement dockerfile, to be used with host mounts
# /cache -> Contains the entire dendrite code at Dockerfile build time. Builds binaries but only keeps the generate-* ones. Pre-compilation saves time.
# /dendrite -> Host-mounted sources
# /runtime -> Binaries and config go here and are run at runtime
# At runtime, dendrite is built from /dendrite and run in /runtime.
#
# Use these mounts to make use of this dockerfile:
# COMPLEMENT_HOST_MOUNTS='/your/local/dendrite:/dendrite:ro;/your/go/path:/go:ro'
2022-07-11 08:31:31 -05:00
FROM golang:1.18-stretch
2022-02-15 11:40:48 -06:00
RUN apt-get update && apt-get install -y sqlite3
ENV SERVER_NAME = localhost
2022-12-23 07:28:15 -06:00
ENV COVER = 0
2022-02-15 11:40:48 -06:00
EXPOSE 8008 8448
2022-08-23 06:10:29 -05:00
WORKDIR /runtime
2022-02-15 11:40:48 -06:00
# This script compiles Dendrite for us.
RUN echo ' \
2022-07-11 08:31:31 -05:00
#!/bin/bash -eux \n\
2022-12-23 07:28:15 -06:00
if test -f "/runtime/dendrite-monolith-server" && test -f "/runtime/dendrite-monolith-server-cover" ; then \n \
2022-02-15 11:40:48 -06:00
echo "Skipping compilation; binaries exist" \n \
exit 0 \n \
2022-07-11 08:31:31 -05:00
fi \n \
cd /dendrite \n \
go build -v -o /runtime /dendrite/cmd/dendrite-monolith-server \n \
2022-12-23 07:28:15 -06:00
go test -c -cover -covermode= atomic -o /runtime/dendrite-monolith-server-cover -coverpkg "github.com/matrix-org/..." /dendrite/cmd/dendrite-monolith-server \n \
2022-07-11 08:31:31 -05:00
' > compile.sh && chmod +x compile.sh
2022-02-15 11:40:48 -06:00
# This script runs Dendrite for us. Must be run in the /runtime directory.
RUN echo ' \
2022-07-11 08:31:31 -05:00
#!/bin/bash -eu \n\
./generate-keys --private-key matrix_key.pem \n \
2022-08-23 06:10:29 -05:00
./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 \n \
2022-07-11 08:31:31 -05:00
./generate-config -server $SERVER_NAME --ci > dendrite.yaml \n \
cp /complement/ca/ca.crt /usr/local/share/ca-certificates/ && update-ca-certificates \n \
2022-12-23 07:28:15 -06:00
[ ${ COVER } -eq 1 ] && exec ./dendrite-monolith-server-cover --test.coverprofile= integrationcover.log --really-enable-open-registration --tls-cert server.crt --tls-key server.key --config dendrite.yaml \n \
2022-08-23 06:10:29 -05:00
exec ./dendrite-monolith-server --really-enable-open-registration --tls-cert server.crt --tls-key server.key --config dendrite.yaml \n \
2022-07-11 08:31:31 -05:00
' > run.sh && chmod +x run.sh
2022-02-15 11:40:48 -06:00
WORKDIR /cache
# Build the monolith in /cache - we won't actually use this but will rely on build artifacts to speed
# up the real compilation. Build the generate-* binaries in the true /runtime locations.
# If the generate-* source is changed, this dockerfile needs re-running.
2022-08-23 06:10:29 -05:00
RUN --mount= target = . \
--mount= type = cache,target= /go/pkg/mod \
--mount= type = cache,target= /root/.cache/go-build \
go build -o /runtime ./cmd/generate-config && \
go build -o /runtime ./cmd/generate-keys
2022-02-15 11:40:48 -06:00
WORKDIR /runtime
2022-08-23 06:10:29 -05:00
CMD /runtime/compile.sh && exec /runtime/run.sh