6

We use AWS code deploy to deploy the Github projects to Ec2 instances every time it deploys it asks for Github username and password to download the repository. Found following ways to solve this

  1. Supply Uname & Pwd (not preferred)
  2. Setup SSH Key (not possible as the instance keeps changing ip)
  3. Oauth token

Setting up Oauth for PHP repository was done by adding it in composer auth.json .composer/auth.json.

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

But couldn't find a way to do this for Golang project. Typically we want to achieve go get https://github.com/username/reponame without supplying the credentials explicitly.

Itachi
  • 1,383
  • 11
  • 22
  • @SalvadorDali Colleagues in the project facing the same issue. – Itachi Nov 30 '15 at 06:06
  • Is it a private repo? – holys Nov 30 '15 at 07:58
  • @ltachi, are you using `go get xxx` ? Did you try this?https://gist.github.com/shurcooL/6927554 – holys Nov 30 '15 at 10:33
  • @holys This involves creating SSH key with the instance. So if instance goes down and comes up with new ip another SSH key is required. If it is auth token i can write a start up script to install it right. Also -u doesn't seem to work. – Itachi Nov 30 '15 at 10:41
  • @ltachi Does this do any help for you ?https://github.com/golang/go/issues/10791 – holys Nov 30 '15 at 10:43

1 Answers1

2

There are two solutions to this problem:

  1. Don't deploy code. Go is a statically compiled programming language. There's no need to have Go source code on the server you intend to run the Go program on.
  2. Don't use go get to get the code for your private GitHub repo. As long as the code ends up in the correct subdirectory ($GOPATH/src/github.com/org/project), Go doesn't care how it got there. Simply add to your build script a few commands:

    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
    
Caleb
  • 9,272
  • 38
  • 30