Skip to content

Commit

Permalink
addressed remaining linter warning + caching & worktree improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Jan 15, 2024
1 parent a4065df commit 42b00f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions tests/e2e/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/test_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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...)
}

Expand Down

0 comments on commit 42b00f4

Please sign in to comment.