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

Suppress usage upon Run error #356

Merged
merged 1 commit into from
Sep 14, 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
18 changes: 13 additions & 5 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cmd

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -59,21 +60,23 @@ var RootCmd = &cobra.Command{
}
return resolveDockerfilePath()
},
RunE: func(cmd *cobra.Command, args []string) error {
Run: func(cmd *cobra.Command, args []string) {
if !checkContained() {
if !force {
return errors.New("kaniko should only be run inside of a container, run with the --force flag if you are sure you want to continue")
exit(errors.New("kaniko should only be run inside of a container, run with the --force flag if you are sure you want to continue"))
}
logrus.Warn("kaniko is being run outside of a container. This can have dangerous effects on your system")
}
if err := os.Chdir("/"); err != nil {
return errors.Wrap(err, "error changing to root dir")
exit(errors.Wrap(err, "error changing to root dir"))
}
image, err := executor.DoBuild(opts)
if err != nil {
return errors.Wrap(err, "error building image")
exit(errors.Wrap(err, "error building image"))
}
if err := executor.DoPush(image, opts); err != nil {
exit(errors.Wrap(err, "error pushing image"))
}
return executor.DoPush(image, opts)
},
}

Expand Down Expand Up @@ -158,3 +161,8 @@ func resolveSourceContext() error {
logrus.Debugf("Build context located at %s", opts.SrcContext)
return nil
}

func exit(err error) {
fmt.Println(err)
os.Exit(1)
}
2 changes: 1 addition & 1 deletion pkg/config/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (b *multiArg) String() string {

// The second method is Set(value string) error
func (b *multiArg) Set(value string) error {
logrus.Infof("appending to multi args %s", value)
logrus.Debugf("appending to multi args %s", value)
*b = append(*b, value)
return nil
}
Expand Down