Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang的Github Oauth代币_Github_Go_Oauth_Aws Code Deploy - Fatal编程技术网

Golang的Github Oauth代币

Golang的Github Oauth代币,github,go,oauth,aws-code-deploy,Github,Go,Oauth,Aws Code Deploy,我们使用AWS code deploy将Github项目部署到Ec2实例,每次它部署时都会请求Github用户名和密码来下载存储库。找到了以下解决方法 供应Uname和Pwd(非首选) 设置SSH密钥(不可能,因为实例不断更改ip) Oauth令牌 通过将Oauth添加到composer auth.json.composer/auth.json中,为PHP存储库设置Oauth 但是找不到一种方法来为Golang项目做到这一点。通常,我们希望在不显式提供凭据的情况下实现go-get 此问题有两种解

我们使用AWS code deploy将Github项目部署到Ec2实例,每次它部署时都会请求Github用户名和密码来下载存储库。找到了以下解决方法

  • 供应Uname和Pwd(非首选)
  • 设置SSH密钥(不可能,因为实例不断更改ip)
  • Oauth令牌
  • 通过将Oauth添加到composer auth.json.composer/auth.json中,为PHP存储库设置Oauth


    但是找不到一种方法来为Golang项目做到这一点。通常,我们希望在不显式提供凭据的情况下实现go-get

    此问题有两种解决方案:

  • 不要部署代码。Go是一种静态编译的编程语言。在您打算运行Go程序的服务器上不需要Go源代码
  • 不要使用
    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
    

  • @项目中的萨尔瓦多同事也面临着同样的问题。这是私人回购吗?@ltachi,你是否在使用
    go-get-xxx
    ?你试过了吗?@holys这涉及到用实例创建SSH密钥。所以,若实例发生故障并出现新的ip,则需要另一个SSH密钥。如果它是auth令牌,我可以编写一个启动脚本来正确安装它。而且-u似乎不起作用。@ltachi这对你有帮助吗
    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