Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker change .gitconfig with token for private repo access

I've been digging to solve the problem during docker build stages of accessing private repos. Seems like using 'tokens' is the easiest and reasonably secure way of achieving this.

I came across an article, explaining this. In the comments someone suggested an improvement to add a github token. I cannot get it to work inside docker. How can I change the .gitconfig and have git always use the token?

This command needs to be change to using the token:

RUN echo "[url \"[email protected]:\"]\n\tinsteadOf = https://github.com/" >> /root/.gitconfig

The comment:

A better approach would be to generate an api token with read only access to that repo and using something like git config --global url."https://${TOKEN}@github.com/".insteadOf "https://github.com/". This way you don't need a wrapper script or ssh host key checking, nor do you need bake your all access

It would be great if someone could help me cross the bridge. Thx

like image 610
Tino Avatar asked Mar 07 '23 10:03

Tino


1 Answers

I solved it by running the following RUN command. Make sure, to have the correct rights when generating the token on github.

FROM golang:1.9
RUN git config --global url."https://USERNAME:[email protected]/".insteadOf "https://github.com/"
....
like image 55
Tino Avatar answered Mar 10 '23 11:03

Tino