mirror of https://github.com/docker/buildx.git
Merge pull request #1877 from jedevc/cache-dockerutil-features
dockerutil: cache feature collection
This commit is contained in:
commit
687feca9e8
|
@ -13,6 +13,9 @@ import (
|
||||||
// Client represents an active docker object.
|
// Client represents an active docker object.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
cli command.Cli
|
cli command.Cli
|
||||||
|
|
||||||
|
featuresOnce sync.Once
|
||||||
|
featuresCache map[Feature]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient initializes a new docker client.
|
// NewClient initializes a new docker client.
|
||||||
|
@ -64,6 +67,13 @@ func (c *Client) LoadImage(ctx context.Context, name string, status progress.Wri
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Features(ctx context.Context, name string) map[Feature]bool {
|
func (c *Client) Features(ctx context.Context, name string) map[Feature]bool {
|
||||||
|
c.featuresOnce.Do(func() {
|
||||||
|
c.featuresCache = c.features(ctx, name)
|
||||||
|
})
|
||||||
|
return c.featuresCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) features(ctx context.Context, name string) map[Feature]bool {
|
||||||
features := make(map[Feature]bool)
|
features := make(map[Feature]bool)
|
||||||
if dapi, err := c.API(name); err == nil {
|
if dapi, err := c.API(name); err == nil {
|
||||||
if info, err := dapi.Info(ctx); err == nil {
|
if info, err := dapi.Info(ctx); err == nil {
|
||||||
|
|
Loading…
Reference in New Issue