Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency
Created July 16, 2018 05:08
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save knowsuchagency/e0ccd472e8ccf0cb6c378ebe467face4 to your computer and use it in GitHub Desktop.
Save knowsuchagency/e0ccd472e8ccf0cb6c378ebe467face4 to your computer and use it in GitHub Desktop.
Makefile Docker Git GitHub multi-stage build ssh private key recipe
FROM python:3 as build-system
RUN pip install -U pip
COPY requirements.txt requirements.txt
### create temporary image used to download and vendor packages using private key ###
FROM build-system as intermediate
# add credentials on build
ARG SSH_PRIVATE_KEY
RUN mkdir /root/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/*
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
# vendor python dependencies
RUN pip download -r requirements.txt -d /vendor/python
### create the runtime image ###
FROM build-system as runtime
# install vendored python dependencies
COPY --from=intermediate /vendor/python /vendor/python
RUN pip install /vendor/python/*
SSH_PRIVATE_KEY=`cat ~/.ssh/id_rsa`
build-image:
docker build . --build-arg SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY}"
git+ssh://git@github.com/{user-or-group}/{repo}.git@{optional-tag-or-commit_hash}#egg={package_name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment