From 10d768baafef059288e609987045989a96cdc9ae Mon Sep 17 00:00:00 2001 From: tomsweeneyredhat Date: Tue, 22 Apr 2025 10:17:56 -0400 Subject: [PATCH] Add inherit-labels option to Build API Add the inherit-labels option to the build API and tweak the go.mod after some unhappiness in my sandbox. Signed-off-by: tomsweeneyredhat --- cmd/podman/common/build.go | 4 ++++ go.mod | 1 - pkg/api/handlers/compat/images_build.go | 2 ++ pkg/api/server/register_images.go | 14 ++++++++++++++ pkg/bindings/images/build.go | 6 ++++++ vendor/modules.txt | 2 -- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/podman/common/build.go b/cmd/podman/common/build.go index 2f46683498..1c4f6a577e 100644 --- a/cmd/podman/common/build.go +++ b/cmd/podman/common/build.go @@ -580,6 +580,10 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *Buil UnsetLabels: flags.UnsetLabels, } + if c.Flag("inherit-labels").Changed { + opts.InheritLabels = types.NewOptionalBool(flags.InheritLabels) + } + if flags.IgnoreFile != "" { excludes, err := parseDockerignore(flags.IgnoreFile) if err != nil { diff --git a/go.mod b/go.mod index 2cea10f1ea..861d08bcda 100644 --- a/go.mod +++ b/go.mod @@ -155,7 +155,6 @@ require ( github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/go-archive v0.1.0 // indirect github.com/moby/patternmatcher v0.6.0 // indirect - github.com/moby/sys/atomicwriter v0.1.0 // indirect github.com/moby/sys/mountinfo v0.7.2 // indirect github.com/moby/sys/sequential v0.6.0 // indirect github.com/moby/sys/userns v0.1.0 // indirect diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 7c0b7d09ed..16b03d4340 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -130,6 +130,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { IDMappingOptions string `schema:"idmappingoptions"` IdentityLabel bool `schema:"identitylabel"` Ignore bool `schema:"ignore"` + InheritLabels bool `schema:"inheritlabels"` Isolation string `schema:"isolation"` Jobs int `schema:"jobs"` LabelOpts string `schema:"labelopts"` @@ -744,6 +745,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { IDMappingOptions: &idMappingOptions, IgnoreUnrecognizedInstructions: query.Ignore, IgnoreFile: ignoreFile, + InheritLabels: types.NewOptionalBool(query.InheritLabels), Isolation: isolation, Jobs: &jobs, Labels: labels, diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go index 2cb79470ae..9350abbe35 100644 --- a/pkg/api/server/register_images.go +++ b/pkg/api/server/register_images.go @@ -567,6 +567,13 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // Contents of base images to be modified on ADD or COPY only // (As of Podman version v5.2) // - in: query + // name: inheritlabels + // type: boolean + // default: true + // description: | + // Inherit the labels from the base image or base stages + // (As of Podman version v5.5) + // - in: query // name: nocache // type: boolean // default: false @@ -1540,6 +1547,13 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // Contents of base images to be modified on ADD or COPY only // (As of Podman version v5.2) // - in: query + // name: inheritlabels + // type: boolean + // default: true + // description: | + // Inherit the labels from the base image or base stages + // (As of Podman version v5.5) + // - in: query // name: nocache // type: boolean // default: false diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 417eeb1603..d73507709d 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -237,6 +237,12 @@ func Build(ctx context.Context, containerFiles []string, options types.BuildOpti if options.IgnoreUnrecognizedInstructions { params.Set("ignore", "1") } + if options.InheritLabels == imageTypes.OptionalBoolFalse { + params.Set("inheritlabels", "0") + } else { + params.Set("inheritlabels", "1") + } + params.Set("isolation", strconv.Itoa(int(options.Isolation))) if options.CommonBuildOpts.HTTPProxy { params.Set("httpproxy", "1") diff --git a/vendor/modules.txt b/vendor/modules.txt index 32216a2c81..37fa9c109b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -723,8 +723,6 @@ github.com/moby/go-archive/tarheader # github.com/moby/patternmatcher v0.6.0 ## explicit; go 1.19 github.com/moby/patternmatcher -# github.com/moby/sys/atomicwriter v0.1.0 -## explicit; go 1.18 # github.com/moby/sys/capability v0.4.0 ## explicit; go 1.21 github.com/moby/sys/capability