MCPcopy Create free account
hub / github.com/docker/buildx / buildkitVersion

Function buildkitVersion

tests/integration.go:189–234  ·  view source on GitHub ↗
(t *testing.T, sb integration.Sandbox)

Source from the content-addressed store, hash-verified

187)
188
189func buildkitVersion(t *testing.T, sb integration.Sandbox) string {
190 bkversMu.Lock()
191 defer bkversMu.Unlock()
192
193 if bkvers == nil {
194 bkvers = make(map[string]string)
195 }
196
197 ver, ok := bkvers[sb.Name()]
198 if !ok {
199 out, err := inspectCmd(sb, withArgs(sb.Address()))
200 require.NoError(t, err, out)
201 for line := range strings.SplitSeq(out, "\n") {
202 if v, ok := strings.CutPrefix(line, "BuildKit version:"); ok {
203 ver = strings.TrimSpace(v)
204 bkvers[sb.Name()] = ver
205 }
206 }
207 if ver == "" {
208 t.Logf("BuildKit version not found in inspect output, extract it from the image.\n%s", out)
209 undockBin, err := exec.LookPath("undock")
210 require.NoError(t, err, "undock not found")
211
212 destDir := t.TempDir()
213 t.Cleanup(func() {
214 os.RemoveAll(destDir)
215 })
216
217 cmd := exec.CommandContext(context.TODO(), undockBin, "--cachedir", "/root/.cache/undock", "--include", "/usr/bin/buildkitd", "--rm-dist", buildkitImage, destDir)
218 require.NoErrorf(t, cmd.Run(), "failed to extract buildkitd binary from %q", buildkitImage)
219
220 cmd = exec.CommandContext(context.TODO(), filepath.Join(destDir, "usr", "bin", "buildkitd"), "--version")
221 out, err := cmd.CombinedOutput()
222 require.NoErrorf(t, err, "failed to get BuildKit version from %q: %s", buildkitImage, string(out))
223
224 v := strings.Fields(strings.TrimSpace(string(out)))
225 if len(v) != 4 {
226 require.Fail(t, "unexpected version format: "+strings.TrimSpace(string(out)))
227 }
228 ver = v[2]
229 bkvers[sb.Name()] = ver
230 }
231 }
232
233 return ver
234}
235
236func matchesBuildKitVersion(t *testing.T, sb integration.Sandbox, constraint string) bool {
237 c, err := semver.NewConstraint(constraint)

Callers 2

matchesBuildKitVersionFunction · 0.85
skipNoCompatBuildKitFunction · 0.85

Calls 5

withArgsFunction · 0.85
AddressMethod · 0.80
RunMethod · 0.80
inspectCmdFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…