Authenticate to repo from image build

I am trying to connect to a private github repo using a token. I have tried a few variations and still get the error though I am using a token. Thank you :).

From alpine:3.15.4

ARG TOKEN

RUN apk add --no-cache --virtual build_deps \
git  \
  && git config --global url."https://${TOKEN}:@github.com/".insteadOf "https://github.com/" \
  && git clone https://${TOKEN}:x-oauth-basic@github.com/repo/xxx.git --branch=main

Build with:

docker image build -t test:1.0.0 --build-arg TOKEN={xxxxx} .

fatal: Authentication failed for 'https://github.com/repo/xxx.git/'
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead

Try this instead of your git clone:

git clone https://${TOKEN}:@github.com/repo/xxx.git --branch=main

So just don’t set the username. It worked for me with your Dockerfile

1 Like

Thank you very much, that worked :).