helper: wait up to 180s for buildkitd (configurable), builder nodes can be busy
All checks were successful
build / test (push) Successful in 46s
build / generate-sbom (push) Successful in 1m8s
build / build (push) Successful in 1m16s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonas Leder 2026-11-18 01:17:11 +01:00
commit 9dd6e2055f
4 changed files with 23 additions and 2 deletions

View file

@ -30,6 +30,7 @@ Forgejo Actions values are used when no override is set. GitLab CI `CI_*` variab
| `REGISTRY_MIRROR` | | docker.io mirror for buildkit |
| `GOPROXY` / `GOPROXY_DISABLE` | `https://goproxy.jonasled.dev,direct` | passed as build arg |
| `TRIVY_SKIP` / `TRIVY_TIMEOUT` | `false` / `5m` | scan control |
| `BUILDKIT_START_TIMEOUT` | `180s` | how long to wait for buildkitd |
| `BUILDCTL_TTY` | `false` | colored progress |
## Runner requirements

View file

@ -6,6 +6,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"
)
// firstEnv returns the first non-empty value of the given variables.
@ -152,3 +153,12 @@ func getGoProxy() string {
}
return "https://goproxy.jonasled.dev,direct"
}
// getBuildkitTimeout is how long to wait for buildkitd to answer. The daemon can start slowly on busy
// builder nodes, so the default is generous. BUILDKIT_START_TIMEOUT takes a Go duration like 90s.
func getBuildkitTimeout() time.Duration {
if d, err := time.ParseDuration(os.Getenv("BUILDKIT_START_TIMEOUT")); err == nil && d > 0 {
return d
}
return 180 * time.Second
}

View file

@ -3,6 +3,7 @@ package main
import (
"strings"
"testing"
"time"
)
// clearEnv blanks every variable the helper reads, then applies overrides,
@ -16,7 +17,7 @@ func clearEnv(t *testing.T, overrides map[string]string) {
"CI_REGISTRY_USER", "CI_REGISTRY_PASSWORD", "REGISTRY_MIRROR",
"GITHUB_SERVER_URL", "GITHUB_REPOSITORY", "GITHUB_SHA", "GITHUB_REF_NAME", "GITHUB_REF_TYPE",
"GITHUB_ACTOR", "GITHUB_TOKEN", "GITHUB_OUTPUT", "DEFAULT_BRANCH", "REGISTRY", "REGISTRY_USER",
"REGISTRY_PASSWORD", "GITLAB_CI",
"REGISTRY_PASSWORD", "GITLAB_CI", "BUILDKIT_START_TIMEOUT",
} {
t.Setenv(k, "")
}
@ -189,3 +190,12 @@ func TestSlug(t *testing.T) {
}
}
}
func TestGetBuildkitTimeout(t *testing.T) {
for in, want := range map[string]time.Duration{"": 180 * time.Second, "90s": 90 * time.Second, "junk": 180 * time.Second, "-5s": 180 * time.Second} {
clearEnv(t, map[string]string{"BUILDKIT_START_TIMEOUT": in})
if got := getBuildkitTimeout(); got != want {
t.Errorf("BUILDKIT_START_TIMEOUT=%q: got %v, want %v", in, got, want)
}
}
}

View file

@ -40,7 +40,7 @@ func run() error {
}
defer d.stop(10 * time.Second)
if err := waitForBuildkit(buildkitAddr(), 60*time.Second, d); err != nil {
if err := waitForBuildkit(buildkitAddr(), getBuildkitTimeout(), d); err != nil {
return err
}
if err := buildImage(); err != nil {