mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
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.
This commit is contained in:
parent
9a8bbc9a59
commit
53c5fa4e6c
1
changelog.d/3972.misc
Normal file
1
changelog.d/3972.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Further reduce the docker image size
|
@ -1,9 +1,13 @@
|
|||||||
ARG PYTHON_VERSION=2
|
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 \
|
build-base \
|
||||||
libffi-dev \
|
libffi-dev \
|
||||||
libjpeg-turbo-dev \
|
libjpeg-turbo-dev \
|
||||||
@ -11,29 +15,46 @@ RUN apk add --no-cache --virtual .build_deps \
|
|||||||
libxslt-dev \
|
libxslt-dev \
|
||||||
linux-headers \
|
linux-headers \
|
||||||
postgresql-dev \
|
postgresql-dev \
|
||||||
zlib-dev \
|
zlib-dev
|
||||||
&& cd /synapse \
|
|
||||||
&& apk add --no-cache --virtual .runtime_deps \
|
# build things which have slow build steps, before we copy synapse, so that
|
||||||
libffi \
|
# the layer can be cached.
|
||||||
libjpeg-turbo \
|
#
|
||||||
libressl \
|
# (we really just care about caching a wheel here, as the "pip install" below
|
||||||
libxslt \
|
# will install them again.)
|
||||||
libpq \
|
|
||||||
zlib \
|
RUN pip install --prefix="/install" --no-warn-script-location \
|
||||||
su-exec \
|
cryptography \
|
||||||
&& pip install --upgrade \
|
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 \
|
lxml \
|
||||||
pip \
|
|
||||||
psycopg2 \
|
psycopg2 \
|
||||||
setuptools \
|
/synapse
|
||||||
&& mkdir -p /synapse/cache \
|
|
||||||
&& pip install -f /synapse/cache --upgrade --process-dependency-links . \
|
###
|
||||||
&& mv /synapse/docker/start.py /synapse/docker/conf / \
|
### Stage 1: runtime
|
||||||
&& rm -rf \
|
###
|
||||||
setup.cfg \
|
|
||||||
setup.py \
|
FROM docker.io/python:${PYTHON_VERSION}-alpine3.8
|
||||||
synapse \
|
|
||||||
&& apk del .build_deps
|
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"]
|
VOLUME ["/data"]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user