Skip to content

Commit

Permalink
build: take advantage of --platform lists
Browse files Browse the repository at this point in the history
The builder can take a list of platforms in the Platforms field of its
BuildOptions argument, and we should definitely take advantage of that.

The `bud-multiple-platform-values` test from buildah exercises support
for this, so
[NO TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind authored and mheon committed Sep 16, 2021
1 parent 702e524 commit fb564d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 2 additions & 3 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
runtimeFlags = append(runtimeFlags, "--systemd-cgroup")
}

imageOS, arch, err := parse.PlatformFromOptions(c)
platforms, err := parse.PlatformsFromOptions(c)
if err != nil {
return nil, err
}
Expand All @@ -490,7 +490,6 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
AddCapabilities: flags.CapAdd,
AdditionalTags: tags,
Annotations: flags.Annotation,
Architecture: arch,
Args: args,
BlobDirectory: flags.BlobCache,
CNIConfigDir: flags.CNIConfigDir,
Expand All @@ -516,11 +515,11 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
MaxPullPushRetries: 3,
NamespaceOptions: nsValues,
NoCache: flags.NoCache,
OS: imageOS,
OciDecryptConfig: decConfig,
Out: stdout,
Output: output,
OutputFormat: format,
Platforms: platforms,
PullPolicy: pullPolicy,
PullPushRetryDelay: 2 * time.Second,
Quiet: flags.Quiet,
Expand Down
18 changes: 9 additions & 9 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
NamespaceOptions string `schema:"nsoptions"`
NoCache bool `schema:"nocache"`
OutputFormat string `schema:"outputformat"`
Platform string `schema:"platform"`
Platform []string `schema:"platform"`
Pull bool `schema:"pull"`
PullPolicy string `schema:"pullpolicy"`
Quiet bool `schema:"q"`
Expand All @@ -126,7 +126,6 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
Registry: "docker.io",
Rm: true,
ShmSize: 64 * 1024 * 1024,
Tag: []string{},
}

decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
Expand Down Expand Up @@ -481,16 +480,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
},
}

if len(query.Platform) > 0 {
variant := ""
buildOptions.OS, buildOptions.Architecture, variant, err = parse.Platform(query.Platform)
for _, platformSpec := range query.Platform {
os, arch, variant, err := parse.Platform(platformSpec)
if err != nil {
utils.BadRequest(w, "platform", query.Platform, err)
utils.BadRequest(w, "platform", platformSpec, err)
return
}
buildOptions.SystemContext.OSChoice = buildOptions.OS
buildOptions.SystemContext.ArchitectureChoice = buildOptions.Architecture
buildOptions.SystemContext.VariantChoice = variant
buildOptions.Platforms = append(buildOptions.Platforms, struct{ OS, Arch, Variant string }{
OS: os,
Arch: arch,
Variant: variant,
})
}
if _, found := r.URL.Query()["timestamp"]; found {
ts := time.Unix(query.Timestamp, 0)
Expand Down
10 changes: 10 additions & 0 deletions pkg/bindings/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
if len(platform) > 0 {
params.Set("platform", platform)
}
if len(options.Platforms) > 0 {
params.Del("platform")
for _, platformSpec := range options.Platforms {
platform = platformSpec.OS + "/" + platformSpec.Arch
if platformSpec.Variant != "" {
platform += "/" + platformSpec.Variant
}
params.Add("platform", platform)
}
}

params.Set("pullpolicy", options.PullPolicy.String())

Expand Down

0 comments on commit fb564d8

Please sign in to comment.