mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-10-31 16:13:45 +08:00 
			
		
		
		
	Set ConfigFile to parse compose files with bake
				
					
				
			Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										23
									
								
								vendor/github.com/compose-spec/compose-go/loader/loader.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								vendor/github.com/compose-spec/compose-go/loader/loader.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -217,16 +217,35 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types. | ||||
|  | ||||
| func parseConfig(b []byte, opts *Options) (map[string]interface{}, error) { | ||||
| 	if !opts.SkipInterpolation { | ||||
| 		substitute, err := opts.Interpolate.Substitute(string(b), template.Mapping(opts.Interpolate.LookupValue)) | ||||
| 		withoutComments, err := removeYamlComments(b) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		b = []byte(substitute) | ||||
|  | ||||
| 		substituted, err := opts.Interpolate.Substitute(string(withoutComments), template.Mapping(opts.Interpolate.LookupValue)) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		b = []byte(substituted) | ||||
| 	} | ||||
|  | ||||
| 	return ParseYAML(b) | ||||
| } | ||||
|  | ||||
| // removeYamlComments drop all comments from the yaml file, so we don't try to apply string substitutions on irrelevant places | ||||
| func removeYamlComments(b []byte) ([]byte, error) { | ||||
| 	var cfg interface{} | ||||
| 	err := yaml.Unmarshal(b, &cfg) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	b, err = yaml.Marshal(cfg) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return b, nil | ||||
| } | ||||
|  | ||||
| func groupXFieldsIntoExtensions(dict map[string]interface{}) map[string]interface{} { | ||||
| 	extras := map[string]interface{}{} | ||||
| 	for key, value := range dict { | ||||
|   | ||||
							
								
								
									
										9
									
								
								vendor/github.com/compose-spec/compose-go/template/template.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/compose-spec/compose-go/template/template.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -20,6 +20,8 @@ import ( | ||||
| 	"fmt" | ||||
| 	"regexp" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/sirupsen/logrus" | ||||
| ) | ||||
|  | ||||
| var delimiter = "\\$" | ||||
| @@ -61,7 +63,7 @@ type Mapping func(string) (string, bool) | ||||
| // the substitution and an error. | ||||
| type SubstituteFunc func(string, Mapping) (string, bool, error) | ||||
|  | ||||
| // SubstituteWith subsitute variables in the string with their values. | ||||
| // SubstituteWith substitute variables in the string with their values. | ||||
| // It accepts additional substitute function. | ||||
| func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, subsFuncs ...SubstituteFunc) (string, error) { | ||||
| 	var err error | ||||
| @@ -97,7 +99,10 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su | ||||
| 			return value | ||||
| 		} | ||||
|  | ||||
| 		value, _ := mapping(substitution) | ||||
| 		value, ok := mapping(substitution) | ||||
| 		if !ok { | ||||
| 			logrus.Warnf("The %q variable is not set. Defaulting to a blank string.", substitution) | ||||
| 		} | ||||
| 		return value | ||||
| 	}) | ||||
|  | ||||
|   | ||||
							
								
								
									
										4
									
								
								vendor/github.com/compose-spec/compose-go/types/config.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								vendor/github.com/compose-spec/compose-go/types/config.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -20,7 +20,6 @@ import ( | ||||
| 	"encoding/json" | ||||
|  | ||||
| 	"github.com/mitchellh/mapstructure" | ||||
| 	"github.com/sirupsen/logrus" | ||||
| ) | ||||
|  | ||||
| // ConfigDetails are the details about a group of ConfigFiles | ||||
| @@ -34,9 +33,6 @@ type ConfigDetails struct { | ||||
| // LookupEnv provides a lookup function for environment variables | ||||
| func (cd ConfigDetails) LookupEnv(key string) (string, bool) { | ||||
| 	v, ok := cd.Environment[key] | ||||
| 	if !ok { | ||||
| 		logrus.Warnf("The %s variable is not set. Defaulting to a blank string.", key) | ||||
| 	} | ||||
| 	return v, ok | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							| @@ -23,7 +23,7 @@ github.com/beorn7/perks/quantile | ||||
| github.com/cenkalti/backoff/v4 | ||||
| # github.com/cespare/xxhash/v2 v2.1.1 | ||||
| github.com/cespare/xxhash/v2 | ||||
| # github.com/compose-spec/compose-go v0.0.0-20210706130854-69459d4976b5 | ||||
| # github.com/compose-spec/compose-go v0.0.0-20210729195839-de56f4f0cb3c | ||||
| github.com/compose-spec/compose-go/errdefs | ||||
| github.com/compose-spec/compose-go/interpolation | ||||
| github.com/compose-spec/compose-go/loader | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 CrazyMax
					CrazyMax