-
-
Save QasimK/6f28a8a7ace4fdd0a23e90a652b6c6d8 to your computer and use it in GitHub Desktop.
Exemplar multi-stage build for a very large Python project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.6.8-slim as base | |
RUN python -m venv /appenv | |
ENV PATH=/appenv/bin:$PATH | |
RUN pip install -U pip | |
# Only for old Docker versions | |
ENV TINI_VERSION v0.18.0 | |
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini | |
RUN chmod +x /tini | |
# ------------------------------------------------------------------------------------- | |
FROM base as wheels | |
RUN apt-get update && apt-get install -y --no-install-recommends build-essential | |
RUN pip install wheel | |
# ? | |
COPY deploy/wheelhouse /wheelhouse | |
# Generate all wheels | |
ENV PIP_WHEEL_DIR=/wheelhouse | |
ENV PIP_FIND_LINKS=/wheelhouse | |
COPY requirements.txt requirements.txt | |
RUN pip wheel -r requirements.txt; | |
# Package the application for later installation (APPNAME) | |
COPY . /application | |
RUN pip wheel /application; | |
# Use external wheelcache, e.g. on CodeFresh | |
VOLUME /wheelcache | |
CMD ["sh", "-c", "cp /wheelhouse/* /wheelcache"] | |
# ------------------------------------------------------------------------------------- | |
FROM base as install | |
COPY --from=wheels /wheelhouse /wheelhouse | |
COPY requirements.txt requirements.txt | |
RUN pip install --no-index -f /wheelhouse -r requirements.txt; \ | |
pip install --no-index -f /wheelhouse APPNAME | |
# ------------------------------------------------------------------------------------- | |
FROM base as installed | |
COPY --from=install /appenv /appenv | |
# ------------------------------------------------------------------------------------- | |
FROM installed AS adminserver | |
EXPOSE 80 443 | |
ENTRYPOINT ["/tini", "--"] | |
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:80", "api.admin:app", "--log-level=info", "--access-logfile=-"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment