From 7b9d0ef285c3587b3ad94f2bd4ac153e7fada5e8 Mon Sep 17 00:00:00 2001 From: Ron Nabuurs Date: Wed, 30 Jan 2019 09:20:58 +0100 Subject: [PATCH] Made the image smaller Fixed bcrypt Added requirements.txt --- Dockerfile | 51 ++++++++++++++++++++++++++++++++++-------------- requirements.txt | 1 + 2 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile index 405f629..e74fdbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,42 @@ -FROM python:3.6-alpine +FROM alpine:3.8 AS base -# Build -COPY . /code -WORKDIR /code - -RUN addgroup -S -g 9898 pypiserver && \ - adduser -S -u 9898 -G pypiserver pypiserver && \ - apk add py-bcrypt && \ - python setup.py install && \ - pip install passlib && \ - cd / && \ - rm -rf /code && \ - mkdir -p /data/packages && \ - chown -R pypiserver:pypiserver /data/packages && \ +# Install python and modules that can't be installed via pip +# Delete the uncompiled variants to shave off ~10MB of the docker file +RUN addgroup -S -g 9898 pypiserver \ + && adduser -S -u 9898 -G pypiserver pypiserver \ + && mkdir -p /data/packages \ + && chown -R pypiserver:pypiserver /data/packages \ # Set the setgid bit so anything added here gets associated with the # pypiserver group - chmod g+s /data/packages + && chmod g+s /data/packages \ + && apk --no-cache add python py2-bcrypt py2-cffi py2-six \ + && find /usr -name "*.py" ! -name "__*" -exec rm {} \; + +FROM base as builder + +# Copy the requirements and install them +# Do this in a separate image in a separate directory +# to not have all the pip stuff in the final image +COPY requirements.txt /requirements.txt + +# Install python packages +RUN apk add --no-cache py2-pip \ + && mkdir /install \ + && pip install --prefix=/install --requirement /requirements.txt \ + && find /install -name "*.py" ! -name "__*" -exec rm {} \; + +FROM base + +# Copy the libraries installed via pip +COPY --from=builder /install /usr + +COPY . /code + +RUN apk add py2-setuptools \ + && cd code \ + && python setup.py install \ + && cd / \ + && rm -rf code VOLUME /data/packages USER pypiserver diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ca4dffb --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +passlib==1.7.1