Skip to content

Instantly share code, notes, and snippets.

@ZipFile
Created August 4, 2018 20:39
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 ZipFile/b2b059debeaaf16f0d5abe199e7fbd84 to your computer and use it in GitHub Desktop.
Save ZipFile/b2b059debeaaf16f0d5abe199e7fbd84 to your computer and use it in GitHub Desktop.
Multistage build with private repo on GitHub. Python/Django app.
FROM ubuntu:bionic as build-base
ENV PYTHONUNBUFFERED 1
ARG SSH_KEY
RUN apt-get update && \
apt-get install -y build-essential \
libprotobuf-dev \
libhiredis-dev \
libxml2-dev \
libxslt1-dev \
python3-all-dev \
python3-venv \
postgresql-server-dev-all \
git \
openssh-client
RUN mkdir -p /root/.ssh
RUN ssh-keyscan github.com > /root/.ssh/known_hosts
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa && chmod 0600 /root/.ssh/id_rsa
COPY . /app
WORKDIR /app
RUN python3 -m venv /env
ENV PATH "/env/bin:$PATH"
RUN pip install --upgrade pip setuptools wheel
RUN pip install --upgrade raven
RUN pip install --upgrade grpcio grpcio-tools
RUN pip install git+ssh://git@github.com/mycorp/myproj-utils.git#egg=myproj-utils[kube,sentry]
RUN pip install -e .
RUN pip uninstall -y grpcio-tools
FROM ubuntu:bionic
RUN adduser --system --ingroup users user
RUN apt-get update && \
apt-get install -y ca-certificates \
libprotobuf10 \
libhiredis0.13 \
python3-all \
libxml2 \
libxslt1.1 \
postgresql-client \
uwsgi \
uwsgi-plugin-python3
COPY --from=build-base /env /env
COPY --from=build-base /app /app
WORKDIR /app
ENV PATH "/env/bin:$PATH"
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE "myproj.settings"
ENV GRPC_ENABLE_FORK_SUPPORT "True"
USER user:users
ENTRYPOINT ["./manage.py"]
@ZipFile
Copy link
Author

ZipFile commented Aug 4, 2018

export TAG="$(./setup.py --name):v$(./setup.py --version)"
export REGISTRY="eu.gcr.io/myrepo"

docker build --no-cache --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -t "${TAG}" -t "${REGISTRY}/${TAG}" .
docker image prune --force --filter dangling=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment