From fe3b9d085f1773576f85c6c580df51d629425161 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 18 Nov 2018 18:59:03 +0000 Subject: [PATCH] meshsim Dockerfile --- docker/Dockerfile | 69 +++++++++++++++++++++++++----------- docker/conf/homeserver.yaml | 2 +- docker/start.py | 11 +++++- synapse/event_auth.py | 2 +- synapse/handlers/presence.py | 2 +- synapse/handlers/typing.py | 2 +- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index db44c02a92..95776f0583 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,21 +1,26 @@ -ARG PYTHON_VERSION=2 +ARG PYTHON_VERSION=3 ### ### Stage 0: builder ### -FROM docker.io/python:${PYTHON_VERSION}-alpine3.8 as builder +FROM docker.io/python:${PYTHON_VERSION}-slim-stretch as builder # install the OS build deps -RUN apk add \ - build-base \ +RUN apt-get update && apt-get install -y \ + build-essential \ libffi-dev \ - libjpeg-turbo-dev \ - libressl-dev \ - libxslt-dev \ - linux-headers \ - postgresql-dev \ - zlib-dev + sqlite3 \ + libssl-dev \ + libjpeg-dev \ + libxslt1-dev \ + libxml2-dev \ + libpq-dev + +# for ksm_preload +RUN apt-get install -y \ + git \ + cmake # build things which have slow build steps, before we copy synapse, so that # the layer can be cached. @@ -34,23 +39,40 @@ RUN pip install --prefix="/install" --no-warn-script-location \ COPY . /synapse RUN pip install --prefix="/install" --no-warn-script-location \ lxml \ - psycopg2 \ + psycopg2-binary \ /synapse +# N.B. to work, this needs: +# echo 1 > /sys/kernel/mm/ksm/run +# echo 31250 > /sys/kernel/mm/ksm/pages_to_scan # 128MB of 4KB pages at a time +# echo 10000 > /sys/kernel/mm/ksm/pages_to_scan # 40MB of pages at a time +# ...to be run in the Docker host + +RUN git clone https://github.com/unbrice/ksm_preload && \ + cd ksm_preload && \ + cmake . && \ + make && \ + cp libksm_preload.so /install/lib + ### ### Stage 1: runtime ### -FROM docker.io/python:${PYTHON_VERSION}-alpine3.8 +FROM docker.io/python:${PYTHON_VERSION}-slim-stretch -RUN apk add --no-cache --virtual .runtime_deps \ - libffi \ - libjpeg-turbo \ - libressl \ - libxslt \ - libpq \ - zlib \ - su-exec +RUN apt-get update && apt-get install -y \ + procps \ + net-tools \ + iproute2 \ + tcpdump \ + traceroute \ + mtr-tiny \ + inetutils-ping \ + less \ + lsof + +# for topologiser +RUN pip install flask COPY --from=builder /install /usr/local COPY ./docker/start.py /start.py @@ -58,6 +80,11 @@ COPY ./docker/conf /conf VOLUME ["/data"] -EXPOSE 8008/tcp 8448/tcp +EXPOSE 8008/tcp 8448/tcp 3000/tcp + +ENV LD_PRELOAD=/usr/local/lib/libksm_preload.so + +# default is 32768 (8 4KB pages) +ENV KSMP_MERGE_THRESHOLD=16384 ENTRYPOINT ["/start.py"] diff --git a/docker/conf/homeserver.yaml b/docker/conf/homeserver.yaml index 1b0f655d26..4194e843c0 100644 --- a/docker/conf/homeserver.yaml +++ b/docker/conf/homeserver.yaml @@ -55,7 +55,7 @@ database: database: "{{ POSTGRES_DB or "synapse" }}" host: "{{ POSTGRES_HOST or "db" }}" port: "{{ POSTGRES_PORT or "5432" }}" - cp_min: 5 + cp_min: 1 cp_max: 10 {% else %} database: diff --git a/docker/start.py b/docker/start.py index 346df8c87f..01cccaf08e 100755 --- a/docker/start.py +++ b/docker/start.py @@ -6,6 +6,7 @@ import sys import subprocess import glob import codecs +import time # Utility functions convert = lambda src, dst, environ: open(dst, "w").write(jinja2.Template(open(src).read()).render(**environ)) @@ -31,6 +32,10 @@ def generate_secrets(environ, secrets): # Prepare the configuration mode = sys.argv[1] if len(sys.argv) > 1 else None environ = os.environ.copy() + +for e in environ: + print("%s:%s" % (e, environ[e])) + ownership = "{}:{}".format(environ.get("UID", 991), environ.get("GID", 991)) args = ["python", "-m", "synapse.app.homeserver"] @@ -64,4 +69,8 @@ else: args += ["--config-path", "/compiled/homeserver.yaml"] # Generate missing keys and start synapse subprocess.check_output(args + ["--generate-keys"]) - os.execv("/sbin/su-exec", ["su-exec", ownership] + args) + + os.system("(sleep 5; /usr/local/bin/register_new_matrix_user -u matthew -p isildur -c /compiled/homeserver.yaml -a) &"); + + os.execv("/usr/local/bin/python", args) + diff --git a/synapse/event_auth.py b/synapse/event_auth.py index 2f5f8819c1..39e4bd2b11 100644 --- a/synapse/event_auth.py +++ b/synapse/event_auth.py @@ -38,7 +38,7 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True): AuthError if the checks fail Returns: - if the auth checks pass. + if the auth checks pass. """ if do_size_check: _check_size_limits(event) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index ba3856674d..172b6947d4 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -347,7 +347,7 @@ class PresenceHandler(object): """Checks the presence of users that have timed out and updates as appropriate. """ - logger.info("Handling presence timeouts") + #logger.info("Handling presence timeouts") now = self.clock.time_msec() try: diff --git a/synapse/handlers/typing.py b/synapse/handlers/typing.py index a61bbf9392..2af164a142 100644 --- a/synapse/handlers/typing.py +++ b/synapse/handlers/typing.py @@ -86,7 +86,7 @@ class TypingHandler(object): self._room_typing = {} def _handle_timeouts(self): - logger.info("Checking for typing timeouts") + #logger.info("Checking for typing timeouts") now = self.clock.time_msec()