Compare commits

..

3 Commits

Author SHA1 Message Date
Ompragash Viswanathan eee08bbac3 Add robust GAR authentication with Docker config and crane options 2025-05-13 16:20:21 +05:30
Ompragash Viswanathan 4c65ff4509 Refactor GAR authentication and crane push to use Application Default Credentials 2025-05-13 13:46:08 +05:30
Ompragash Viswanathan ef62817264 Add push-only support to Kaniko-GAR 2025-05-12 20:24:42 +05:30
2 changed files with 9 additions and 6 deletions
+2 -2
View File
@@ -37,7 +37,7 @@ pipeline:
identifier: Build
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: golang:1.23.0
image: golang:1.22.4
shell: Sh
command: |-
go test ./...
@@ -322,7 +322,7 @@ pipeline:
identifier: Build_and_Test
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: golang:1.23.0
image: golang:1.22.4
shell: Sh
command: |-
go test ./...
+7 -4
View File
@@ -513,11 +513,13 @@ func handlePushOnly(c *cli.Context) error {
// Setup GAR authentication
jsonKey := c.String("json-key")
if jsonKey != "" {
// Setup standard env variable auth which didn't work
if err := setupGARAuth(jsonKey); err != nil {
return err
}
logrus.Info("Setting up authentication for GAR")
// Try an alternative approach: create a Docker config.json with GAR credentials
logrus.Info("Setting up Docker config authentication for GAR")
// Create Docker config directory if it doesn't exist
dockerConfigDir := "/kaniko/.docker"
@@ -566,6 +568,7 @@ func handlePushOnly(c *cli.Context) error {
if err := os.Setenv("DOCKER_CONFIG", dockerConfigDir); err != nil {
return fmt.Errorf("failed to set DOCKER_CONFIG environment variable: %v", err)
}
logrus.Infof("Set DOCKER_CONFIG to %s", dockerConfigDir)
// Set up crane to use basic auth with docker config
opts = append(opts, crane.WithAuthFromKeychain(authn.DefaultKeychain))
@@ -589,11 +592,11 @@ func handlePushOnly(c *cli.Context) error {
for _, tag := range tags {
dest := fmt.Sprintf("%s/%s:%s", registry, repo, tag)
logrus.Infof("Pushing image to: %s", dest)
if err := crane.Push(img, dest, opts...); err != nil {
return fmt.Errorf("failed to push image to %s: %v", dest, err)
}
logrus.Infof("Successfully pushed image to %s", dest)
}