Last active
January 12, 2022 11:21
-
-
Save kennethreitz/e4e7e383536cf40d42109ece06440b40 to your computer and use it in GitHub Desktop.
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 ubuntu:19.04 | |
ENV DEBIAN_FRONTEND noninteractive | |
ENV LC_ALL C.UTF-8 | |
ENV LANG C.UTF-8 | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PIPENV_MAX_SUBPROCESS 64 | |
ENV PIPENV_SKIP_LOCK 1 | |
ENV PIP_EXISTS_ACTION a | |
# Setup mirrors, for faster downloads (main sources can be slow sometimes). | |
RUN set -ex && echo 'deb http://mirrors.digitalocean.com/ubuntu/ disco main universe' > /etc/apt/sources.list && \ | |
echo 'deb http://mirrors.digitalocean.com/ubuntu/ disco-security main universe' >> /etc/apt/sources.list && \ | |
echo 'deb http://mirrors.digitalocean.com/ubuntu/ disco-updates main universe' >> /etc/apt/sources.list | |
# -- Install system deps: | |
RUN set -ex && apt update && apt install python3-dev python3-pip enchant musl-dev libopenblas-dev -y | |
# -- Install Pipenv: | |
RUN set -ex && pip3 install pipenv==2018.11.26 --no-cache-dir | |
# -- Install Application into container: | |
RUN set -ex && mkdir /opt/pipeline | |
WORKDIR /opt/pipeline | |
COPY ./Pipfile /opt/pipeline/Pipfile | |
COPY ./Pipfile.lock /opt/pipeline/Pipfile.lock | |
RUN set -ex && mkdir -p /opt/pipeline/python/pipeline/vendor | |
COPY ./python/pipeline/vendor /opt/pipeline/python/pipeline/vendor | |
# Install Pipenv deps: | |
RUN set -ex && pip3 install Cython numpy pytest && pipenv install --system --deploy | |
# ------------------------ | |
# Multi-Stage Docker Build | |
# https://docs.docker.com/develop/develop-images/multistage-build/ | |
# | |
# This enables us to "start fresh", and copy our build artifacts (e.g. python packages), | |
# without the build depednecies in the final image (e.g. gcc and friends). | |
# ------------------------ | |
FROM ubuntu:19.04 | |
ENV DEBIAN_FRONTEND noninteractive | |
ENV LC_ALL C.UTF-8 | |
ENV LANG C.UTF-8 | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
# Setup mirrors, for faster downloads (main sources can be slow sometimes). | |
RUN echo 'deb http://mirrors.digitalocean.com/ubuntu/ disco main universe' > /etc/apt/sources.list && \ | |
echo 'deb http://mirrors.digitalocean.com/ubuntu/ disco-security main universe' >> /etc/apt/sources.list && \ | |
echo 'deb http://mirrors.digitalocean.com/ubuntu/ disco-updates main universe' >> /etc/apt/sources.list | |
RUN set -ex && apt update && apt install python3 enchant curl pandoc jq git poppler-utils aspell-en -y | |
RUN set -ex && curl -sL curl -sL https://deb.nodesource.com/setup_10.x | bash - && \ | |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ | |
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ | |
apt-get update -y && apt-get install yarn nodejs -y | |
# Install nodejs deps | |
COPY ./package.json /opt/pipeline/package.json | |
COPY ./yarn.lock /opt/pipeline/yarn.lock | |
RUN set -ex && yarn install --production | |
# Copy Python packages from previous build. | |
COPY --from=0 /usr/local/lib/python3.7/dist-packages/ /usr/local/lib/python3.7/dist-packages/ | |
COPY --from=0 /usr/lib/python3/dist-packages/ /usr/lib/python3/dist-packages/ | |
COPY --from=0 /usr/local/bin/pytest /usr/local/bin/pytest | |
# Copy | |
WORKDIR /opt/pipeline | |
COPY . /opt/pipeline | |
ARG git_hash | |
ENV GIT_HASH=$git_hash | |
CMD ["./pipeline.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not a fundamental difference but a performance enhancement for when you use it in a project:
Get speedier builds of your code changes by separating out the runtime (Python and node installs and stuff) into a base image that you publish separately and FROM that base image(s) instead.