From b7e7712f07272e1612b47d9d174f0f55d0fdd247 Mon Sep 17 00:00:00 2001 From: Mathijs van Gorcum Date: Mon, 10 Sep 2018 12:21:42 +0000 Subject: Remove build requirements after building --- docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docker/Dockerfile') diff --git a/docker/Dockerfile b/docker/Dockerfile index 777976217d..f6da05f4ef 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -26,8 +26,9 @@ RUN cd /synapse \ && rm -rf \ setup.cfg \ setup.py \ - synapse - + synapse \ + && apk del .nacl_deps + VOLUME ["/data"] EXPOSE 8008/tcp 8448/tcp -- cgit 1.4.1 From e586916cda1f3549bd9ebab2e75d3824840c76a0 Mon Sep 17 00:00:00 2001 From: Mathijs van Gorcum Date: Mon, 10 Sep 2018 14:02:42 +0000 Subject: Move COPY before RUN and merge RUNs --- docker/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docker/Dockerfile') diff --git a/docker/Dockerfile b/docker/Dockerfile index f6da05f4ef..b9f0acccc3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,7 @@ FROM docker.io/python:2-alpine3.8 +COPY . /synapse + RUN apk add --no-cache --virtual .nacl_deps \ build-base \ libffi-dev \ @@ -9,12 +11,10 @@ RUN apk add --no-cache --virtual .nacl_deps \ linux-headers \ postgresql-dev \ su-exec \ - zlib-dev - -COPY . /synapse - + zlib-dev \ + # A wheel cache may be provided in ./cache for faster build -RUN cd /synapse \ + && cd /synapse \ && pip install --upgrade \ lxml \ pip \ -- cgit 1.4.1 From af10fa6536bf25630f4a290c756cd7f78e394a41 Mon Sep 17 00:00:00 2001 From: Jan Christian Grünhage Date: Mon, 10 Sep 2018 17:35:01 +0200 Subject: add runtime dependencies --- docker/Dockerfile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'docker/Dockerfile') diff --git a/docker/Dockerfile b/docker/Dockerfile index b9f0acccc3..20d3fe3bd8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,7 +2,7 @@ FROM docker.io/python:2-alpine3.8 COPY . /synapse -RUN apk add --no-cache --virtual .nacl_deps \ +RUN apk add --no-cache --virtual .build_deps \ build-base \ libffi-dev \ libjpeg-turbo-dev \ @@ -10,11 +10,16 @@ RUN apk add --no-cache --virtual .nacl_deps \ libxslt-dev \ linux-headers \ postgresql-dev \ - su-exec \ zlib-dev \ - -# A wheel cache may be provided in ./cache for faster build && cd /synapse \ + && apk add --no-cache --virtual .runtime_deps \ + libffi \ + libjpeg-turbo \ + libressl \ + libxslt \ + libpq \ + zlib \ + su-exec \ && pip install --upgrade \ lxml \ pip \ @@ -27,7 +32,7 @@ RUN apk add --no-cache --virtual .nacl_deps \ setup.cfg \ setup.py \ synapse \ - && apk del .nacl_deps + && apk del .build_deps VOLUME ["/data"] -- cgit 1.4.1 From 8dfb33d325a7b231668973338894d08f0d5436c9 Mon Sep 17 00:00:00 2001 From: Jan Christian Grünhage Date: Wed, 19 Sep 2018 13:48:41 +0200 Subject: make python 3 work in the docker container --- .dockerignore | 1 + docker/Dockerfile | 4 +++- docker/start.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'docker/Dockerfile') diff --git a/.dockerignore b/.dockerignore index 0180602e56..81e8f6d50a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ Dockerfile .travis.yml .gitignore demo/etc +synctl tox.ini .git/* .tox/* diff --git a/docker/Dockerfile b/docker/Dockerfile index 20d3fe3bd8..ad0ae0b734 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,5 @@ -FROM docker.io/python:2-alpine3.8 +ARG PYTHON_VERSION=2 +FROM docker.io/python:${PYTHON_VERSION}-alpine3.8 COPY . /synapse @@ -12,6 +13,7 @@ RUN apk add --no-cache --virtual .build_deps \ postgresql-dev \ zlib-dev \ && cd /synapse \ + && sed -i 's/\["synctl"\] + //' setup.py \ && apk add --no-cache --virtual .runtime_deps \ libffi \ libjpeg-turbo \ diff --git a/docker/start.py b/docker/start.py index 90e8b9c51a..346df8c87f 100755 --- a/docker/start.py +++ b/docker/start.py @@ -5,6 +5,7 @@ import os import sys import subprocess import glob +import codecs # Utility functions convert = lambda src, dst, environ: open(dst, "w").write(jinja2.Template(open(src).read()).render(**environ)) @@ -23,7 +24,7 @@ def generate_secrets(environ, secrets): with open(filename) as handle: value = handle.read() else: print("Generating a random secret for {}".format(name)) - value = os.urandom(32).encode("hex") + value = codecs.encode(os.urandom(32), "hex").decode() with open(filename, "w") as handle: handle.write(value) environ[secret] = value -- cgit 1.4.1 From df55a943cadaba60b9171f2e70f62dc4b38fbd78 Mon Sep 17 00:00:00 2001 From: Jan Christian Grünhage Date: Tue, 25 Sep 2018 14:33:38 +0200 Subject: Update Dockerfile --- docker/Dockerfile | 1 - 1 file changed, 1 deletion(-) (limited to 'docker/Dockerfile') diff --git a/docker/Dockerfile b/docker/Dockerfile index ad0ae0b734..1d00defc2d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,7 +13,6 @@ RUN apk add --no-cache --virtual .build_deps \ postgresql-dev \ zlib-dev \ && cd /synapse \ - && sed -i 's/\["synctl"\] + //' setup.py \ && apk add --no-cache --virtual .runtime_deps \ libffi \ libjpeg-turbo \ -- cgit 1.4.1 From 53c5fa4e6c179c6ed855169dcb99b69699db75be Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 1 Oct 2018 12:29:17 +0100 Subject: Further reduce the size of the docker image (#3972) Rewrite the dockerfile as a multistage build: this means we can get rid of a whole load of cruft which we don't need. --- changelog.d/3972.misc | 1 + docker/Dockerfile | 71 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 changelog.d/3972.misc (limited to 'docker/Dockerfile') diff --git a/changelog.d/3972.misc b/changelog.d/3972.misc new file mode 100644 index 0000000000..e56299ee78 --- /dev/null +++ b/changelog.d/3972.misc @@ -0,0 +1 @@ +Further reduce the docker image size diff --git a/docker/Dockerfile b/docker/Dockerfile index 1d00defc2d..db44c02a92 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,9 +1,13 @@ ARG PYTHON_VERSION=2 -FROM docker.io/python:${PYTHON_VERSION}-alpine3.8 -COPY . /synapse +### +### Stage 0: builder +### +FROM docker.io/python:${PYTHON_VERSION}-alpine3.8 as builder -RUN apk add --no-cache --virtual .build_deps \ +# install the OS build deps + +RUN apk add \ build-base \ libffi-dev \ libjpeg-turbo-dev \ @@ -11,30 +15,47 @@ RUN apk add --no-cache --virtual .build_deps \ libxslt-dev \ linux-headers \ postgresql-dev \ - zlib-dev \ - && cd /synapse \ - && apk add --no-cache --virtual .runtime_deps \ - libffi \ - libjpeg-turbo \ - libressl \ - libxslt \ - libpq \ - zlib \ - su-exec \ - && pip install --upgrade \ + zlib-dev + +# build things which have slow build steps, before we copy synapse, so that +# the layer can be cached. +# +# (we really just care about caching a wheel here, as the "pip install" below +# will install them again.) + +RUN pip install --prefix="/install" --no-warn-script-location \ + cryptography \ + msgpack-python \ + pillow \ + pynacl + +# now install synapse and all of the python deps to /install. + +COPY . /synapse +RUN pip install --prefix="/install" --no-warn-script-location \ lxml \ - pip \ psycopg2 \ - setuptools \ - && mkdir -p /synapse/cache \ - && pip install -f /synapse/cache --upgrade --process-dependency-links . \ - && mv /synapse/docker/start.py /synapse/docker/conf / \ - && rm -rf \ - setup.cfg \ - setup.py \ - synapse \ - && apk del .build_deps - + /synapse + +### +### Stage 1: runtime +### + +FROM docker.io/python:${PYTHON_VERSION}-alpine3.8 + +RUN apk add --no-cache --virtual .runtime_deps \ + libffi \ + libjpeg-turbo \ + libressl \ + libxslt \ + libpq \ + zlib \ + su-exec + +COPY --from=builder /install /usr/local +COPY ./docker/start.py /start.py +COPY ./docker/conf /conf + VOLUME ["/data"] EXPOSE 8008/tcp 8448/tcp -- cgit 1.4.1