From 58cc9fcd4c34b754092db518fcf0707542de14de Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 19 Dec 2018 13:29:25 +0100 Subject: [PATCH] use multi-stage build - python 3.7 - build wheels in first stage, install in second - run with slim image by default instead of full (~200MB vs ~1GB) --- Dockerfile | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 91e21487..99e7355b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,28 @@ -FROM python:3.6.3 +ARG PYTHON_VERSION=3.7 +FROM python:${PYTHON_VERSION} + +# build wheels in first image +ADD . /tmp/src +RUN mkdir /tmp/wheelhouse \ + && cd /tmp/wheelhouse \ + && pip3 wheel --no-cache-dir /tmp/src + +# run with slim variant instead of full +# since we won't need compilers and friends +FROM python:${PYTHON_VERSION}-slim + +# we do need git, though +RUN apt-get update \ + && apt-get -y install --no-install-recommends git \ + && rm -rf /var/lib/apt/lists/* + +# install repo2docker +COPY --from=0 /tmp/wheelhouse /tmp/wheelhouse +RUN pip3 install --no-cache-dir /tmp/wheelhouse/*.whl + +# add git-credential helper +COPY ./docker/git-credential-env /usr/local/bin/git-credential-env +RUN git config --system credential.helper env # Used for testing purpose in ports.py EXPOSE 52000 -RUN mkdir /tmp/src -ADD . /tmp/src -RUN pip3 install --no-cache-dir /tmp/src -RUN cp /tmp/src/docker/git-credential-env /usr/local/bin/git-credential-env && \ - git config --system credential.helper env