Skip to content

Commit

Permalink
feat(test): use local scanner image if found
Browse files Browse the repository at this point in the history
  • Loading branch information
paralta committed Aug 28, 2023
1 parent 0444e92 commit c5ca772
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/orchestrator/provider/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,22 @@ func (c *Client) createScanContainer(ctx context.Context, assetVolume, networkID
return "", fmt.Errorf("failed to create scan config file: %w", err)
}

// Pull scanner image
imagePullResp, err := c.dockerClient.ImagePull(ctx, config.ScannerImage, types.ImagePullOptions{})
// Pull scanner image if required
images, err := c.dockerClient.ImageList(ctx, types.ImageListOptions{
Filters: filters.NewArgs(filters.Arg("name", config.ScannerImage)),
})
if err != nil {
return "", fmt.Errorf("failed to pull scanner image: %w", err)
return "", fmt.Errorf("failed to get images: %w", err)
}
if len(images) == 0 {
imagePullResp, err := c.dockerClient.ImagePull(ctx, config.ScannerImage, types.ImagePullOptions{})
if err != nil {
return "", fmt.Errorf("failed to pull scanner image: %w", err)
}
// Drain response to avoid blocking
_, _ = io.Copy(io.Discard, imagePullResp)
_ = imagePullResp.Close()
}

// Drain response to avoid blocking
_, _ = io.Copy(io.Discard, imagePullResp)
_ = imagePullResp.Close()

// Create scan container
containerResp, err := c.dockerClient.ContainerCreate(
Expand Down

0 comments on commit c5ca772

Please sign in to comment.