Skip to content

Commit

Permalink
Merge pull request #292 from rawkode/feature/allow-build-only
Browse files Browse the repository at this point in the history
Add Flag to Disable Push to Container Registry
  • Loading branch information
priyawadhwa authored Aug 17, 2018
2 parents 60bdda4 + 4535039 commit 10efecb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ Set this flag as `--tarPath=<path>` to save the image as a tarball at path inste

Set this flag to indicate which build stage is the target build stage.

#### --no-push

Set this flag if you only want to build the image, without pushing to a registry.

### Debug Image

The kaniko executor image is based off of scratch and doesn't contain a shell.
Expand Down
12 changes: 11 additions & 1 deletion cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ var (
singleSnapshot bool
reproducible bool
target string
noPush bool
)

func init() {
RootCmd.PersistentFlags().StringVarP(&dockerfilePath, "dockerfile", "f", "Dockerfile", "Path to the dockerfile to be built.")
RootCmd.PersistentFlags().StringVarP(&srcContext, "context", "c", "/workspace/", "Path to the dockerfile build context.")
RootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "", "Name of the GCS bucket from which to access build context as tarball.")
RootCmd.PersistentFlags().VarP(&destinations, "destination", "d", "Registry the final image should be pushed to. Set it repeatedly for multiple destinations.")
RootCmd.MarkPersistentFlagRequired("destination")
RootCmd.PersistentFlags().StringVarP(&snapshotMode, "snapshotMode", "", "full", "Set this flag to change the file attributes inspected during snapshotting")
RootCmd.PersistentFlags().VarP(&buildArgs, "build-arg", "", "This flag allows you to pass in ARG values at build time. Set it repeatedly for multiple values.")
RootCmd.PersistentFlags().BoolVarP(&dockerInsecureSkipTLSVerify, "insecure-skip-tls-verify", "", false, "Push to insecure registry ignoring TLS verify")
Expand All @@ -62,6 +62,7 @@ func init() {
RootCmd.PersistentFlags().BoolVarP(&singleSnapshot, "single-snapshot", "", false, "Set this flag to take a single snapshot at the end of the build.")
RootCmd.PersistentFlags().BoolVarP(&reproducible, "reproducible", "", false, "Strip timestamps out of the image to make it reproducible")
RootCmd.PersistentFlags().StringVarP(&target, "target", "", "", " Set the target build stage to build")
RootCmd.PersistentFlags().BoolVarP(&noPush, "no-push", "", false, "Do not push the image to the registry")
}

var RootCmd = &cobra.Command{
Expand All @@ -73,6 +74,10 @@ var RootCmd = &cobra.Command{
if err := resolveSourceContext(); err != nil {
return err
}
if !noPush && len(destinations) == 0 {
return errors.New("You must provide --destination, or use --no-push")
}

return checkDockerfilePath()
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -101,6 +106,11 @@ var RootCmd = &cobra.Command{
os.Exit(1)
}

if noPush {
logrus.Info("Skipping push to container registry due to --no-push flag")
os.Exit(0)
}

if err := executor.DoPush(image, destinations, tarPath, dockerInsecureSkipTLSVerify); err != nil {
logrus.Error(err)
os.Exit(1)
Expand Down

0 comments on commit 10efecb

Please sign in to comment.