Skip to content

Commit

Permalink
Temporary Fix docker images timeout issue (#4762)
Browse files Browse the repository at this point in the history
* returned-the-old-way-of-handling-images

* introduced-additional-parameter

* amended-the-description

* amended-condition
  • Loading branch information
dimaste authored Jan 9, 2024
1 parent ac5cf17 commit 89e1e01
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cmd/whitesourceExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ func runWhitesourceScan(ctx context.Context, config *ScanOptions, scan *ws.Scan,
// Download Docker image for container scan
// ToDo: move it to improve testability
if config.BuildTool == "docker" {
if len(config.ScanImages) != 0 {
if len(config.ScanImages) != 0 && config.ActivateMultipleImagesScan {
for _, image := range config.ScanImages {
config.ScanImage = image
err := downloadDockerImageAsTar(config, utils)
err := downloadDockerImageAsTarNew(config, utils)
if err != nil {
return errors.Wrapf(err, "failed to download docker image")
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ func createToolRecordWhitesource(utils whitesourceUtils, workspace string, confi
return record.GetFileName(), nil
}

func downloadDockerImageAsTar(config *ScanOptions, utils whitesourceUtils) error {
func downloadDockerImageAsTarNew(config *ScanOptions, utils whitesourceUtils) error {

imageNameToSave := strings.Replace(config.ScanImage, "/", "-", -1)

Expand All @@ -1113,3 +1113,27 @@ func downloadDockerImageAsTar(config *ScanOptions, utils whitesourceUtils) error

return nil
}

func downloadDockerImageAsTar(config *ScanOptions, utils whitesourceUtils) error {

saveImageOptions := containerSaveImageOptions{
ContainerImage: config.ScanImage,
ContainerRegistryURL: config.ScanImageRegistryURL,
ContainerRegistryUser: config.ContainerRegistryUser,
ContainerRegistryPassword: config.ContainerRegistryPassword,
DockerConfigJSON: config.DockerConfigJSON,
FilePath: config.ProjectName, // previously was config.ProjectName
ImageFormat: "legacy", // keep the image format legacy or whitesource is not able to read layers
}
dClientOptions := piperDocker.ClientOptions{ImageName: saveImageOptions.ContainerImage, RegistryURL: saveImageOptions.ContainerRegistryURL, LocalPath: "", ImageFormat: "legacy"}
dClient := &piperDocker.Client{}
dClient.SetOptions(dClientOptions)
if _, err := runContainerSaveImage(&saveImageOptions, &telemetry.CustomData{}, "./cache", "", dClient, utils); err != nil {
if strings.Contains(fmt.Sprint(err), "no image found") {
log.SetErrorCategory(log.ErrorConfiguration)
}
return errors.Wrapf(err, "failed to download Docker image %v", config.ScanImage)
}

return nil
}
11 changes: 11 additions & 0 deletions cmd/whitesourceExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions resources/metadata/whitesourceExecuteScan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ spec:
- STAGES
- STEPS
default: false
- name: activateMultipleImagesScan
type: bool
description: "Use this parameter to activate the scan of multiple images. Additionally you'll need to provide skipParentProjectResolution and scanImages parameters"
scope:
- PARAMETERS
- STAGES
- STEPS
default: false
- name: scanImageRegistryUrl
type: string
description: "For `buildTool: docker`: Defines the registry where the scanImage is located."
Expand Down

0 comments on commit 89e1e01

Please sign in to comment.