-
-
Save yashgiri/d4e434ccffed5c0f20fd51ff9e711e8a to your computer and use it in GitHub Desktop.
Experiment in using GitHub CLI to authenticate fetching docker images from GitHub Package Registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ~/docker/config.json | |
| { | |
| "credsStore": "desktop", | |
| "credHelpers": { | |
| "docker.pkg.github.com": "gh", | |
| "ghcr.io": "gh" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This "docker-credential-gh" utility should exist an as executable somewhere in PATH. | |
| # | |
| # Dependencies: gh | |
| # | |
| set -e | |
| cmd="$1" | |
| if [ "erase" = "$cmd" ]; then | |
| cat - >/dev/null | |
| exit 0 | |
| fi | |
| if [ "store" = "$cmd" ]; then | |
| cat - >/dev/null | |
| exit 0 | |
| fi | |
| if [ "get" != "$cmd" ]; then | |
| exit 1 | |
| fi | |
| host="$(cat -)" | |
| host="${host#https://}" | |
| host="${host%/}" | |
| if [ "$host" != "ghcr.io" ] && [ "$host" != "docker.pkg.github.com" ]; then | |
| exit 1 | |
| fi | |
| token="$(gh config get -h github.com oauth_token)" | |
| if [ -z "$token" ]; then | |
| exit 1 | |
| fi | |
| printf '{"Username":"%s", "Secret":"%s"}\n' "$(gh config get -h github.com user)" "$token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment