Add retry logic to building zlint test container (#28167)

- Sometimes we are failing to pull the zlint tagged version from
   GitHub when building up the test containers. Add a simple retry
   around the container building step to see if this resolves the
   issue.
This commit is contained in:
Steven Clark
2024-08-23 08:33:21 -04:00
committed by GitHub
parent 6558df47b4
commit 5d4ea2f4fa

View File

@@ -6,10 +6,13 @@ package pkiext
import (
"context"
"encoding/json"
"fmt"
"sync"
"testing"
"time"
"github.com/hashicorp/vault/builtin/logical/pki"
"github.com/hashicorp/vault/helper/testhelpers"
"github.com/hashicorp/vault/sdk/helper/docker"
"github.com/stretchr/testify/require"
)
@@ -50,15 +53,21 @@ RUN go install github.com/zmap/zlint/v3/cmd/zlint@v3.6.2
}
ctx := context.Background()
output, err := zRunner.BuildImage(ctx, containerfile, bCtx,
docker.BuildRemove(true), docker.BuildForceRemove(true),
docker.BuildPullParent(true),
docker.BuildTags([]string{imageName + ":" + imageTag}))
if err != nil {
t.Fatalf("Could not build new image: %v", err)
}
t.Logf("Image build output: %v", string(output))
// Sometimes we see timeouts and issues pulling the zlint code from GitHub
testhelpers.RetryUntil(t, 30*time.Second, func() error {
output, err := zRunner.BuildImage(ctx, containerfile, bCtx,
docker.BuildRemove(true),
docker.BuildForceRemove(true),
docker.BuildPullParent(true),
docker.BuildTags([]string{imageName + ":" + imageTag}))
if err != nil {
return fmt.Errorf("could not build new image with zlint: %w", err)
}
t.Logf("Image build output: %v", string(output))
return nil
})
}
func RunZLintContainer(t *testing.T, certificate string) []byte {