I have a private repo that is a dependency as a pip install. I have the proper ssh keys added to the repo I am running the pipeline on, but they are not working within the docker image. How do I get they keys in the docker container so the pip install won't fail?
I have added the following based off of other articles I have read, but once I get to ssh-add ~/.ssh/id_rsa, I get Error loading key "/root/.ssh/id_rsa": invalid format.
bitbucket-pipelines.yml
- step:
name: Build and Test
script:
- export SSH_PRIVATE_KEY=`cat /opt/atlassian/pipelines/agent/data/id_rsa`
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
- docker build . --file Dockerfile --tag ${IMAGE_NAME}
- docker save ${IMAGE_NAME} --output "${IMAGE_NAME}.tar"
services:
- docker
caches:
- docker
artifacts:
- "*.tar"
Dockerfile
ARG SSH_PRIVATE_KEY
RUN mkdir ~/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > ~.ssh/id_rsa
RUN chmod 600 ~/.ssh/id_rsa
RUN touch ~/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
RUN eval $(ssh-agent -s)
RUN ssh-add ~/.ssh/id_rsa
Hi, @Chance Gehrke! Welcome to the community!
Could you please try to use the following command to build the image?
- docker build --build-arg SSH_PRIVATE_KEY . --file Dockerfile --tag ${IMAGE_NAME}
I hope this helps, but do let me know if you have any questions.
Kind regards,
Caroline
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.