Golang and dependencies from private git repositories

Viewed 471

Let's assume that I have a Go project that depends on 2 different private repositories from github. I'm using deployment keys, for github authentication. I'm trying to set up CI to build, test and deploy the whole thing.

CI created environment with all 2 deploy ssh keys in place (lets call them ~/.ssh/key1 and ~/.ssh/key2)

When I run go build, it tries to download all dependencies at once. How can I avoid exception that repo does not exist (due to authentication issues)? How would you approach solving that problem?

1 Answers

If you are working with two different keys, you would need to modify the URL of those dependencies in order to reference those separate keys.

That is done through a ~/.ssh/config (assuming the Jenkins agent is run with the right user, and does have access to ~/.ssh/config

In that ~/.ssh/config, you declare two 'Host' entries, each one referencing their own private key:

Host repo1
  User git
  Hostname git.server.com
  IdentityFile ~/.ssh/key1

Host repo2
  User git
  Hostname git.server.com
  IdentityFile ~/.ssh/key2

Then make sure the dependency for repo1, for instance, is no longer git@git.server.com:aUser/aRepo but:

repo1:aUser/aRepo
Related