-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow controlling detected platforms cache timeout #4949
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,28 @@ import ( | |
"sort" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/containerd/containerd/platforms" | ||
"github.com/moby/buildkit/util/bklog" | ||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
var mu sync.Mutex | ||
var arr []ocispecs.Platform | ||
var CacheMaxAge = 20 * time.Second | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity. How often does this change during the lifetime of a buildkit process? I guess it would only change on an install of new binfmt handlers right? Potentially, could we invalidate the cache based on the contents of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, it depends on what the user is doing outside of buildkit.
binfmt_misc is usually not mounted in the environment where buildkit runs |
||
|
||
var ( | ||
mu sync.Mutex | ||
arr []ocispecs.Platform | ||
lastRefresh time.Time | ||
) | ||
|
||
func SupportedPlatforms(noCache bool) []ocispecs.Platform { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if !noCache && arr != nil { | ||
if arr != nil && (!noCache || CacheMaxAge < 0 || time.Since(lastRefresh) < CacheMaxAge) { | ||
return arr | ||
} | ||
defer func() { lastRefresh = time.Now() }() | ||
def := nativePlatform() | ||
arr = append([]ocispecs.Platform{}, def) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,10 +245,14 @@ func (w *Worker) Labels() map[string]string { | |
|
||
func (w *Worker) Platforms(noCache bool) []ocispecs.Platform { | ||
if noCache { | ||
matchers := make([]platforms.MatchComparer, len(w.WorkerOpt.Platforms)) | ||
for i, p := range w.WorkerOpt.Platforms { | ||
matchers[i] = platforms.Only(p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the effect of this isn't that significant compared to qemu detection logic, calling |
||
} | ||
for _, p := range archutil.SupportedPlatforms(noCache) { | ||
exists := false | ||
for _, pp := range w.WorkerOpt.Platforms { | ||
if platforms.Only(pp).Match(p) { | ||
for _, m := range matchers { | ||
if m.Match(p) { | ||
exists = true | ||
break | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to always use cache by setting
platformsCacheMaxAge = -1
with this custom type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tested this