sh: git: not found || Could not authenticate against github.com

Viewed 712

sh: git: not found || Could not authenticate against github.com

Above was the error I was getting from a make rebuild command that runs a bunch of stuff, the solution that I/we used to solve that was to add Git personal access token to work mac keychain and then add

"config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "github-oauth": {
            "github.com": "foobar"
        }
    }

github-oauth to my composer.json so that the work project builds, then I've deleted the github-oauth from the composer.json so the project is up and I can code away, but my issue is that this is going to happen at the next rebuild.

Basically my question is - how do you authenticate against github with a personal access token, on a shared project that is Dockerised? I expect the answer is to have your personal access token in an env for each user locally stored, but I am a junior and am not sure how you would go about this.

It is built in circle-ci so could we share a github account and store the personal access token in the env of there? I don't want my personal access token to become public / remote of course.

1 Answers

Here is how I handle this situation, create a file containing the auth token and this file should not be commited to your vcs, here is an example for git:

//.gitignore
docker/php/auth.json
//docker/php/auth.json
{
    "github-oauth": {
        "github.com": "YOUR_TOKEN"
    }
}
# Dockerfile
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

#Copy your token
COPY docker/php/auth.json /root/.composer/auth.json

#Then you can call composer
composer install

Projet structure:

docker/
    php/
        auth.json
.gitignore
Dockerfile

Hope this help

Related