GitLab is a free, open-source way to host private .git
repositories but it does not seem to work with Go. When you create a project it generates a URL of the form:
git@1.2.3.4:private-developers/project.git
where:
1.2.3.4
is the IP address of the gitlab serverprivate-developers
is a user group which has access to the private repo
Golang 1.2.1 doesn't seem to understand this syntax.
go get git@1.2.3.4:private-developers/project.git
results in:
package git@23.251.148.129/project.git: unrecognized import path "git@1.2.3.4/project.git"
Is there a way to get this to work?
This issue is now resolved in Gitlab 8.* but is still unintuitive. The most difficult challenge indeed is
go get
and the following steps will allow you to overcome those:Create an SSH key pair. Be sure to not overwrite an existing pair that is by default saved in
~/.ssh/
.Create a new Secret Variable in your Gitlab project. Use
SSH_PRIVATE_KEY
as Key and the content of your private key as Value.Modify your
.gitlab-ci.yml
with abefore_script
.Add the public key from the key pair created in step 1 as a Deploy Key in the project that you need to
go get
.For the record, this works outside of go using gitlab 7.3.2 and, as JimB has observed, can be used as a workaround. I find that i do get prompted for username/password, even though an SSH key is registered with gitlab:
Alternatively i can use the SSH equivalent which, since i have an SSH key registered with gitlab, avoids the prompts:
Neither works with go currently. A fix may be in 7.9 but i haven't had a chance to test it: upcoming bugfix
The way I usually do it is:
Ensure you are using SSH.
once that's done you can configure your git to use
ssh
insteadhttps
If you are using Mac OX. you can run vim ~/.gitconfig and add
once configured you can run
I hope that helps.
From dep version 5.2,
dep
supports private repositories for Gitlab private repositories.On .netrc file, you can provide your Gitlab username and access token for accessing private repositories.
.netrc
file in your $HOME directory.netrc
with your Gitlab credentialsdep
command to resolve private packages. In this case,Gitlab does support
go get
natively.go get
will issue an http request to the url you provide and look for meta tags that point to the exact source control path.For my gitlab installation this is
mygitlabdomain.com/myProject/myRepo
. For you I assume this would be1.2.3.4/private-developers/project
.Unfortunately it only appears to give the http scm path, not the ssh path, so I had to enter my credentials to clone. You can easily fiddle with the remote in your local repository after it clones if you want to update to the ssh url.
You can test the url by poking
http://1.2.3.4:private-developers/project?go-get=1
and viewing source and looking for the meta tag.If
go get
can't fetch the repo, you can always do the initial clone with git directly:The tools will then work normally, expect for
go get -u
which will require the-f
flag because the git remote doesn't match the canonical import path.