meshsim Dockerfile

This commit is contained in:
Matthew Hodgson 2018-11-18 18:59:03 +00:00 committed by Andrew Morgan
parent dad89a4902
commit fe3b9d085f
6 changed files with 62 additions and 26 deletions

View file

@ -1,21 +1,26 @@
ARG PYTHON_VERSION=2 ARG PYTHON_VERSION=3
### ###
### Stage 0: builder ### 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 # install the OS build deps
RUN apk add \ RUN apt-get update && apt-get install -y \
build-base \ build-essential \
libffi-dev \ libffi-dev \
libjpeg-turbo-dev \ sqlite3 \
libressl-dev \ libssl-dev \
libxslt-dev \ libjpeg-dev \
linux-headers \ libxslt1-dev \
postgresql-dev \ libxml2-dev \
zlib-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 # build things which have slow build steps, before we copy synapse, so that
# the layer can be cached. # the layer can be cached.
@ -34,23 +39,40 @@ RUN pip install --prefix="/install" --no-warn-script-location \
COPY . /synapse COPY . /synapse
RUN pip install --prefix="/install" --no-warn-script-location \ RUN pip install --prefix="/install" --no-warn-script-location \
lxml \ lxml \
psycopg2 \ psycopg2-binary \
/synapse /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 ### 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 \ RUN apt-get update && apt-get install -y \
libffi \ procps \
libjpeg-turbo \ net-tools \
libressl \ iproute2 \
libxslt \ tcpdump \
libpq \ traceroute \
zlib \ mtr-tiny \
su-exec inetutils-ping \
less \
lsof
# for topologiser
RUN pip install flask
COPY --from=builder /install /usr/local COPY --from=builder /install /usr/local
COPY ./docker/start.py /start.py COPY ./docker/start.py /start.py
@ -58,6 +80,11 @@ COPY ./docker/conf /conf
VOLUME ["/data"] 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"] ENTRYPOINT ["/start.py"]

View file

@ -55,7 +55,7 @@ database:
database: "{{ POSTGRES_DB or "synapse" }}" database: "{{ POSTGRES_DB or "synapse" }}"
host: "{{ POSTGRES_HOST or "db" }}" host: "{{ POSTGRES_HOST or "db" }}"
port: "{{ POSTGRES_PORT or "5432" }}" port: "{{ POSTGRES_PORT or "5432" }}"
cp_min: 5 cp_min: 1
cp_max: 10 cp_max: 10
{% else %} {% else %}
database: database:

View file

@ -6,6 +6,7 @@ import sys
import subprocess import subprocess
import glob import glob
import codecs import codecs
import time
# Utility functions # Utility functions
convert = lambda src, dst, environ: open(dst, "w").write(jinja2.Template(open(src).read()).render(**environ)) 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 # Prepare the configuration
mode = sys.argv[1] if len(sys.argv) > 1 else None mode = sys.argv[1] if len(sys.argv) > 1 else None
environ = os.environ.copy() environ = os.environ.copy()
for e in environ:
print("%s:%s" % (e, environ[e]))
ownership = "{}:{}".format(environ.get("UID", 991), environ.get("GID", 991)) ownership = "{}:{}".format(environ.get("UID", 991), environ.get("GID", 991))
args = ["python", "-m", "synapse.app.homeserver"] args = ["python", "-m", "synapse.app.homeserver"]
@ -64,4 +69,8 @@ else:
args += ["--config-path", "/compiled/homeserver.yaml"] args += ["--config-path", "/compiled/homeserver.yaml"]
# Generate missing keys and start synapse # Generate missing keys and start synapse
subprocess.check_output(args + ["--generate-keys"]) 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)

View file

@ -38,7 +38,7 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
AuthError if the checks fail AuthError if the checks fail
Returns: Returns:
if the auth checks pass. if the auth checks pass.
""" """
if do_size_check: if do_size_check:
_check_size_limits(event) _check_size_limits(event)

View file

@ -347,7 +347,7 @@ class PresenceHandler(object):
"""Checks the presence of users that have timed out and updates as """Checks the presence of users that have timed out and updates as
appropriate. appropriate.
""" """
logger.info("Handling presence timeouts") #logger.info("Handling presence timeouts")
now = self.clock.time_msec() now = self.clock.time_msec()
try: try:

View file

@ -86,7 +86,7 @@ class TypingHandler(object):
self._room_typing = {} self._room_typing = {}
def _handle_timeouts(self): def _handle_timeouts(self):
logger.info("Checking for typing timeouts") #logger.info("Checking for typing timeouts")
now = self.clock.time_msec() now = self.clock.time_msec()