#################### # Dependancy Builder #################### FROM python:3.7-stretch AS builder # Set working directory WORKDIR /usr/src/app # Turns off writing .pyc files; superfluous on an ephemeral container. ENV PYTHONDONTWRITEBYTECODE=1 # Seems to speed things up ENV PYTHONUNBUFFERED=1 # Use the executables from the virtualenv instead of globals ENV PATH="/opt/venv/bin:$PATH" # Setup virtualenv to build dependancies into RUN python -m venv /opt/venv # Install python dependancies COPY requirements.txt ./requirements.txt RUN pip install --no-cache-dir -r requirements.txt ##################### # Condensed App Image ##################### # Smaller official Debian-based Python image FROM python:3.7-slim-stretch AS app # Set working directory WORKDIR /usr/src/app # Extra python env ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PATH="/opt/venv/bin:$PATH" # Setup the virtualenv RUN python -m venv /opt/venv # Copy in tools and python environment COPY --from=builder /opt/venv /opt/venv # Copy in the rest of the app COPY ./ /usr/src/app