Clone private repository in Dockerfile using access token during CI docker build

I’m currently using Docker secrets to clone a private (GitLab) repo in my Dockerfile during the CI build.


DOCKER_BUILDKIT=1 docker build --secret id=credentials,src=secrets.json --pull -t $CI_REGISTRY_IMAGE:$version .




RUN --mount=type=secret,id=credentials,required \
    git clone https://$(cat /run/secrets/credentials | jq -r '."gitlab_username"'):$(cat /run/secrets/credentials | jq -r '."gitlab_token"') --branch=develop /var/www/

How can I clone a private repo (in my Dockerfile) without having to have the secrets.json file in the docker build repo?