Sage-Bionetworks/sage-monorepo

[Docs] Document a reproducible way to login into GitHub from the devcontainer

Closed this issue · 4 comments

What product(s) is this documentation issue for?

Sage Monorepo

Documentation issue

  • Reporting a typo
  • Reporting a documentation bug
  • Documentation improvement
  • Documentation feedback

Description

I had this issue in the past and the solution was not very clear at the time. I'm now having another issue with the following setup:

  1. WSL (Windows) => EC2 (AmazonLinux2023) => Devcontainer (Ubuntu)

Is there a specific documentation page you are reporting?

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

I tried installing GCM on AL2023 but this OS is not supported, at least by the install script:

$ curl -L https://aka.ms/gcm/linux-install-source.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  7233  100  7233    0     0  31600      0 --:--:-- --:--:-- --:--:-- 31600
This script will download, compile, and install Git Credential Manager to:

    /usr/local/bin

Git Credential Manager is licensed under the MIT License: https://aka.ms/gcm/license
ERROR: amzn is not officially supported by the GCM project.
See https://gh.io/gcm/linux for details.

Preview devcontainer (working)

On the host:

~/.gitconfig:

[user]
        email = thomas.schaffter@gmail.com
        name = Thomas Schaffter
[credential "https://github.com"]
        helper =
        helper = !/usr/bin/gh auth git-credential
[credential "https://gist.github.com"]
        helper =
        helper = !/usr/bin/gh auth git-credential

In the container:

~/.gitconfig:

[user]
        email = thomas.schaffter@gmail.com
        name = Thomas Schaffter
[credential "https://github.com"]
        helper = 
        helper = !/usr/bin/gh auth git-credential
[credential "https://gist.github.com"]
        helper = 
        helper = !/usr/bin/gh auth git-credential
[credential]
        helper = "!f() { /home/vscode/.vscode-server/bin/e170252f762678dec6ca2cc69aba1570769a5d39/node /tmp/vscode-remote-containers-bb7355d7-9d6c-4d02-aacf-c570382357d2.js git-credential-helper $*; }; f"

This comment mentions that VS Code is injecting the extra helper and copy the git configuration to the container. The git config is copied when the container is created.

Configure GitHub CLI as credential helper

Inside the devcontainer where the GH CLI is pre-installed:

$ gh auth login
$ gh auth setup-git

The content of ~/.gitconfig has been updated:

[credential]
        credentialStore = cache
        helper = "!f() { /home/vscode/.vscode-server/bin/e170252f762678dec6ca2cc69aba1570769a5d39/node /tmp/vscode-remote-containers-00eefd95-ad20-43f8-a57f-59253eeded22.js git-credential-helper $*; }; f"
[user]
        name = Thomas Schaffter
        email = thomas.schaffter@gmail.com
[credential "https://github.com"]
        helper = 
        helper = !/usr/bin/gh auth git-credential
[credential "https://gist.github.com"]
        helper = 
        helper = !/usr/bin/gh auth git-credential

I'm now able to push successfully to my fork.

I confirm that running the following two commands solve my problem, at least until I rebuild the dev container.

$ gh auth login
$ gh auth setup-git

A permanent solution to prevent the broken GitHub login popup to show up may be to update the VS Code config file to avoid VS Code from injecting the extra helper. This file being tracked with git, updating the config of the extra helper there would affect the environment of the other developers. If we do it, then we will need all to use the above two commands.

This microsoft/vscode-remote-release#5500 mentions that VS Code is injecting the extra helper and copy the git configuration to the container. The git config is copied when the container is created.