Skip to content
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

refactor: avoid unnecessary calls to platforms.DefaultSpec() #5756

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion exporter/containerimage/exptypes/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ParsePlatforms(meta map[string][]byte) (Platforms, error) {
return ps, nil
}

p := platforms.DefaultSpec()
var p ocispecs.Platform
if imgConfig, ok := meta[ExporterImageConfigKey]; ok {
var img ocispecs.Image
err := json.Unmarshal(imgConfig, &img)
Expand All @@ -51,6 +51,8 @@ func ParsePlatforms(meta map[string][]byte) (Platforms, error) {
} else if img.OS != "" || img.Architecture != "" {
return Platforms{}, errors.Errorf("invalid image config: os and architecture must be specified together")
}
} else {
p = platforms.DefaultSpec()
}
p = platforms.Normalize(p)
pk := platforms.FormatAll(p)
Expand Down
4 changes: 3 additions & 1 deletion frontend/dockerfile/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ func Build(ctx context.Context, c client.Client) (_ *client.Result, err error) {
return nil, nil, nil, err
}

p := platforms.DefaultSpec()
var p ocispecs.Platform
if platform != nil {
p = *platform
} else {
p = platforms.DefaultSpec()
}
scanTargets.Store(platforms.FormatAll(platforms.Normalize(p)), scanTarget)

Expand Down
4 changes: 3 additions & 1 deletion frontend/dockerui/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func (bc *Client) Build(ctx context.Context, fn BuildFunc) (*ResultBuilder, erro
}
}

p := platforms.DefaultSpec()
var p ocispecs.Platform
if tp != nil {
p = *tp
} else {
p = platforms.DefaultSpec()
}

// in certain conditions we allow input platform to be extended from base image
Expand Down
8 changes: 6 additions & 2 deletions frontend/dockerui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ func (bc *Client) BuildOpts() client.BuildOpts {
func (bc *Client) init() error {
opts := bc.bopts.Opts

defaultBuildPlatform := platforms.Normalize(platforms.DefaultSpec())
var defaultBuildPlatform ocispecs.Platform
if workers := bc.bopts.Workers; len(workers) > 0 && len(workers[0].Platforms) > 0 {
defaultBuildPlatform = workers[0].Platforms[0]
} else {
defaultBuildPlatform = platforms.Normalize(platforms.DefaultSpec())
}
buildPlatforms := []ocispecs.Platform{defaultBuildPlatform}
targetPlatforms := []ocispecs.Platform{}
Expand Down Expand Up @@ -459,9 +461,11 @@ func (bc *Client) NamedContext(name string, opt ContextOpt) (*NamedContext, erro
}
name = strings.TrimSuffix(reference.FamiliarString(named), ":latest")

pp := platforms.DefaultSpec()
var pp ocispecs.Platform
if opt.Platform != nil {
pp = *opt.Platform
} else {
pp = platforms.DefaultSpec()
}
pname := name + "::" + platforms.FormatAll(platforms.Normalize(pp))
nc, err := bc.namedContext(name, pname, opt)
Expand Down
4 changes: 3 additions & 1 deletion solver/llbsolver/ops/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (e *ExecOp) CacheMap(ctx context.Context, g session.Group, index int) (*sol
}
op.Meta.ProxyEnv = nil

p := platforms.DefaultSpec()
var p ocispecs.Platform
if e.platform != nil {
p = ocispecs.Platform{
OS: e.platform.OS,
Expand All @@ -132,6 +132,8 @@ func (e *ExecOp) CacheMap(ctx context.Context, g session.Group, index int) (*sol
OSVersion: e.platform.OSVersion,
OSFeatures: e.platform.OSFeatures,
}
} else {
p = platforms.DefaultSpec()
}

// Special case for cache compatibility with buggy versions that wrongly
Expand Down
Loading