@@ -29,6 +29,7 @@ import (
2929 "github.com/zarf-dev/zarf/src/internal/packager/helm"
3030 "github.com/zarf-dev/zarf/src/internal/packager/images"
3131 "github.com/zarf-dev/zarf/src/internal/packager/kustomize"
32+ "github.com/zarf-dev/zarf/src/internal/value"
3233 "github.com/zarf-dev/zarf/src/pkg/archive"
3334 "github.com/zarf-dev/zarf/src/pkg/logger"
3435 "github.com/zarf-dev/zarf/src/pkg/packager/actions"
@@ -156,11 +157,9 @@ func AssemblePackage(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath
156157 }
157158 }
158159
159- l .Debug ("copying values files to package" , "files" , pkg .Values .Files )
160- for _ , file := range pkg .Values .Files {
161- if err = copyValuesFile (ctx , file , packagePath , buildPath ); err != nil {
162- return nil , err
163- }
160+ l .Debug ("merging values files to package" , "files" , pkg .Values .Files )
161+ if err = mergeAndWriteValuesFile (ctx , pkg .Values .Files , packagePath , buildPath ); err != nil {
162+ return nil , err
164163 }
165164
166165 checksumContent , checksumSha , err := getChecksum (buildPath )
@@ -876,35 +875,34 @@ func createReproducibleTarballFromDir(dirPath, dirPrefix, tarballPath string, ov
876875 })
877876}
878877
879- func copyValuesFile (ctx context.Context , file , packagePath , buildPath string ) error {
878+ func mergeAndWriteValuesFile (ctx context.Context , files [] string , packagePath , buildPath string ) error {
880879 l := logger .From (ctx )
881880
882- // Process local values file
883- src := file
884- if ! filepath .IsAbs (src ) {
885- src = filepath .Join (packagePath , ValuesDir , file )
886- }
887- // Validate src
888- if _ , err := os .Stat (src ); err != nil {
889- return fmt .Errorf ("unable to access values file %s: %w" , src , err )
890- }
891-
892- // Ensure relative paths don't munge the destination and write outside of the package tmpdir
893- cleanFile := filepath .Clean (file )
894- if strings .HasPrefix (cleanFile , ".." ) {
895- return fmt .Errorf ("values file path %s escapes package directory" , file )
881+ // Build absolute paths for all values files
882+ valueFilePaths := make ([]string , len (files ))
883+ for i , file := range files {
884+ src := file
885+ if ! filepath .IsAbs (src ) {
886+ src = filepath .Join (packagePath , file )
887+ }
888+ // Validate src exists
889+ if _ , err := os .Stat (src ); err != nil {
890+ return fmt .Errorf ("unable to access values file %s: %w" , src , err )
891+ }
892+ valueFilePaths [i ] = src
896893 }
897894
898- //Copy file to pre-archive package - destination includes ValuesDir
899- dst := filepath .Join (buildPath , ValuesDir , cleanFile )
900- l .Debug ("copying values file" , "src" , src , "dst" , dst )
901- if err := helpers .CreatePathAndCopy (src , dst ); err != nil {
902- return fmt .Errorf ("failed to copy values file %s: %w" , src , err )
895+ // Parse and merge all values files
896+ vals , err := value .ParseFiles (ctx , valueFilePaths , value.ParseFilesOptions {})
897+ if err != nil {
898+ return fmt .Errorf ("failed to parse values files: %w" , err )
903899 }
904900
905- // Set appropriate file permissions
906- if err := os .Chmod (dst , helpers .ReadWriteUser ); err != nil {
907- return fmt .Errorf ("failed to set permissions on values file %s: %w" , dst , err )
901+ // Write merged values to YAML
902+ dst := filepath .Join (buildPath , ValuesYAML )
903+ l .Debug ("writing merged values file" , "dst" , dst , "fileCount" , len (files ))
904+ if err := utils .WriteYaml (dst , vals , helpers .ReadWriteUser ); err != nil {
905+ return fmt .Errorf ("failed to write merged values file: %w" , err )
908906 }
909907
910908 return nil
0 commit comments