From e65b7b3ada3d92c6e08bf504b6baf42914c7d627 Mon Sep 17 00:00:00 2001 From: Rauny Date: Thu, 29 Apr 2021 12:23:43 -0300 Subject: [PATCH] add flag --no-push (#21) --- cmd/kaniko-docker/main.go | 6 ++++++ cmd/kaniko-ecr/main.go | 6 ++++++ cmd/kaniko-gcr/main.go | 6 ++++++ kaniko.go | 6 +++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/kaniko-docker/main.go b/cmd/kaniko-docker/main.go index 5547fde..8576d46 100644 --- a/cmd/kaniko-docker/main.go +++ b/cmd/kaniko-docker/main.go @@ -127,6 +127,11 @@ func main() { Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.", EnvVar: "PLUGIN_ARTIFACT_FILE", }, + cli.BoolFlag{ + Name: "no-push", + Usage: "Set this flag if you only want to build the image, without pushing to a registry", + EnvVar: "PLUGIN_NO_PUSH", + }, } if err := app.Run(os.Args); err != nil { @@ -155,6 +160,7 @@ func run(c *cli.Context) error { CacheRepo: c.String("cache-repo"), CacheTTL: c.Int("cache-ttl"), DigestFile: defaultDigestFile, + NoPush: c.Bool("no-push"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-ecr/main.go b/cmd/kaniko-ecr/main.go index 4d82704..7a34818 100644 --- a/cmd/kaniko-ecr/main.go +++ b/cmd/kaniko-ecr/main.go @@ -117,6 +117,11 @@ func main() { Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.", EnvVar: "PLUGIN_ARTIFACT_FILE", }, + cli.BoolFlag{ + Name: "no-push", + Usage: "Set this flag if you only want to build the image, without pushing to a registry", + EnvVar: "PLUGIN_NO_PUSH", + }, } if err := app.Run(os.Args); err != nil { @@ -144,6 +149,7 @@ func run(c *cli.Context) error { CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), CacheTTL: c.Int("cache-ttl"), DigestFile: defaultDigestFile, + NoPush: c.Bool("no-push"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-gcr/main.go b/cmd/kaniko-gcr/main.go index 20aac4d..4d8e8b6 100644 --- a/cmd/kaniko-gcr/main.go +++ b/cmd/kaniko-gcr/main.go @@ -113,6 +113,11 @@ func main() { Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.", EnvVar: "PLUGIN_ARTIFACT_FILE", }, + cli.BoolFlag{ + Name: "no-push", + Usage: "Set this flag if you only want to build the image, without pushing to a registry", + EnvVar: "PLUGIN_NO_PUSH", + }, } if err := app.Run(os.Args); err != nil { @@ -144,6 +149,7 @@ func run(c *cli.Context) error { CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), CacheTTL: c.Int("cache-ttl"), DigestFile: defaultDigestFile, + NoPush: c.Bool("no-push"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/kaniko.go b/kaniko.go index d9be685..f9f851a 100644 --- a/kaniko.go +++ b/kaniko.go @@ -26,6 +26,7 @@ type ( CacheRepo string // Remote repository that will be used to store cached layers CacheTTL int // Cache timeout in hours DigestFile string // Digest file location + NoPush bool // Set this flag if you only want to build the image, without pushing to a registry } // Artifact defines content of artifact file Artifact struct { @@ -34,7 +35,6 @@ type ( Registry string // Docker artifact registry RegistryType artifact.RegistryTypeEnum // Rocker artifact registry type ArtifactFile string // Artifact file location - } // Plugin defines the Docker plugin parameters. @@ -100,6 +100,10 @@ func (p Plugin) Exec() error { cmdArgs = append(cmdArgs, fmt.Sprintf("--digest-file=%s", p.Build.DigestFile)) } + if p.Build.NoPush { + cmdArgs = append(cmdArgs, fmt.Sprintf("--no-push")) + } + cmd := exec.Command("/kaniko/executor", cmdArgs...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr