Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flag to Disable Push to Container Registry #292

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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