6

我们使用 AWS 代码部署将 Github 项目部署到 Ec2 实例,每次部署时都会询问 Github 用户名和密码以下载存储库。找到以下方法来解决这个问题

  1. 提供 Uname 和 Pwd(非首选)
  2. 设置 SSH 密钥(不可能,因为实例不断更改 ip)
  3. Oauth 令牌

为 PHP 存储库设置 Oauth 是通过将其添加到 composer auth.json .composer/auth.json 来完成的。

{
    "http-basic": {},
    "github-oauth": {"github.com": "xyzasasasauhu"}
}

但是找不到为 Golang 项目执行此操作的方法。通常,我们希望在不明确提供凭据的情况下实现go get https://github.com/username/reponame 。

4

1 回答 1

1

这个问题有两种解决方案:

  1. 不要部署代码。Go 是一种静态编译的编程语言。在您打算运行 Go 程序的服务器上不需要有 Go 源代码。
  2. 不要go get用于获取您的私有 GitHub 存储库的代码。只要代码最终位于正确的子目录 ( $GOPATH/src/github.com/org/project) 中,Go 就不会关心它是如何到达那里的。只需在构建脚本中添加一些命令:

    DIR=$GOPATH/src/github.com/org/project
    TOKEN=yourtoken
    
    if [ -d $DIR ]; then
      cd $DIR
      git reset --hard  
      git clean -dfx
    else
      mkdir -p $DIR
      cd $DIR
      git init  
    fi
    
    git pull https://$TOKEN@github.com/org/project.git
    
于 2015-12-17T03:05:41.220 回答