Tightened up the Docker build.

master
Pacman Ghost 1 year ago
parent 2946b2d10f
commit cbc86e6fe8
  1. 76
      Dockerfile

@ -1,57 +1,14 @@
# NOTE: Use the run-container.sh script to build and launch this container.
# We do a multi-stage build (requires Docker >= 17.05) to install everything, then copy it all
# to the final target image.
# NOTE: Multi-stage builds require Docker >= 17.05.
FROM centos:8 AS base
# update packages
RUN dnf -y upgrade-minimal
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# NOTE: We install the Python dependencies into a temporary intermediate stage, then copy everything over
# to the final image, because some modules (e.g. grpcio) need pre-requisites to be installed.
# This saves us about 300 MB for the final image and, importantly, adding a requirement doesn't cause us
# to re-install Java and Firefox below, when we start building the final image.
FROM base AS build
# install Python
# NOTE: The version of Python we want is newer than what's in Centos 8,
# so we have to install from source :-/
RUN dnf -y groupinstall "Development Tools" && \
dnf -y install openssl-devel bzip2-devel libffi-devel sqlite-devel
RUN cd /tmp && \
dnf -y install wget && \
wget https://www.python.org/ftp/python/3.8.7/Python-3.8.7.tgz && \
tar xvf Python-3.8.7.tgz && \
cd Python-3.8.7/ && \
./configure --enable-optimizations && \
make install
# set up a virtualenv
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# install the application requirements
COPY requirements.txt requirements-dev.txt ./
RUN pip3 install -r requirements.txt
ARG CONTROL_TESTS_PORT
RUN if [ -n "$CONTROL_TESTS_PORT" ]; then \
dnf install -y gcc-c++ python3-devel && \
pip3 install -r requirements-dev.txt \
; fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FROM base
# update packages and install requirements
RUN dnf -y upgrade-minimal && \
dnf install -y python38
# copy the Python installation from the build image
COPY --from=build /usr/local/bin/python3.8 /usr/local/bin/python3.8
COPY --from=build /usr/local/lib/python3.8 /usr/local/lib/python3.8
COPY --from=build /usr/local/bin/pip3 /usr/local/bin/pip3
RUN ln -s /usr/local/bin/python3.8 /usr/local/bin/python3
# NOTE: We don't need the following stuff for the build step, but it's nice to not have to re-install
# it all every time we change the requirements :-/
# install Java
RUN url="https://download.java.net/java/GA/jdk15.0.1/51f4f36ad4ef43e39d0dfdbaf6549e32/9/GPL/openjdk-15.0.1_linux-x64_bin.tar.gz" ; \
@ -71,7 +28,28 @@ RUN url=$( curl -s https://api.github.com/repos/mozilla/geckodriver/releases/lat
# clean up
RUN dnf clean all
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FROM base AS build
# set up a virtualenv
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --upgrade pip
# install the application requirements
COPY requirements.txt requirements-dev.txt /tmp/
RUN pip3 install -r /tmp/requirements.txt
ARG CONTROL_TESTS_PORT
RUN if [ -n "$CONTROL_TESTS_PORT" ]; then \
pip3 install -r /tmp/requirements-dev.txt \
; fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FROM base
# copy the virtualenv from the build image
COPY --from=build /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

Loading…
Cancel
Save