Skip to content

Commit

Permalink
Make json key optional for GCR push (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham149 authored Oct 18, 2021
1 parent 0a35538 commit 5e7bcab
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/kaniko-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/urfave/cli"

kaniko "github.com/drone/drone-kaniko"
"github.com/drone/drone-kaniko/cmd/artifact"
"github.com/drone/drone-kaniko/pkg/artifact"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/kaniko-ecr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ecrpublic"
"github.com/aws/smithy-go"
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/joho/godotenv"
"github.com/pkg/errors"
Expand Down
12 changes: 5 additions & 7 deletions cmd/kaniko-gcr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/urfave/cli"

kaniko "github.com/drone/drone-kaniko"
"github.com/drone/drone-kaniko/cmd/artifact"
"github.com/drone/drone-kaniko/pkg/artifact"
)

const (
Expand Down Expand Up @@ -141,8 +141,10 @@ func run(c *cli.Context) error {
noPush := c.Bool("no-push")
jsonKey := c.String("json-key")

// only setup auth when pushing or credentials are defined
if !noPush || jsonKey != "" {
// JSON key may not be set in the following cases:
// 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 {
return err
}
Expand Down Expand Up @@ -178,10 +180,6 @@ func run(c *cli.Context) error {
}

func setupGCRAuth(jsonKey string) error {
if jsonKey == "" {
return fmt.Errorf("GCR JSON key must be specified")
}

err := ioutil.WriteFile(gcrKeyPath, []byte(jsonKey), 0644)
if err != nil {
return errors.Wrap(err, "failed to write GCR JSON key")
Expand Down
2 changes: 1 addition & 1 deletion kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os/exec"
"strings"

"github.com/drone/drone-kaniko/cmd/artifact"
"github.com/drone/drone-kaniko/pkg/artifact"
"golang.org/x/mod/semver"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5e7bcab

Please sign in to comment.