Skip to content

Instantly share code, notes, and snippets.

@ColeMurray
Last active July 19, 2023 03:35
Show Gist options
  • Save ColeMurray/d376cc472b5e30b48be07f6ad9326d89 to your computer and use it in GitHub Desktop.
Save ColeMurray/d376cc472b5e30b48be07f6ad9326d89 to your computer and use it in GitHub Desktop.
basic-multi-layer-docker-build
FROM python:3.10-slim as sources
RUN apt-get -y update --fix-missing
ENV DEBIAN_FRONTEND=noninteractive
ARG SSH_KEY_PRIV
RUN apt-get update -qq && apt-get install -y git openssh-server
# Authorize SSH Host
RUN mkdir -p /root/.ssh && \
chmod 0700 /root/.ssh && \
ssh-keyscan github.com > /root/.ssh/known_hosts
# Add the keys and set permissions
RUN echo "${SSH_KEY_PRIV}" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa
RUN eval `ssh-agent -s` && ssh-add $HOME/.ssh/id_rsa
# do activities requiring the private key
pip install requirements.txt
FROM python:3.10-slim as production
RUN apt-get -y update --fix-missing
COPY --from=sources /opt/app /opt/app
COPY --from=sources /opt/app/venv /opt/app/venv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment