Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FROM debian
- RUN apt-get update -y && \
- # SSH and git binaries are required
- apt-get install -y curl ssh git && \
- # Prepare required configurations and directories
- mkdir -p ~/.ssh && \
- git config --global user.name "example" && \
- git config --global user.email "git@example.com" && \
- touch /root/.ssh/known_hosts && \
- # We must add our git host to known_hosts file
- ssh-keyscan github.com >> ~/.ssh/known_hosts
- # Here is the most important yet tricky part.
- # When you add secrets to a BuildConfig with Docker strategy,
- # the secrets are being copied over relative to the actual Dockerfile,
- # so you would need to ADD/COPY the secrets to docker context (i.e. inside the container)
- ADD secrets /etc/secrets
- # Since git will use ssh-agent binary we must identify our SSH private key
- RUN eval "$(ssh-agent)" && ssh-agent -s && \
- chmod -R 0600 /etc/secrets && \
- ssh-add /etc/secrets/**/* && \
- # Use ssh remote to clone as usual
- git clone git@github.com:my-org/my-library.git && \
- ls -lash my-library/ && \
- # Do not keep SSH keys inside the image and remove them for better security
- rm -rf /etc/secrets
Add Comment
Please, Sign In to add comment