Skip to content

Instantly share code, notes, and snippets.

@fidiego
Created July 15, 2020 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fidiego/ea0cf6797ba226560eafc509bce18fab to your computer and use it in GitHub Desktop.
Save fidiego/ea0cf6797ba226560eafc509bce18fab to your computer and use it in GitHub Desktop.
# vim: syntax=dockerfile
### Multi-stage build
### 1. django: install dependencies
# FROM python:3.7.7-alpine3.11 for build step
FROM python@sha256:778802b5b9797279772814fb15a7c6ee494848ced17965bb57092a0b900c0e4f as builder
# install dependencies to build c-extensions
RUN apk update && apk add --no-cache \
gcc \
build-base \
libstdc++ \
libffi-dev \
linux-headers \
make \
musl-dev \
postgresql-dev==12.2-r0 && \
python -m pip install pipenv==2018.11.26
# set some env vars for python stuffs
ENV PIPENV_COLORBLIND=true \
PIPENV_HIDE_EMOJIS=true \
PIPENV_NOSPIN=true \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_NO_CACHE_DIR=off \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1 \
ENV=prod
# install python dependencies with pip
WORKDIR /code
COPY Pipfile Pipfile.lock /code/
RUN pipenv install --system --deploy --ignore-pipfile
# purge dependencies we only needed to build c-extensions
RUN apk del --purge \
gcc \
build-base \
linux-headers \
musl-dev \
make && \
rm -rf /root/.cache /tmp/* && \
find /usr -name '*.h' -type f -delete && \
{ find /usr/local/lib -name '*.dist-info' -exec rm -rf '{}' \; 2> /dev/null || true; }
# copy source
COPY . /code
ARG GIT_HEAD
ARG GIT_BRANCH
ENV GIT_HEAD=$GIT_HEAD \
GIT_BRANCH=$GIT_BRANCH
LABEL maintainer="tech@rapidresponse.io"
LABEL branch=$GIT_BRANCH
LABEL version=$GIT_HEAD
RUN pip install importlib_metadata # so we can build some wheels
CMD ["python", "manage.py", "preflight"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment