Skip to content

Commit

Permalink
Add support for GitHub into the key chain. (#109)
Browse files Browse the repository at this point in the history
* We want to be able to run hydros in cluster and authenticate to GHCR
* To do that we include github.Keychain which will look for GITHUB_TOKEN
environment variable

  * see google/go-containerregistry#1252
  • Loading branch information
jlewi authored Oct 22, 2024
1 parent 56ddcdd commit cd8f1ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pkg/images/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/gcrane"
v1 "github.com/google/go-containerregistry/pkg/v1"
)

Expand All @@ -15,7 +14,7 @@ import (
//
// This is different from image downloader because that appears to download the manifest and individual blobs.
func ExportImage(src string, tarFilePath string) error {
options := []crane.Option{crane.WithAuthFromKeychain(gcrane.Keychain)}
options := []crane.Option{crane.WithAuthFromKeychain(keychain)}
var img v1.Image
desc, err := crane.Get(src, options...)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/images/keychain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package images

import (
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/authn/github"
"github.com/google/go-containerregistry/pkg/v1/google"
)

var (
// TODO(jeremy): Should we add support for Azure and AWS?
// see https://github.com/google/go-containerregistry/pull/1252/files#diff-d062be9a5715169ccabeaa8a2d525b7340f8ec9a7534b3a27dfd1ae35148de29
// for how we could do that.
// TODO(jeremy): Should we use K8s chain? https://github.com/google/go-containerregistry/blob/main/pkg/authn/k8schain/README.md
keychain = authn.NewMultiKeychain(
authn.DefaultKeychain,
google.Keychain,
github.Keychain,
)
)
5 changes: 2 additions & 3 deletions pkg/images/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/go-logr/zapr"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/gcrane"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand All @@ -27,8 +26,8 @@ type Replicator struct {
// NewReplicator creates a new Replicator.
func NewReplicator() (*Replicator, error) {
// TODO(jeremy): What's a better pattern for handling options for crane.
rOptions := []remote.Option{remote.WithAuthFromKeychain(gcrane.Keychain)}
options := []crane.Option{crane.WithAuthFromKeychain(gcrane.Keychain)}
rOptions := []remote.Option{remote.WithAuthFromKeychain(keychain)}
options := []crane.Option{crane.WithAuthFromKeychain(keychain)}

r := &Replicator{
rOptions: rOptions,
Expand Down

0 comments on commit cd8f1ad

Please sign in to comment.