Skip to content

Commit

Permalink
improve logging and add demo images
Browse files Browse the repository at this point in the history
  • Loading branch information
yashbhutwala committed Aug 29, 2020
1 parent dedbe91 commit 44e594d
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 21 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

This plugin runs Black Duck Image Scans for software composition analysis. Just point and scan images in any namespace, third-party or your own yaml files, helm charts and more. It also suggests image upgrades for outdated images. Check out the [future section here](#future) for exciting coming soon features!

See [demo images here](./examples/)

![Image of bd-xray output table](./examples/demo/bd-xray.png)
![Image of results in Black Duck UI](./examples/demo/bd-image-version.png)

TODO: put video here

<!-- omit in toc -->
## Table of Contents

Expand Down
Binary file added examples/demo/bd-alpine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/demo/bd-image-version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/demo/bd-namespace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/demo/bd-scans.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/demo/bd-ubuntu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/demo/bd-xray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 8 additions & 9 deletions pkg/bd-xray/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func BlockOnDoneChan(doneChan chan bool) {
log.Tracef("blocking on done channel")
select {
case <-doneChan:
log.Infof("All done!")
log.Debugf("All image scans completed!")
}
}

Expand All @@ -129,7 +129,6 @@ func RunMultipleImageScansConcurrently(ctx context.Context, cancellationFunc con

for _, image := range imageList {
image := image
log.Infof("Scanning image: %s", image)
scanStatusRow := &ScanStatusRow{}
goRoutineGroup.Add(func() error {
return RunImageScanCommand(ctx, detectClient, image, detectPassThroughFlagsMap, scanStatusRow, scanStatusRowChan, projectName)
Expand Down Expand Up @@ -186,12 +185,12 @@ func RunImageScanCommand(ctx context.Context, detectClient *detect.Client, fullI
}

// parsing output infos
log.Infof("finding scan status file from uniqueOutputDirName: %s", uniqueOutputDirName)
log.Tracef("finding scan status file from uniqueOutputDirName: %s", uniqueOutputDirName)
statusFilePath, err := detect.FindScanStatusFile(uniqueOutputDirName)
if err != nil {
return err
}
log.Infof("statusFilePath is known to be: %s", statusFilePath)
log.Tracef("statusFilePath: %s", statusFilePath)
statusJSON, err := detect.ParseStatusJSONFile(statusFilePath)
if err != nil {
return err
Expand All @@ -203,7 +202,7 @@ func RunImageScanCommand(ctx context.Context, detectClient *detect.Client, fullI
return nil
}
location := locations[0]
log.Infof("location in Black Duck: %s", location)
log.Tracef("BlackDuckURL: %s", location)

// fill in all the rows
scanStatusRow.ImageName = imageName
Expand All @@ -225,7 +224,7 @@ func RunImageScanCommand(ctx context.Context, detectClient *detect.Client, fullI
}
scanStatusRow.LatestAvailableImageVersion = latestVersion

log.Infof("Sending output to Table Printer %s %s %s", scanStatusRow.ImageName, scanStatusRow.BlackDuckURL, scanStatusRow.LatestAvailableImageVersion)
log.Tracef("sending to printer: '%s' '%s' '%s'", scanStatusRow.ImageName, scanStatusRow.BlackDuckURL, scanStatusRow.LatestAvailableImageVersion)
scanStatusRowChan <- scanStatusRow

return err
Expand Down Expand Up @@ -256,11 +255,11 @@ func PrintScanStatusTable(scanStatusRowChan <-chan *ScanStatusRow, printingFinis
fmt.Sprintf("%s", row.BlackDuckURL),
fmt.Sprintf("%s", row.LatestAvailableImageVersion),
})
fmt.Printf("Intermediate Table: \n%s\n\n", t.Render())
log.Tracef("rendering intermediate table")
fmt.Printf("\n%s\n\n", t.Render())
}
// TODO: to be able to render concurrently
log.Tracef("rendering the table")
fmt.Printf("\n%s\n\n", t.Render())
log.Tracef("finished rendering table")
printingFinishedChannel <- true
close(printingFinishedChannel)
}
4 changes: 2 additions & 2 deletions pkg/detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *Client) DownloadDetectIfNotExists() error {

func (c *Client) RunImageScan(fullImageName, projectName, imageName, imageTag, outputDirName, userSpecifiedDetectFlags string) error {
var err error
log.Infof("scanning: %s", fullImageName)
log.Infof("scanning: '%s'", fullImageName)

// a unique string, but something that's human readable, i.e.: NAME_TAG
uniqueSanitizedString := util.SanitizeString(fmt.Sprintf("%s_%s", imageName, imageTag))
Expand Down Expand Up @@ -275,7 +275,7 @@ func (c *Client) GetPersistentDockerInspectorServicesFlags() string {
func (c *Client) SetupPersistentDockerInspectorServices() error {
var err error
// first setup docker-inspector
succeeded := util.RunBash("runDetectAgainstDockerServices", RunDetectAgainstDockerServicesBashScript)
succeeded := util.RunBash("set up persistent docker inspector services for concurrent scanning", RunDetectAgainstDockerServicesBashScript)
if !succeeded {
return errors.Errorf("error running the runDetectAgainstDockerServices script directly from golang")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/kubeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (kc *Client) ListPods(ctx context.Context, namespace string) (*corev1.PodLi
}

func (kc *Client) ListDeployments(ctx context.Context, namespace string) (*appsv1.DeploymentList, error) {
log.Infof("listing deployments in namespace: '%s'; equivalent to 'kubectl get deployments -n %s'", namespace, namespace)
log.Debugf("listing deployments in namespace: '%s'; equivalent to 'kubectl get deployments -n %s'", namespace, namespace)
deploymentList, err := kc.Clientset.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{})
return deploymentList, errors.Wrapf(err, "could not get a list of deployments in namespace: '%s'", namespace)
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ func RunCommand(cmd *exec.Cmd) (string, error) {
if 0 == len(currDirectory) {
currDirectory, _ = os.Executable()
}
log.Infof("started command: '%s' in directory: '%s'", cmd.String(), currDirectory)
log.Debugf("executing subcommand: '%s' from parent command directory: '%s'\n\n", cmd.String(), currDirectory)
go func() {
ForLoop:
for {
log.Infof("waiting for command '%s' ...", cmd.String())
log.Debugf("waiting for command '%s' ...\n\n", cmd.String())
select {
case <-stop:
break ForLoop
default:
}
time.Sleep(5 * time.Second)
time.Sleep(30 * time.Second)
}
}()
cmdOutput, err := cmd.CombinedOutput()
Expand Down Expand Up @@ -252,7 +252,7 @@ var (

func FinishRunning(stepName string, cmd *exec.Cmd) (bool, string, string) {
// TODO
verbose := true
verbose := false

log.Printf("Running: %v", stepName)
stdout, stderr := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
Expand Down Expand Up @@ -290,13 +290,14 @@ func FinishRunning(stepName string, cmd *exec.Cmd) (bool, string, string) {

// Runs the provided bash without wrapping it in any kubernetes-specific gunk.
func RunRawBashWithOutputs(stepName, bash string) (bool, string, string) {
cmd := exec.Command("bash", "-s")

// TODO:
traceBash := true
// traceBash := true
// if traceBash {
// cmd.Args = append(cmd.Args, "-x")
// }

cmd := exec.Command("bash", "-s")
if traceBash {
cmd.Args = append(cmd.Args, "-x")
}
cmd.Stdin = strings.NewReader(bash)
return FinishRunning(stepName, cmd)
}
Expand Down

0 comments on commit 44e594d

Please sign in to comment.