Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Further reduce the size of the docker image #3972

Merged
merged 4 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3972.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Further reduce the docker image size
76 changes: 52 additions & 24 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
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

# first of all, install the runtime deps; this layer can then be used in the
# final stage as well.

RUN apk add --no-cache --virtual .runtime_deps \
libffi \
libjpeg-turbo \
libressl \
libxslt \
libpq \
zlib \
su-exec
richvdh marked this conversation as resolved.
Show resolved Hide resolved

# install the OS build deps, and build wheels for the python libs which have
# slow build steps, as more layers which can be cached independently

RUN apk add --no-cache --virtual .build_deps \
richvdh marked this conversation as resolved.
Show resolved Hide resolved
build-base \
Expand All @@ -11,30 +28,41 @@ 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

RUN pip install --prefix="/install" --no-warn-script-location \
cryptography \
lxml \
pip \
msgpack-python \
pillow \
jcgruenhage marked this conversation as resolved.
Show resolved Hide resolved
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

pynacl

# now install synapse and all of the python deps to /install.

COPY . /synapse
RUN pip install --prefix="/install" --no-warn-script-location \
/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
Expand Down