Skip to content

Instantly share code, notes, and snippets.

@tuco86
Last active May 30, 2019 21:05
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuco86/67d84dfb27268b1faf05d2dbb1acb667 to your computer and use it in GitHub Desktop.
Save tuco86/67d84dfb27268b1faf05d2dbb1acb667 to your computer and use it in GitHub Desktop.
Build packages as wheels, then install in small container.
FROM python:3.7-slim-stretch AS build
RUN \
apt-get -q update \
&& apt-get -q install -y --no-install-recommends \
build-essential \
libssl-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pip install -U pip
WORKDIR /build
ADD constraints.txt /build/constraints.txt
ENV \
PIP_WHEEL_DIR=/build/wheelhouse \
PIP_NO_CACHE=true \
PIP_CONSTRAINTS=/build/constraints.txt
RUN pip wheel -r constraints.txt --no-cache-dir
FROM python:3.7-slim-stretch
RUN \
apt-get -q update \
&& apt-get -q upgrade -y \
&& apt-get -q install -y --no-install-recommends \
libssl1.1 \
&& rm -rf /var/lib/apt/lists/* \
&& pip install -U pip
COPY --from=build /build/wheelhouse /tmp/wheelhouse
WORKDIR /app
ADD setup.py /app/
ENV \
PIP_FIND_LINKS=/tmp/wheelhouse \
PIP_NO_INDEX=true \
PIP_NO_CACHE=true
RUN pip install -e .
ADD gunicorn.conf.py /app/
ADD src /app/src
RUN useradd app
USER app
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/gunicorn", "-b", ":8080", "-c", "gunicorn.conf.py", "app:load_wsgi_app()" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment