@@ -145,7 +145,7 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
145145 op (opts )
146146 }
147147
148- configs := []* types.Config {}
148+ var configs []* types.Config
149149 for i , file := range configDetails .ConfigFiles {
150150 configDict := file .Config
151151 if configDict == nil {
@@ -222,14 +222,14 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
222222}
223223
224224func parseConfig (b []byte , opts * Options ) (map [string ]interface {}, error ) {
225- yaml , err := ParseYAML (b )
225+ yml , err := ParseYAML (b )
226226 if err != nil {
227227 return nil , err
228228 }
229229 if ! opts .SkipInterpolation {
230- return interp .Interpolate (yaml , * opts .Interpolate )
230+ return interp .Interpolate (yml , * opts .Interpolate )
231231 }
232- return yaml , err
232+ return yml , err
233233}
234234
235235func groupXFieldsIntoExtensions (dict map [string ]interface {}) map [string ]interface {} {
@@ -342,8 +342,8 @@ func createTransformHook(additionalTransformers ...Transformer) mapstructure.Dec
342342 reflect .TypeOf (types.UlimitsConfig {}): transformUlimits ,
343343 reflect .TypeOf (types .UnitBytes (0 )): transformSize ,
344344 reflect .TypeOf ([]types.ServicePortConfig {}): transformServicePort ,
345- reflect .TypeOf (types.ServiceSecretConfig {}): transformStringSourceMap ,
346- reflect .TypeOf (types.ServiceConfigObjConfig {}): transformStringSourceMap ,
345+ reflect .TypeOf (types.ServiceSecretConfig {}): transformFileReferenceConfig ,
346+ reflect .TypeOf (types.ServiceConfigObjConfig {}): transformFileReferenceConfig ,
347347 reflect .TypeOf (types.StringOrNumberList {}): transformStringOrNumberList ,
348348 reflect .TypeOf (map [string ]* types.ServiceNetworkConfig {}): transformServiceNetworkMap ,
349349 reflect .TypeOf (types.Mapping {}): transformMappingOrListFunc ("=" , false ),
@@ -372,7 +372,7 @@ func createTransformHook(additionalTransformers ...Transformer) mapstructure.Dec
372372 }
373373}
374374
375- // keys needs to be converted to strings for jsonschema
375+ // keys need to be converted to strings for jsonschema
376376func convertToStringKeysRecursive (value interface {}, keyPrefix string ) (interface {}, error ) {
377377 if mapping , ok := value .(map [interface {}]interface {}); ok {
378378 dict := make (map [string ]interface {})
@@ -396,7 +396,7 @@ func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interfac
396396 return dict , nil
397397 }
398398 if list , ok := value .([]interface {}); ok {
399- convertedList := []interface {} {}
399+ var convertedList []interface {}
400400 for index , entry := range list {
401401 newKeyPrefix := fmt .Sprintf ("%s[%d]" , keyPrefix , index )
402402 convertedEntry , err := convertToStringKeysRecursive (entry , newKeyPrefix )
@@ -532,7 +532,7 @@ func LoadService(name string, serviceDict map[string]interface{}, workingDir str
532532 }
533533
534534 for i , volume := range serviceConfig .Volumes {
535- if volume .Type != "bind" {
535+ if volume .Type != types . VolumeTypeBind {
536536 continue
537537 }
538538
@@ -552,8 +552,8 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l
552552 environment := types.MappingWithEquals {}
553553
554554 if len (serviceConfig .EnvFile ) > 0 {
555- for _ , file := range serviceConfig .EnvFile {
556- filePath := absPath (workingDir , file )
555+ for _ , envFile := range serviceConfig .EnvFile {
556+ filePath := absPath (workingDir , envFile )
557557 file , err := os .Open (filePath )
558558 if err != nil {
559559 return err
@@ -797,7 +797,7 @@ var transformServicePort TransformerFunc = func(data interface{}) (interface{},
797797 // We process the list instead of individual items here.
798798 // The reason is that one entry might be mapped to multiple ServicePortConfig.
799799 // Therefore we take an input of a list and return an output of a list.
800- ports := []interface {} {}
800+ var ports []interface {}
801801 for _ , entry := range entries {
802802 switch value := entry .(type ) {
803803 case int :
@@ -852,17 +852,27 @@ var transformServiceDeviceRequest TransformerFunc = func(data interface{}) (inte
852852 }
853853}
854854
855- var transformStringSourceMap TransformerFunc = func (data interface {}) (interface {}, error ) {
855+ var transformFileReferenceConfig TransformerFunc = func (data interface {}) (interface {}, error ) {
856856 switch value := data .(type ) {
857857 case string :
858858 return map [string ]interface {}{"source" : value }, nil
859859 case map [string ]interface {}:
860- return groupXFieldsIntoExtensions (data .(map [string ]interface {})), nil
860+ if target , ok := value ["target" ]; ok {
861+ value ["target" ] = cleanTarget (target .(string ))
862+ }
863+ return groupXFieldsIntoExtensions (value ), nil
861864 default :
862865 return data , errors .Errorf ("invalid type %T for secret" , value )
863866 }
864867}
865868
869+ func cleanTarget (target string ) string {
870+ if target == "" {
871+ return ""
872+ }
873+ return path .Clean (target )
874+ }
875+
866876var transformBuildConfig TransformerFunc = func (data interface {}) (interface {}, error ) {
867877 switch value := data .(type ) {
868878 case string :
@@ -906,9 +916,15 @@ var transformExtendsConfig TransformerFunc = func(data interface{}) (interface{}
906916var transformServiceVolumeConfig TransformerFunc = func (data interface {}) (interface {}, error ) {
907917 switch value := data .(type ) {
908918 case string :
909- return ParseVolume (value )
919+ volume , err := ParseVolume (value )
920+ volume .Target = cleanTarget (volume .Target )
921+ return volume , err
910922 case map [string ]interface {}:
911- return groupXFieldsIntoExtensions (data .(map [string ]interface {})), nil
923+ data := groupXFieldsIntoExtensions (data .(map [string ]interface {}))
924+ if target , ok := data ["target" ]; ok {
925+ data ["target" ] = cleanTarget (target .(string ))
926+ }
927+ return data , nil
912928 default :
913929 return data , errors .Errorf ("invalid type %T for service volume" , value )
914930 }
@@ -971,7 +987,7 @@ func transformMappingOrList(mappingOrList interface{}, sep string, allowNil bool
971987 switch value := mappingOrList .(type ) {
972988 case map [string ]interface {}:
973989 return toMapStringString (value , allowNil )
974- case ( []interface {}) :
990+ case []interface {}:
975991 result := make (map [string ]interface {})
976992 for _ , value := range value {
977993 parts := strings .SplitN (value .(string ), sep , 2 )
@@ -1054,7 +1070,7 @@ func toString(value interface{}, allowNil bool) interface{} {
10541070}
10551071
10561072func toStringList (value map [string ]interface {}, separator string , allowNil bool ) []string {
1057- output := []string {}
1073+ var output []string
10581074 for key , value := range value {
10591075 if value == nil && ! allowNil {
10601076 continue
0 commit comments