t j
t j

Reputation: 7324

Dockerhub automated builds with multiple private repos

Is there a way to connect to multiple private git repos during an automated dockerhub build? We are building golang apps and need to 'go get' other private repos as part of our build and at the moment they fail as docker can't connect to them, only the target private repo.

The main repo is fine as the deploy key is installed via Dockerhub, but any subsequent private repo imports fail.

One way around this I can see, is to build the image locally, "docker push" it to dockerhub and then pull it down on the deploy side which defeats the purpose of dockerhub and the automated build system. The other is to bake ssh keys into the base image which is not a great idea.

Does anyone have a solution to this that doesn't involve baking ssh keys into images or building locally?

Many thanks.

Upvotes: 11

Views: 1972

Answers (1)

damoiser
damoiser

Reputation: 6238

single ssh-key

If you have only one ssh-key, then adding it to the root ssh-path in the Docker container (/root/.ssh/id_rsa) should be enough to successfully pulling your repos. Depends where your private-repos are, you should probably add some other configs to the .ssh.

multiple ssh-keys

If you have differents ssh-keys I suggest you to create a personal token for all your repos. So you can resolve easily the problem. You should update the git-url before getting:

[ taken from here: https://gist.github.com/shurcooL/6927554 ]

git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"

With this change, you should be able to build successfully your docker-container.


Using a vendor-tool can help you solving this. From go1.5 the vendoring feature is at disposal. We are using Glide and it stores the references only (not the wholes projects).

Upvotes: 1

Related Questions