Merge pull request #6 from mzihlmann/add-labels-on-last-image

fix: preserve labels from base images
This commit is contained in:
mzihlmann 2025-05-25 10:50:48 +01:00 committed by GitHub
commit 6f15090e58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 4 deletions

View File

@ -92,7 +92,11 @@ func newStageBuilder(args *dockerfile.BuildArgs, opts *config.KanikoOptions, sta
return nil, err
}
imageConfig, err := initializeConfig(sourceImage, opts)
_opts := *opts
if !stage.Final {
_opts.Labels = []string{}
}
imageConfig, err := initializeConfig(sourceImage, &_opts)
if err != nil {
return nil, err
}
@ -772,9 +776,7 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
configFile.OS = strings.Split(opts.CustomPlatform, "/")[0]
configFile.Architecture = strings.Split(opts.CustomPlatform, "/")[1]
}
if !stage.Final {
configFile.Config.Labels = map[string]string{}
}
sourceImage, err = mutate.ConfigFile(sourceImage, configFile)
if err != nil {
return nil, err