Shrink the docker image via multi-stage builds

This restructures the entire docker image build process to first
install bw_plex and its python dependencies into a virtualenv in a
"builder" docker container; then the main image build merely installs
the runtime dependencies and copies the virtualenv contents over,
setting the appropriate $PATH variable.

Additionally, use the contents of the current git checkout to build
the docker image, as opposed to downloading the source code from
github & pip-installing that. In addition to saving space, should
allow developers to test their changes better.
This commit is contained in:
Andreas Fuchs
2020-04-26 01:15:02 -04:00
parent fc64975bfb
commit 40a0990819
2 changed files with 32 additions and 19 deletions

7
.dockerignore Normal file
View File

@@ -0,0 +1,7 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
*.whl
Dockerfile

View File

@@ -1,8 +1,24 @@
FROM ubuntu:18.04 AS builder
ENV DEBIAN_FRONTEND="noninteractive"
ENV LC_ALL C.UTF-8
ENV lang C.UTF-8
RUN apt-get update && apt-get -y install \
git-core swig libpulse-dev libasound2-dev ffmpeg tesseract-ocr python3-pip pandoc python3.6-tk \
python3-setuptools python3-venv && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && \
python3 -m venv /app/bw_plex
ENV PATH="/app/bw_plex/bin:$PATH"
WORKDIR /src
# Python requirements from pip
RUN pip3 --no-cache-dir install pytest pytest-cov pytest-mock pytest_click pypandoc codecov \
opencv-contrib-python-headless SpeechRecognition pocketsphinx pytesseract
ADD . /src
RUN pip3 --no-cache-dir wheel -e . && pip3 --no-cache-dir install bw_plex*.whl
FROM ubuntu:18.04
# This images is much bigger then i want, ill try to reduce it
# but im such a docker noob, send a PR if you know how to fix it.
LABEL maintainer="hellowlol1@gmail.com"
ENV DEBIAN_FRONTEND="noninteractive"
@@ -11,22 +27,12 @@ ENV lang C.UTF-8
# Package requirements
RUN apt-get update && apt-get -y install \
git swig libpulse-dev libasound2-dev ffmpeg tesseract-ocr python3-pip pandoc python3.6-tk \
python3-setuptools && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && \
mkdir -p /app/bw_plex
libpulse0 libasound2 ffmpeg tesseract-ocr python3-pip pandoc python3.6-tk \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Python requirements from pip
RUN pip3 install pytest pytest-cov pytest-mock pytest_click pypandoc codecov \
opencv-contrib-python-headless SpeechRecognition pocketsphinx pytesseract
RUN git clone --depth=1 https://github.com/Hellowlol/bw_plex.git /app/bw_plex
#&& rm -rf /app/bw_plex/.git
# This is needed for the the manual install of bw_plex
WORKDIR /app/bw_plex
RUN pip3 install -e .
COPY --from=builder /app/bw_plex /app/bw_plex
ENV PATH="/app/bw_plex/bin:$PATH"
# COPY root/ /
VOLUME /config