2023-03-08 09:03:26 -05:00
|
|
|
ARG SYNAPSE_VERSION=1.78
|
2022-10-31 19:41:26 -04:00
|
|
|
ARG HARDENED_MALLOC_VERSION=11
|
|
|
|
ARG UID=991
|
|
|
|
ARG GID=991
|
|
|
|
|
|
|
|
### Build Hardened Malloc
|
|
|
|
FROM alpine:latest as build-malloc
|
|
|
|
|
|
|
|
ARG HARDENED_MALLOC_VERSION
|
|
|
|
ARG CONFIG_NATIVE=false
|
|
|
|
ARG VARIANT=default
|
|
|
|
|
|
|
|
RUN apk --no-cache add build-base git gnupg && cd /tmp \
|
|
|
|
&& wget -q https://github.com/thestinger.gpg && gpg --import thestinger.gpg \
|
|
|
|
&& git clone --depth 1 --branch ${HARDENED_MALLOC_VERSION} https://github.com/GrapheneOS/hardened_malloc \
|
|
|
|
&& cd hardened_malloc && git verify-tag $(git describe --tags) \
|
|
|
|
&& make CONFIG_NATIVE=${CONFIG_NATIVE} VARIANT=${VARIANT}
|
|
|
|
|
|
|
|
### Nginx & Redis
|
|
|
|
FROM alpine:latest as deps_base
|
|
|
|
|
|
|
|
RUN apk --no-cache add nginx redis
|
|
|
|
|
|
|
|
### Redis Base
|
|
|
|
FROM redis:6-alpine AS redis_base
|
|
|
|
|
|
|
|
### Build Synapse
|
|
|
|
FROM python:alpine as builder
|
|
|
|
|
|
|
|
ARG SYNAPSE_VERSION
|
|
|
|
|
|
|
|
RUN apk -U upgrade \
|
|
|
|
&& apk add -t build-deps \
|
|
|
|
build-base \
|
|
|
|
libffi-dev \
|
|
|
|
libjpeg-turbo-dev \
|
|
|
|
libressl-dev \
|
|
|
|
libxslt-dev \
|
|
|
|
linux-headers \
|
|
|
|
postgresql-dev \
|
|
|
|
rustup \
|
|
|
|
zlib-dev \
|
2023-01-09 17:02:48 -05:00
|
|
|
git \
|
2022-10-31 19:41:26 -04:00
|
|
|
&& rustup-init -y && source $HOME/.cargo/env \
|
|
|
|
&& pip install --upgrade pip \
|
|
|
|
&& pip install --prefix="/install" --no-warn-script-location \
|
2023-01-31 15:27:04 -05:00
|
|
|
-e "git+https://git.anonymousland.org/anonymousland/synapse-product#egg=matrix-synapse[all]==${SYNAPSE_VERSION}"
|
2022-10-31 19:41:26 -04:00
|
|
|
|
|
|
|
### Build Production
|
|
|
|
|
|
|
|
FROM python:alpine
|
|
|
|
|
|
|
|
ARG UID
|
|
|
|
ARG GID
|
|
|
|
|
|
|
|
RUN apk -U upgrade \
|
|
|
|
&& apk add -t run-deps \
|
|
|
|
libffi \
|
|
|
|
libgcc \
|
|
|
|
libjpeg-turbo \
|
|
|
|
libressl \
|
|
|
|
libstdc++ \
|
|
|
|
libxslt \
|
|
|
|
libpq \
|
|
|
|
zlib \
|
|
|
|
tzdata \
|
|
|
|
xmlsec \
|
|
|
|
git \
|
|
|
|
curl \
|
2022-12-27 12:20:48 -05:00
|
|
|
icu-libs \
|
2022-10-31 19:41:26 -04:00
|
|
|
&& adduser -g ${GID} -u ${UID} --disabled-password --gecos "" synapse \
|
|
|
|
&& rm -rf /var/cache/apk/*
|
2022-10-31 20:10:13 -04:00
|
|
|
|
2022-10-31 20:14:07 -04:00
|
|
|
RUN set -x ; \
|
|
|
|
addgroup -g 82 -S www-data ; \
|
|
|
|
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
|
2022-10-31 19:41:26 -04:00
|
|
|
|
|
|
|
RUN pip install --upgrade pip \
|
|
|
|
&& pip install -e "git+https://github.com/matrix-org/mjolnir.git#egg=mjolnir&subdirectory=synapse_antispam"
|
|
|
|
|
2022-12-07 15:09:46 -05:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
|
|
pip install supervisor~=4.2
|
|
|
|
|
|
|
|
RUN pip install Jinja2
|
|
|
|
|
2022-10-31 20:05:53 -04:00
|
|
|
RUN mkdir /var/log/nginx /var/lib/nginx
|
|
|
|
|
2022-10-31 19:56:22 -04:00
|
|
|
COPY --from=deps_base /usr/sbin/nginx /usr/sbin
|
|
|
|
COPY --from=deps_base /usr/share/nginx /usr/share/nginx
|
|
|
|
COPY --from=deps_base /usr/lib/nginx /usr/lib/nginx
|
|
|
|
COPY --from=deps_base /etc/nginx /etc/nginx
|
|
|
|
|
2022-10-31 19:52:39 -04:00
|
|
|
RUN chown www-data /var/lib/nginx
|
2023-01-01 12:46:07 -05:00
|
|
|
RUN mkdir /var/lib/nginx/logs/
|
|
|
|
RUN chown 991:www-data /var/lib/nginx/logs/
|
2022-10-31 19:52:39 -04:00
|
|
|
RUN ln -sf /dev/stdout /var/log/nginx/access.log
|
|
|
|
RUN ln -sf /dev/stderr /var/log/nginx/error.log
|
|
|
|
|
2022-10-31 19:41:26 -04:00
|
|
|
COPY --from=build-malloc /tmp/hardened_malloc/out/libhardened_malloc.so /usr/local/lib/
|
|
|
|
COPY --from=builder /install /usr/local
|
2022-12-07 15:09:46 -05:00
|
|
|
COPY --chown=synapse:synapse ./rootfs /
|
2022-10-31 19:41:26 -04:00
|
|
|
COPY --from=redis_base /usr/local/bin/redis-server /usr/local/bin
|
2022-11-08 16:04:22 -05:00
|
|
|
|
|
|
|
COPY ./rootfs/start.py /start.py
|
2022-10-31 19:41:26 -04:00
|
|
|
COPY ./rootfs/conf-workers/* /conf/
|
2022-11-08 16:04:22 -05:00
|
|
|
COPY ./rootfs/configure_workers_and_start.py /configure_workers_and_start.py
|
2022-10-31 20:18:51 -04:00
|
|
|
COPY ./prefix-log /usr/local/bin/
|
2022-11-08 14:22:13 -05:00
|
|
|
|
2023-01-01 12:46:07 -05:00
|
|
|
RUN chown -R synapse:synapse /conf/
|
|
|
|
RUN chown -R synapse:www-data /etc/nginx
|
|
|
|
RUN chown synapse:synapse /usr/local/lib/libhardened_malloc.so
|
|
|
|
|
|
|
|
RUN mkdir -p /etc/supervisor/conf.d
|
|
|
|
RUN mkdir -p /etc/nginx/conf.d
|
|
|
|
RUN chown -R synapse:www-data /etc/nginx
|
|
|
|
|
|
|
|
RUN mkdir -p /health/
|
|
|
|
RUN chown -R synapse:synapse /health/
|
|
|
|
|
|
|
|
RUN chown -R synapse:synapse /etc/supervisor
|
|
|
|
|
|
|
|
RUN chmod +x /usr/local/bin/prefix-log
|
|
|
|
|
2022-11-08 14:22:13 -05:00
|
|
|
RUN chmod 755 /start.py
|
2022-10-31 19:41:26 -04:00
|
|
|
|
2023-01-01 12:46:07 -05:00
|
|
|
RUN chown synapse:synapse /
|
|
|
|
|
2022-10-31 19:41:26 -04:00
|
|
|
ENV LD_PRELOAD="/usr/local/lib/libhardened_malloc.so"
|
|
|
|
|
|
|
|
USER synapse
|
|
|
|
|
|
|
|
VOLUME /data
|
|
|
|
|
|
|
|
EXPOSE 8008/tcp
|
|
|
|
|
2023-01-01 12:46:07 -05:00
|
|
|
CMD ["python3", "/configure_workers_and_start.py"]
|
2022-10-31 19:41:26 -04:00
|
|
|
|
|
|
|
HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
|
|
|
|
CMD /bin/sh /healthcheck.sh
|