如何将 Go dep 与 GitLab 子组一起使用 [英] How to use Go dep with GitLab subgroups

查看:11
本文介绍了如何将 Go dep 与 GitLab 子组一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Go 项目,它需要来自私有 GitLab 存储库(如 git.mydomain.com/myteam/category/subcategory/project.git)的一些依赖项.但是我收到了这个错误.

确保 Solve(): https://git.mydomain.com/myteam/category.git 的远程存储库不存在或不可访问: : 退出状态 128

解决方案

这个问题在

  • 创建一个~/.netrc文件:

     机器 gitlab.com登录 <你的 gitlab 用户名>密码 <在步骤 1 中创建的令牌>

  • 稍微保护一下你的 .netrc 文件:

     chmod 600 ~/.netrc

  • 利润

  • 现在应该可以工作了:

     dep ensure -add gitlab.com/<company>/<subgroup>/<project>

    如果您使用的是私有 GitLab 安装,我相信您会在适用的情况下将 gitlab.com 替换为适当的主机名.

    I have a Go project that requires some dependencies from a private GitLab repository like git.mydomain.com/myteam/category/subcategory/project.git. But I'm getting this error.

    ensure Solve(): remote repository at https://git.mydomain.com/myteam/category.git does not exist or is inaccessible: : exit status 128
    

    解决方案

    This issue is discussed at length on the GitLab support tracker.

    TL;DR; It's (intentionally) broken for private repos:

    Is [your group] private? If so, this is expected behavior, and I would recommend reading the discussion from #1337 (comment 36293613) onwards. In this case, we have decided to maximize security/privacy at the slight expense of usability. The recommended workaround is to specifically add .git to your URL.

    The only solution I've found is to use go get's support for .netrc, which solves this both for dep, as well as modern Go modules.

    1. Create a Personal Access token on GitLab with api scope:

    2. Create a ~/.netrc file:

       machine gitlab.com
           login <your gitlab username>
           password <the token created in step 1>
      

    3. Protect your .netrc file a bit:

       chmod 600 ~/.netrc
      

    4. Profit

    This should now work:

        dep ensure -add gitlab.com/<company>/<subgroup>/<project>
    

    If you're using a private GitLab installation, I trust you to replace gitlab.com with the appropriate hostname where applicable.

    这篇关于如何将 Go dep 与 GitLab 子组一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆