From 42b00f4aacfe7f3050f5574915827b9efafe9c19 Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Mon, 15 Jan 2024 09:50:43 +0100 Subject: [PATCH] addressed remaining linter warning + caching & worktree improvement --- tests/e2e/builder.go | 15 ++++++++++++--- tests/e2e/test_target.go | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/e2e/builder.go b/tests/e2e/builder.go index 027898217f..63e9961661 100644 --- a/tests/e2e/builder.go +++ b/tests/e2e/builder.go @@ -21,9 +21,9 @@ func setupWorkSpace(revision string) (string, error) { //#nosec G204 -- Bypass linter warning for spawning subprocess with variable cmd := exec.Command("git", "worktree", "add", - "--checkout", workSpace, revision) + "--force", "--checkout", workSpace, revision) out, err := cmd.CombinedOutput() - fmt.Printf("Running: %s", cmd.String()) + fmt.Println("Running: ", cmd.String()) if err != nil { log.Printf("Error creating worktree (%v): %s", err, string(out)) return "", err @@ -55,7 +55,7 @@ func dockerIsUp() bool { } // Build docker image of ICS for a given revision -func buildDockerImage(imageName, revision string, targetCfg TargetConfig) error { +func buildDockerImage(imageName, revision string, targetCfg TargetConfig, noCache bool) error { fmt.Printf("Building ICS %s image %s\n", revision, imageName) if !dockerIsUp() { return fmt.Errorf("docker engine is not running") @@ -101,6 +101,10 @@ func buildDockerImage(imageName, revision string, targetCfg TargetConfig) error dockerFile := "Dockerfile" args := []string{"build", "-t", imageName} + if noCache { + args = append(args, "--no-cache") + } + if targetCfg.useGaia && targetCfg.gaiaTag != "" { dockerFile = "Dockerfile.gaia" args = append(args, "--build-arg", fmt.Sprintf("USE_GAIA_TAG=%s", targetCfg.gaiaTag)) @@ -111,6 +115,11 @@ func buildDockerImage(imageName, revision string, targetCfg TargetConfig) error cmd := exec.Command("docker", args...) cmd.Dir = workSpace out, err := cmd.CombinedOutput() + if err != nil && !noCache { + // Retry image creation from pristine state by enforcing --no-cache + log.Printf("Image creation failed '%v'. Re-trying without cache!", err) + return buildDockerImage(imageName, revision, targetCfg, true) + } if err != nil { return fmt.Errorf("building docker image failed running '%v' (%v): %s", cmd, err, out) } diff --git a/tests/e2e/test_target.go b/tests/e2e/test_target.go index 111992149d..026ad9b474 100644 --- a/tests/e2e/test_target.go +++ b/tests/e2e/test_target.go @@ -76,7 +76,7 @@ func (dc *DockerContainer) Build() error { if err != nil { return fmt.Errorf("failed building docker image: %v", err) } - err = buildDockerImage(consumerImageName, consumerVersion, dc.targetConfig) + err = buildDockerImage(consumerImageName, consumerVersion, dc.targetConfig, false) if err != nil { return err } @@ -92,7 +92,7 @@ func (dc *DockerContainer) Build() error { if err != nil { return fmt.Errorf("failed building docker image: %v", err) } - err = buildDockerImage(providerImageName, providerVersion, dc.targetConfig) + err = buildDockerImage(providerImageName, providerVersion, dc.targetConfig, false) if err != nil { return err } @@ -145,6 +145,7 @@ func (dc *DockerContainer) ExecCommand(name string, arg ...string) *exec.Cmd { func (dc *DockerContainer) ExecDetachedCommand(name string, arg ...string) *exec.Cmd { args := []string{"exec", "-d", dc.containerCfg.InstanceName, name} args = append(args, arg...) + //#nosec G204 -- Bypass linter warning for spawning subprocess with variable return exec.Command("docker", args...) }