diff --git a/Dockerfile b/Dockerfile index 9c8e6fd..20e1c16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o windows-kantra main.g FROM quay.io/konveyor/analyzer-lsp:latest -RUN mkdir /opt/rulesets /opt/rulesets/input /opt/rulesets/convert /opt/openrewrite /opt/input /opt/output /opt/xmlrules /opt/shimoutput +RUN mkdir /opt/rulesets /opt/rulesets/input /opt/rulesets/convert /opt/openrewrite /opt/input /opt/input/rules /opt/input/rules/custom /opt/output /opt/xmlrules /opt/shimoutput COPY --from=builder /workspace/kantra /usr/local/bin/kantra COPY --from=builder /workspace/darwin-kantra /usr/local/bin/darwin-kantra diff --git a/cmd/analyze.go b/cmd/analyze.go index c30cbd0..65d2d33 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -60,6 +60,7 @@ type analyzeCommand struct { mode string rules []string jaegerEndpoint string + enableDefaultRulesets bool // tempDirs list of temporary dirs created, used for cleanup tempDirs []string @@ -158,6 +159,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command { analyzeCommand.Flags().BoolVar(&analyzeCmd.jsonOutput, "json-output", false, "create analysis and dependency output as json") analyzeCommand.Flags().BoolVar(&analyzeCmd.overwrite, "overwrite", false, "overwrite output directory") analyzeCommand.Flags().StringVar(&analyzeCmd.jaegerEndpoint, "jaeger-endpoint", "", "jaeger endpoint to collect traces") + analyzeCommand.Flags().BoolVar(&analyzeCmd.enableDefaultRulesets, "enable-default-rulesets", true, "run default rulesets with analysis") return analyzeCommand } @@ -229,6 +231,9 @@ func (a *analyzeCommand) Validate() error { if absPath, err := filepath.Abs(a.mavenSettingsFile); a.mavenSettingsFile != "" && err == nil { a.mavenSettingsFile = absPath } + if !a.enableDefaultRulesets && len(a.rules) == 0 { + return fmt.Errorf("must specify rules if default rulesets are not enabled") + } return nil } @@ -526,7 +531,12 @@ func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) { } } else { - rulesVolumes[r] = path.Join(RulesMountPath, filepath.Base(r)) + if !a.enableDefaultRulesets { + rulesVolumes[r] = path.Join(CustomRulePath, filepath.Base(r)) + } else { + rulesVolumes[r] = path.Join(RulesMountPath, filepath.Base(r)) + } + } } if rulesetNeeded { @@ -536,7 +546,11 @@ func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) { a.log.V(1).Error(err, "failed to create temp ruleset", "path", tempRulesetPath) return nil, err } - rulesVolumes[tempDir] = path.Join(RulesMountPath, filepath.Base(tempDir)) + if !a.enableDefaultRulesets { + rulesVolumes[tempDir] = path.Join(CustomRulePath, filepath.Base(tempDir)) + } else { + rulesVolumes[tempDir] = path.Join(RulesMountPath, filepath.Base(tempDir)) + } } return rulesVolumes, nil } @@ -582,9 +596,13 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e // output directory a.output: OutputPath, } - + var convertPath string if xmlOutputDir != "" { - convertPath := path.Join(RulesetPath, "convert") + if !a.enableDefaultRulesets { + convertPath = path.Join(CustomRulePath, "convert") + } else { + convertPath = path.Join(RulesetPath, "convert") + } volumes[xmlOutputDir] = convertPath // for cleanup purposes a.tempDirs = append(a.tempDirs, xmlOutputDir) @@ -608,10 +626,16 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e args := []string{ fmt.Sprintf("--provider-settings=%s", ProviderSettingsMountPath), - fmt.Sprintf("--rules=%s/", RulesetPath), fmt.Sprintf("--output-file=%s", AnalysisOutputMountPath), fmt.Sprintf("--context-lines=%d", 100), } + if a.enableDefaultRulesets { + args = append(args, + fmt.Sprintf("--rules=%s/", RulesetPath)) + } else { + args = append(args, + fmt.Sprintf("--rules=%s/", CustomRulePath)) + } if a.jaegerEndpoint != "" { args = append(args, "--enable-jaeger") args = append(args, "--jaeger-endpoint") diff --git a/cmd/settings.go b/cmd/settings.go index d79a027..e234bb9 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -17,6 +17,7 @@ const ( OutputPath = "/opt/output" XMLRulePath = "/opt/xmlrules" ShimOutputPath = "/opt/shimoutput" + CustomRulePath = "/opt/input/rules" ) type Config struct {