From b0736f15adfc608c4e91262527bb335936b3a16d Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 25 Jun 2020 12:20:15 +0200 Subject: [PATCH] Somewhat reduce the docker image size --- extras/docker/apache/Dockerfile | 30 ++++++++++++++++---- extras/docker/base/Dockerfile | 2 -- extras/docker/development/Dockerfile | 41 ++++++++++++++++++---------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/extras/docker/apache/Dockerfile b/extras/docker/apache/Dockerfile index 82866a0fd..1d6b2d05c 100644 --- a/extras/docker/apache/Dockerfile +++ b/extras/docker/apache/Dockerfile @@ -15,9 +15,32 @@ # sudo docker container start --attach wger.apache # +########## +# Builder +########## +FROM ubuntu:20.04 as builder + +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + build-essential \ + python3-dev \ + python3-pip \ + git + +# Set up the application +COPY . . +RUN pip3 install wheel \ + && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt \ + && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_forked.txt + + +######## +# Final +######## FROM wger/base:1.9 LABEL maintainer="Roland Geider " +ARG DOCKER_DIR=./extras/docker/apache EXPOSE 80 # Set locale to UTF8, otherwise problems with the encoding can occur, e.g. @@ -27,9 +50,6 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -# Path to where misc docker files live, relative to the project root -ARG DOCKER_DIR=./extras/docker/apache - # Install dependencies RUN apt-get update \ @@ -58,6 +78,7 @@ RUN chmod 0644 /etc/cron.d/wger \ && touch /var/log/cron.log COPY --chown=wger:www-data . /home/wger/src +COPY --from=builder /usr/src/app/wheels /wheels # Set up the application RUN ln -s /home/wger/static/CACHE /var/www @@ -68,8 +89,7 @@ RUN python3 -m venv /home/wger/venv RUN . /home/wger/venv/bin/activate \ && pip install --upgrade pip \ && pip install wheel \ - && pip install -r requirements.txt \ - && pip install -r requirements_forked.txt \ + && pip install --no-cache /wheels/* \ && python setup.py develop \ && npm install \ && npm install bower \ diff --git a/extras/docker/base/Dockerfile b/extras/docker/base/Dockerfile index e101ce355..921a513f7 100644 --- a/extras/docker/base/Dockerfile +++ b/extras/docker/base/Dockerfile @@ -16,12 +16,10 @@ LABEL maintainer="Roland Geider " ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install --no-install-recommends -y \ - build-essential \ git \ locales \ nodejs \ npm \ - python3-dev \ python3-venv \ vim \ tmux \ diff --git a/extras/docker/development/Dockerfile b/extras/docker/development/Dockerfile index c6cc47daf..37f021d6e 100644 --- a/extras/docker/development/Dockerfile +++ b/extras/docker/development/Dockerfile @@ -23,9 +23,31 @@ # sudo docker container start --attach wger.devel # -FROM wger/base:1.9 +########## +# Builder +########## +FROM ubuntu:20.04 as builder +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + build-essential \ + python3-dev \ + python3-pip \ + git + +# Set up the application +COPY . . +RUN pip3 install wheel \ + && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt \ + && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_forked.txt + + +######## +# Final +######## +FROM wger/base:1.9 LABEL maintainer="Roland Geider " +ARG DOCKER_DIR=./extras/docker/development EXPOSE 8000 # Set locale to UTF8, otherwise problems with the encoding can occur, e.g. @@ -35,12 +57,11 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -# Path to where misc docker files live, relative to the project root -ARG DOCKER_DIR=./extras/docker/development # Set up the application USER wger COPY --chown=wger:wger . /home/wger/src +COPY --from=builder /usr/src/app/wheels /wheels #RUN git clone https://github.com/wger-project/wger.git /home/wger/src WORKDIR /home/wger/src @@ -48,8 +69,7 @@ RUN python3 -m venv /home/wger/venv RUN . /home/wger/venv/bin/activate \ && pip install --upgrade pip \ && pip install wheel \ - && pip install -r requirements_devel.txt \ - && pip install -r requirements_forked.txt \ + && pip install --no-cache /wheels/* \ && python setup.py develop \ && npm install \ && npm install bower \ @@ -62,15 +82,6 @@ RUN . /home/wger/venv/bin/activate \ # Download the exercise images RUN mkdir ~/media \ - && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \ - && . /home/wger/venv/bin/activate + && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py - -USER root -RUN apt-get remove -y \ - build-essential \ - python-dev \ - && apt autoremove -y - -USER wger CMD ["/bin/bash"]