Make json key optional for GCR push (#30)

This commit is contained in:
Shubham Agrawal
2021-10-18 17:06:53 +05:30
committed by GitHub
parent 0a35538489
commit 5e7bcabe6a
7 changed files with 8 additions and 10 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
kaniko "github.com/drone/drone-kaniko" kaniko "github.com/drone/drone-kaniko"
"github.com/drone/drone-kaniko/cmd/artifact" "github.com/drone/drone-kaniko/pkg/artifact"
) )
const ( const (
+1 -1
View File
@@ -14,7 +14,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ecrpublic" "github.com/aws/aws-sdk-go-v2/service/ecrpublic"
"github.com/aws/smithy-go" "github.com/aws/smithy-go"
kaniko "github.com/drone/drone-kaniko" kaniko "github.com/drone/drone-kaniko"
"github.com/drone/drone-kaniko/cmd/artifact" "github.com/drone/drone-kaniko/pkg/artifact"
"github.com/drone/drone-kaniko/pkg/docker" "github.com/drone/drone-kaniko/pkg/docker"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/pkg/errors" "github.com/pkg/errors"
+5 -7
View File
@@ -11,7 +11,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
kaniko "github.com/drone/drone-kaniko" kaniko "github.com/drone/drone-kaniko"
"github.com/drone/drone-kaniko/cmd/artifact" "github.com/drone/drone-kaniko/pkg/artifact"
) )
const ( const (
@@ -141,8 +141,10 @@ func run(c *cli.Context) error {
noPush := c.Bool("no-push") noPush := c.Bool("no-push")
jsonKey := c.String("json-key") jsonKey := c.String("json-key")
// only setup auth when pushing or credentials are defined // JSON key may not be set in the following cases:
if !noPush || jsonKey != "" { // 1. Image does not need to be pushed to GCR.
// 2. Workload identity is set on GKE in which pod will inherit the credentials via service account.
if jsonKey != "" {
if err := setupGCRAuth(jsonKey); err != nil { if err := setupGCRAuth(jsonKey); err != nil {
return err return err
} }
@@ -178,10 +180,6 @@ func run(c *cli.Context) error {
} }
func setupGCRAuth(jsonKey string) error { func setupGCRAuth(jsonKey string) error {
if jsonKey == "" {
return fmt.Errorf("GCR JSON key must be specified")
}
err := ioutil.WriteFile(gcrKeyPath, []byte(jsonKey), 0644) err := ioutil.WriteFile(gcrKeyPath, []byte(jsonKey), 0644)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to write GCR JSON key") return errors.Wrap(err, "failed to write GCR JSON key")
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/drone/drone-kaniko/cmd/artifact" "github.com/drone/drone-kaniko/pkg/artifact"
"golang.org/x/mod/semver" "golang.org/x/mod/semver"
) )