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

Optionally ignore image archive parse errors #287

Merged
merged 3 commits into from
Mar 8, 2020
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ No configuration is necessary, however, you can create a config file and overrid
```yaml
# supported options are "docker" and "podman"
container-engine: docker

# continue with analysis even if there are errors parsing the image archive
ignore-errors: false
log:
enabled: true
path: ./dive.log
Expand Down
19 changes: 13 additions & 6 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/wagoodman/dive/dive"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wagoodman/dive/runtime"
)

Expand Down Expand Up @@ -56,11 +57,17 @@ func doAnalyzeCmd(cmd *cobra.Command, args []string) {
imageStr = userImage
}

ignoreErrors, err := cmd.PersistentFlags().GetBool("ignore-errors")
if err != nil {
logrus.Error("unable to get 'ignore-errors' option:", err)
}

runtime.Run(runtime.Options{
Ci: isCi,
Source: sourceType,
Image: imageStr,
ExportFile: exportFile,
CiConfig: ciConfig,
Ci: isCi,
Source: sourceType,
Image: imageStr,
ExportFile: exportFile,
CiConfig: ciConfig,
IgnoreErrors: viper.GetBool("ignore-errors") || ignoreErrors,
})
}
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func initCli() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.dive.yaml, ~/.config/dive/*.yaml, or $XDG_CONFIG_HOME/dive.yaml)")
rootCmd.PersistentFlags().String("source", "docker", "The container engine to fetch the image from. Allowed values: "+strings.Join(dive.ImageSources, ", "))
rootCmd.PersistentFlags().BoolP("version", "v", false, "display version number")
rootCmd.PersistentFlags().BoolP("ignore-errors", "i", false, "ignore image parsing errors and run the analysis anyway")
rootCmd.Flags().BoolVar(&isCi, "ci", false, "Skip the interactive TUI and validate against CI rules (same as env var CI=true)")
rootCmd.Flags().StringVarP(&exportFile, "json", "j", "", "Skip the interactive TUI and write the layer analysis statistics to a given file.")
rootCmd.Flags().StringVar(&ciConfigFile, "ci-config", ".dive-ci", "If CI=true in the environment, use the given yaml to drive validation rules.")
Expand All @@ -62,6 +63,9 @@ func initCli() {
}
}

if err := ciConfig.BindPFlag("ignore-errors", rootCmd.PersistentFlags().Lookup("ignore-errors")); err != nil {
log.Fatalf("Unable to bind 'ignore-errors' flag: %v", err)
}
}

// initConfig reads in config file and ENV variables if set.
Expand Down Expand Up @@ -98,6 +102,7 @@ func initConfig() {
viper.SetDefault("filetree.show-attributes", true)

viper.SetDefault("container-engine", "docker")
viper.SetDefault("ignore-errors", false)

err = viper.BindPFlag("source", rootCmd.PersistentFlags().Lookup("source"))
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions runtime/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
)

type Options struct {
Ci bool
Image string
Source dive.ImageSource
ExportFile string
CiConfig *viper.Viper
BuildArgs []string
Ci bool
Image string
Source dive.ImageSource
IgnoreErrors bool
ExportFile string
CiConfig *viper.Viper
BuildArgs []string
}
6 changes: 4 additions & 2 deletions runtime/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ func run(enableUi bool, options Options, imageResolver image.Resolver, events ev
for _, err := range errors {
events.message(" " + err.Error())
}
events.exitWithError(fmt.Errorf("file tree has path errors"))
return
if !options.IgnoreErrors {
events.exitWithError(fmt.Errorf("file tree has path errors (use '--ignore-errors' to attempt to continue)"))
return
}
}

if enableUi {
Expand Down