cmd/hi: improve test cleanup to reduce CI disk usage (#2881)

This commit is contained in:
Kristoffer Dalby
2025-11-28 16:59:54 +01:00
committed by GitHub
parent db293e0698
commit ed78bf4b98
7 changed files with 230 additions and 17 deletions

View File

@@ -1,17 +1,25 @@
package dockertestutil
import (
"context"
"os/exec"
"time"
)
// RunDockerBuildForDiagnostics runs docker build manually to get detailed error output.
// This is used when a docker build fails to provide more detailed diagnostic information
// than what dockertest typically provides.
func RunDockerBuildForDiagnostics(contextDir, dockerfile string) string {
cmd := exec.Command("docker", "build", "-f", dockerfile, contextDir)
//
// Returns the build output regardless of success/failure, and an error if the build failed.
func RunDockerBuildForDiagnostics(contextDir, dockerfile string) (string, error) {
// Use a context with timeout to prevent hanging builds
const buildTimeout = 10 * time.Minute
ctx, cancel := context.WithTimeout(context.Background(), buildTimeout)
defer cancel()
cmd := exec.CommandContext(ctx, "docker", "build", "--progress=plain", "--no-cache", "-f", dockerfile, contextDir)
output, err := cmd.CombinedOutput()
if err != nil {
return string(output)
}
return ""
return string(output), err
}