From 63ea46afd9656da60ef3bd54d187d794e5d1599b Mon Sep 17 00:00:00 2001 From: Lucas Pablo Calisi Date: Thu, 21 Dec 2023 15:15:17 -0300 Subject: [PATCH] feat: extend include for environment and paths Signed-off-by: Lucas Pablo Calisi --- pkg/build/types/image_configuration.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/build/types/image_configuration.go b/pkg/build/types/image_configuration.go index 3720afb0e..7df7ca7c4 100644 --- a/pkg/build/types/image_configuration.go +++ b/pkg/build/types/image_configuration.go @@ -85,6 +85,11 @@ func (ic *ImageConfiguration) parse(configData []byte, logger log.Logger) error pkgs := append([]string{}, baseIc.Contents.Packages...) pkgs = append(pkgs, mergedIc.Contents.Packages...) ic.Contents.Packages = pkgs + + // Merge environment and path mutations. + ic.Environment = mergeEnvironment(baseIc, mergedIc) + + ic.Paths = append(baseIc.Paths, mergedIc.Paths...) } repos := make([]string, 0, len(ic.Contents.Repositories)) @@ -97,6 +102,21 @@ func (ic *ImageConfiguration) parse(configData []byte, logger log.Logger) error return nil } +// Merge environment variables from base config but if no exists in config. +func mergeEnvironment(baseIC, mergedIc ImageConfiguration) map[string]string { + env := make(map[string]string) + + for key, value := range baseIC.Environment { + env[key] = value + } + + for key, value := range mergedIc.Environment { + env[key] = value + } + + return env +} + // Loads an image configuration given a configuration file path. func (ic *ImageConfiguration) Load(imageConfigPath string, logger log.Logger) error { data, err := os.ReadFile(imageConfigPath)