From c5ca7725c1ab06a4270493b248c8e9f5c620a981 Mon Sep 17 00:00:00 2001 From: Catarina Paralta <46568597+paralta@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:05:14 +0100 Subject: [PATCH] feat(test): use local scanner image if found --- pkg/orchestrator/provider/docker/client.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/orchestrator/provider/docker/client.go b/pkg/orchestrator/provider/docker/client.go index 896267901e..619dfafe9a 100644 --- a/pkg/orchestrator/provider/docker/client.go +++ b/pkg/orchestrator/provider/docker/client.go @@ -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(