Skip to content

Commit

Permalink
feat: extend include for environment and paths
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Pablo Calisi <[email protected]>
  • Loading branch information
lpcalisi committed Dec 21, 2023
1 parent 9ad04bd commit 63ea46a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/build/types/image_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit 63ea46a

Please sign in to comment.