Skip to content

Instantly share code, notes, and snippets.

@zynaxsoft
Last active March 6, 2020 05:43
Show Gist options
  • Save zynaxsoft/d055311397c57ea5c20af9a0c6d75ff9 to your computer and use it in GitHub Desktop.
Save zynaxsoft/d055311397c57ea5c20af9a0c6d75ff9 to your computer and use it in GitHub Desktop.
Dockerfile for private repo
FROM python:3.9-rc-buster as intermediate
COPY requirements.txt /app/
WORKDIR /app
ARG SSH_PRIVATE_KEY
# ssh setup
RUN mkdir /root/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" >> /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3 -m venv $VIRTUAL_ENV
RUN pip3 install -r requirements.txt
FROM python:3.9-rc-buster
COPY --from=intermediate /opt/venv /opt/venv
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
WORKDIR /app
COPY . /app
@zynaxsoft
Copy link
Author

zynaxsoft commented Feb 27, 2020

Building

export SSH_PRIVATE_KEY=$(cat /path/to/private.key)
docker build -t mytest:latest --build-arg SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY}" .
unset SSH_PRIVATE_KEY

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