diff --git a/bake/compose.go b/bake/compose.go index 2ea88850..2872c72d 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -76,6 +76,9 @@ func ParseCompose(dt []byte) (*Config, error) { Dockerfile: dockerfilePathP, Labels: s.Build.Labels, Args: flatten(s.Build.Args.Resolve(func(val string) (string, bool) { + if val, ok := s.Environment[val]; ok && val != nil { + return *val, true + } val, ok := cfg.Environment[val] return val, ok })), diff --git a/bake/compose_test.go b/bake/compose_test.go index d9a4eb1a..a5389007 100644 --- a/bake/compose_test.go +++ b/bake/compose_test.go @@ -280,6 +280,36 @@ services: require.Equal(t, c.Targets[1].NoCache, newBool(true)) } +func TestEnv(t *testing.T) { + envf, err := os.CreateTemp("", "env") + require.NoError(t, err) + defer os.Remove(envf.Name()) + + _, err = envf.WriteString("FOO=bsdf -csdf\n") + require.NoError(t, err) + + var dt = []byte(` +services: + scratch: + build: + context: . + args: + CT_ECR: foo + FOO: + NODE_ENV: + environment: + - NODE_ENV=test + - AWS_ACCESS_KEY_ID=dummy + - AWS_SECRET_ACCESS_KEY=dummy + env_file: + - ` + envf.Name() + ` +`) + + c, err := ParseCompose(dt) + require.NoError(t, err) + require.Equal(t, c.Targets[0].Args, map[string]string{"CT_ECR": "foo", "FOO": "bsdf -csdf", "NODE_ENV": "test"}) +} + func newBool(val bool) *bool { b := val return &b diff --git a/go.mod b/go.mod index c2699bfd..f464a3ce 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/bugsnag/panicwrap v1.2.0 // indirect github.com/cenkalti/backoff v2.1.1+incompatible // indirect github.com/cloudflare/cfssl v0.0.0-20181213083726-b94e044bb51e // indirect - github.com/compose-spec/compose-go v1.0.5 + github.com/compose-spec/compose-go v1.0.8 github.com/containerd/console v1.0.3 github.com/containerd/containerd v1.6.0-beta.3 github.com/docker/cli v20.10.11+incompatible diff --git a/go.sum b/go.sum index f844d43f..8e5db86c 100644 --- a/go.sum +++ b/go.sum @@ -280,10 +280,10 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/compose-spec/compose-go v1.0.5 h1:WtfK7tJsk5C8h12iggum7p28kTxeXH7Xi5c/pLfnBwk= -github.com/compose-spec/compose-go v1.0.5/go.mod h1:LQ/JAjSIyh8bTu4RV6nkyf0Ow/Yf3qpvzrdEigxduiw= -github.com/compose-spec/godotenv v1.1.0 h1:wzShe5P6L/Aw3wsV357eWlZdMcPaOe2V2+3+qGwMEL4= -github.com/compose-spec/godotenv v1.1.0/go.mod h1:zF/3BOa18Z24tts5qnO/E9YURQanJTBUf7nlcCTNsyc= +github.com/compose-spec/compose-go v1.0.8 h1:fgT7mYYu5Sp37i2lUIAAvwJpkAHk6dP5ITHy/LlutUk= +github.com/compose-spec/compose-go v1.0.8/go.mod h1:REnCbBugoIdHB7S1sfkN/aJ7AJpNApGNjNiVjA9L8x4= +github.com/compose-spec/godotenv v1.1.1 h1:lp+WpAInnw06YN9sV/XLUOV/9z4C+6wjJdWlrdVac7o= +github.com/compose-spec/godotenv v1.1.1/go.mod h1:zF/3BOa18Z24tts5qnO/E9YURQanJTBUf7nlcCTNsyc= github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE= github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU= github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU= diff --git a/vendor/github.com/compose-spec/compose-go/loader/full-example.yml b/vendor/github.com/compose-spec/compose-go/loader/full-example.yml index 94634459..529d28b6 100644 --- a/vendor/github.com/compose-spec/compose-go/loader/full-example.yml +++ b/vendor/github.com/compose-spec/compose-go/loader/full-example.yml @@ -268,7 +268,7 @@ services: - .:/code - ./static:/var/www/html # User-relative path - - ~/configs:/etc/configs/:ro + - ~/configs:/etc/configs:ro # Named volume - datavolume:/var/lib/mysql - type: bind diff --git a/vendor/github.com/compose-spec/compose-go/loader/loader.go b/vendor/github.com/compose-spec/compose-go/loader/loader.go index 57505ee5..b55b0056 100644 --- a/vendor/github.com/compose-spec/compose-go/loader/loader.go +++ b/vendor/github.com/compose-spec/compose-go/loader/loader.go @@ -145,7 +145,7 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types. op(opts) } - configs := []*types.Config{} + var configs []*types.Config for i, file := range configDetails.ConfigFiles { configDict := file.Config if configDict == nil { @@ -222,14 +222,14 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types. } func parseConfig(b []byte, opts *Options) (map[string]interface{}, error) { - yaml, err := ParseYAML(b) + yml, err := ParseYAML(b) if err != nil { return nil, err } if !opts.SkipInterpolation { - return interp.Interpolate(yaml, *opts.Interpolate) + return interp.Interpolate(yml, *opts.Interpolate) } - return yaml, err + return yml, err } func groupXFieldsIntoExtensions(dict map[string]interface{}) map[string]interface{} { @@ -342,8 +342,8 @@ func createTransformHook(additionalTransformers ...Transformer) mapstructure.Dec reflect.TypeOf(types.UlimitsConfig{}): transformUlimits, reflect.TypeOf(types.UnitBytes(0)): transformSize, reflect.TypeOf([]types.ServicePortConfig{}): transformServicePort, - reflect.TypeOf(types.ServiceSecretConfig{}): transformStringSourceMap, - reflect.TypeOf(types.ServiceConfigObjConfig{}): transformStringSourceMap, + reflect.TypeOf(types.ServiceSecretConfig{}): transformFileReferenceConfig, + reflect.TypeOf(types.ServiceConfigObjConfig{}): transformFileReferenceConfig, reflect.TypeOf(types.StringOrNumberList{}): transformStringOrNumberList, reflect.TypeOf(map[string]*types.ServiceNetworkConfig{}): transformServiceNetworkMap, reflect.TypeOf(types.Mapping{}): transformMappingOrListFunc("=", false), @@ -372,7 +372,7 @@ func createTransformHook(additionalTransformers ...Transformer) mapstructure.Dec } } -// keys needs to be converted to strings for jsonschema +// keys need to be converted to strings for jsonschema func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) { if mapping, ok := value.(map[interface{}]interface{}); ok { dict := make(map[string]interface{}) @@ -396,7 +396,7 @@ func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interfac return dict, nil } if list, ok := value.([]interface{}); ok { - convertedList := []interface{}{} + var convertedList []interface{} for index, entry := range list { newKeyPrefix := fmt.Sprintf("%s[%d]", keyPrefix, index) convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) @@ -532,7 +532,7 @@ func LoadService(name string, serviceDict map[string]interface{}, workingDir str } for i, volume := range serviceConfig.Volumes { - if volume.Type != "bind" { + if volume.Type != types.VolumeTypeBind { continue } @@ -552,14 +552,14 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l environment := types.MappingWithEquals{} if len(serviceConfig.EnvFile) > 0 { - for _, file := range serviceConfig.EnvFile { - filePath := absPath(workingDir, file) + for _, envFile := range serviceConfig.EnvFile { + filePath := absPath(workingDir, envFile) file, err := os.Open(filePath) if err != nil { return err } defer file.Close() - fileVars, err := godotenv.Parse(file) + fileVars, err := godotenv.ParseWithLookup(file, godotenv.LookupFn(lookupEnv)) if err != nil { return err } @@ -797,7 +797,7 @@ var transformServicePort TransformerFunc = func(data interface{}) (interface{}, // We process the list instead of individual items here. // The reason is that one entry might be mapped to multiple ServicePortConfig. // Therefore we take an input of a list and return an output of a list. - ports := []interface{}{} + var ports []interface{} for _, entry := range entries { switch value := entry.(type) { case int: @@ -852,17 +852,27 @@ var transformServiceDeviceRequest TransformerFunc = func(data interface{}) (inte } } -var transformStringSourceMap TransformerFunc = func(data interface{}) (interface{}, error) { +var transformFileReferenceConfig TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: return map[string]interface{}{"source": value}, nil case map[string]interface{}: - return groupXFieldsIntoExtensions(data.(map[string]interface{})), nil + if target, ok := value["target"]; ok { + value["target"] = cleanTarget(target.(string)) + } + return groupXFieldsIntoExtensions(value), nil default: return data, errors.Errorf("invalid type %T for secret", value) } } +func cleanTarget(target string) string { + if target == "" { + return "" + } + return path.Clean(target) +} + var transformBuildConfig TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: @@ -906,9 +916,15 @@ var transformExtendsConfig TransformerFunc = func(data interface{}) (interface{} var transformServiceVolumeConfig TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: - return ParseVolume(value) + volume, err := ParseVolume(value) + volume.Target = cleanTarget(volume.Target) + return volume, err case map[string]interface{}: - return groupXFieldsIntoExtensions(data.(map[string]interface{})), nil + data := groupXFieldsIntoExtensions(data.(map[string]interface{})) + if target, ok := data["target"]; ok { + data["target"] = cleanTarget(target.(string)) + } + return data, nil default: return data, errors.Errorf("invalid type %T for service volume", value) } @@ -971,7 +987,7 @@ func transformMappingOrList(mappingOrList interface{}, sep string, allowNil bool switch value := mappingOrList.(type) { case map[string]interface{}: return toMapStringString(value, allowNil) - case ([]interface{}): + case []interface{}: result := make(map[string]interface{}) for _, value := range value { parts := strings.SplitN(value.(string), sep, 2) @@ -1054,7 +1070,7 @@ func toString(value interface{}, allowNil bool) interface{} { } func toStringList(value map[string]interface{}, separator string, allowNil bool) []string { - output := []string{} + var output []string for key, value := range value { if value == nil && !allowNil { continue diff --git a/vendor/github.com/compose-spec/compose-go/loader/merge.go b/vendor/github.com/compose-spec/compose-go/loader/merge.go index 0c7a6dd5..b01c868c 100644 --- a/vendor/github.com/compose-spec/compose-go/loader/merge.go +++ b/vendor/github.com/compose-spec/compose-go/loader/merge.go @@ -114,6 +114,11 @@ func _merge(baseService *types.ServiceConfig, overrideService *types.ServiceConf if overrideService.Entrypoint != nil { baseService.Entrypoint = overrideService.Entrypoint } + if baseService.Environment != nil { + baseService.Environment.OverrideBy(overrideService.Environment) + } else { + baseService.Environment = overrideService.Environment + } return baseService, nil } @@ -179,7 +184,7 @@ func toServiceVolumeConfigsMap(s interface{}) (map[interface{}]interface{}, erro } func toServiceSecretConfigsSlice(dst reflect.Value, m map[interface{}]interface{}) error { - s := []types.ServiceSecretConfig{} + var s []types.ServiceSecretConfig for _, v := range m { s = append(s, v.(types.ServiceSecretConfig)) } @@ -189,7 +194,7 @@ func toServiceSecretConfigsSlice(dst reflect.Value, m map[interface{}]interface{ } func toSServiceConfigObjConfigsSlice(dst reflect.Value, m map[interface{}]interface{}) error { - s := []types.ServiceConfigObjConfig{} + var s []types.ServiceConfigObjConfig for _, v := range m { s = append(s, v.(types.ServiceConfigObjConfig)) } @@ -199,7 +204,7 @@ func toSServiceConfigObjConfigsSlice(dst reflect.Value, m map[interface{}]interf } func toServicePortConfigsSlice(dst reflect.Value, m map[interface{}]interface{}) error { - s := []types.ServicePortConfig{} + var s []types.ServicePortConfig for _, v := range m { s = append(s, v.(types.ServicePortConfig)) } @@ -220,7 +225,7 @@ func toServicePortConfigsSlice(dst reflect.Value, m map[interface{}]interface{}) } func toServiceVolumeConfigsSlice(dst reflect.Value, m map[interface{}]interface{}) error { - s := []types.ServiceVolumeConfig{} + var s []types.ServiceVolumeConfig for _, v := range m { s = append(s, v.(types.ServiceVolumeConfig)) } @@ -229,7 +234,7 @@ func toServiceVolumeConfigsSlice(dst reflect.Value, m map[interface{}]interface{ return nil } -type tomapFn func(s interface{}) (map[interface{}]interface{}, error) +type toMapFn func(s interface{}) (map[interface{}]interface{}, error) type writeValueFromMapFn func(reflect.Value, map[interface{}]interface{}) error func safelyMerge(mergeFn func(dst, src reflect.Value) error) func(dst, src reflect.Value) error { @@ -245,13 +250,13 @@ func safelyMerge(mergeFn func(dst, src reflect.Value) error) func(dst, src refle } } -func mergeSlice(tomap tomapFn, writeValue writeValueFromMapFn) func(dst, src reflect.Value) error { +func mergeSlice(toMap toMapFn, writeValue writeValueFromMapFn) func(dst, src reflect.Value) error { return func(dst, src reflect.Value) error { - dstMap, err := sliceToMap(tomap, dst) + dstMap, err := sliceToMap(toMap, dst) if err != nil { return err } - srcMap, err := sliceToMap(tomap, src) + srcMap, err := sliceToMap(toMap, src) if err != nil { return err } @@ -262,12 +267,12 @@ func mergeSlice(tomap tomapFn, writeValue writeValueFromMapFn) func(dst, src ref } } -func sliceToMap(tomap tomapFn, v reflect.Value) (map[interface{}]interface{}, error) { +func sliceToMap(toMap toMapFn, v reflect.Value) (map[interface{}]interface{}, error) { // check if valid if !v.IsValid() { return nil, errors.Errorf("invalid value : %+v", v) } - return tomap(v.Interface()) + return toMap(v.Interface()) } func mergeLoggingConfig(dst, src reflect.Value) error { diff --git a/vendor/github.com/compose-spec/compose-go/loader/volume.go b/vendor/github.com/compose-spec/compose-go/loader/volume.go index 173b76b6..dd0f612e 100644 --- a/vendor/github.com/compose-spec/compose-go/loader/volume.go +++ b/vendor/github.com/compose-spec/compose-go/loader/volume.go @@ -36,11 +36,11 @@ func ParseVolume(spec string) (types.ServiceVolumeConfig, error) { return volume, errors.New("invalid empty volume spec") case 1, 2: volume.Target = spec - volume.Type = string(types.VolumeTypeVolume) + volume.Type = types.VolumeTypeVolume return volume, nil } - buffer := []rune{} + var buffer []rune for _, char := range spec + string(endOfSpec) { switch { case isWindowsDrive(buffer, char): @@ -50,7 +50,7 @@ func ParseVolume(spec string) (types.ServiceVolumeConfig, error) { populateType(&volume) return volume, errors.Wrapf(err, "invalid spec: %s", spec) } - buffer = []rune{} + buffer = nil default: buffer = append(buffer, char) } diff --git a/vendor/github.com/compose-spec/compose-go/template/template.go b/vendor/github.com/compose-spec/compose-go/template/template.go index 26e9b36a..ecb7358b 100644 --- a/vendor/github.com/compose-spec/compose-go/template/template.go +++ b/vendor/github.com/compose-spec/compose-go/template/template.go @@ -26,7 +26,7 @@ import ( var delimiter = "\\$" var substitutionNamed = "[_a-z][_a-z0-9]*" -var substitutionBraced = "[_a-z][_a-z0-9]*(?::?[-?][^}]*)?" +var substitutionBraced = "[_a-z][_a-z0-9]*(?::?[-?](.*}|[^}]*))?" var patternString = fmt.Sprintf( "%s(?i:(?P%s)|(?P%s)|{(?P%s)}|(?P))", @@ -35,14 +35,6 @@ var patternString = fmt.Sprintf( var defaultPattern = regexp.MustCompile(patternString) -// DefaultSubstituteFuncs contains the default SubstituteFunc used by the docker cli -var DefaultSubstituteFuncs = []SubstituteFunc{ - softDefault, - hardDefault, - requiredNonEmpty, - required, -} - // InvalidTemplateError is returned when a variable template is not in a valid // format type InvalidTemplateError struct { @@ -67,6 +59,14 @@ type SubstituteFunc func(string, Mapping) (string, bool, error) // 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) { + if len(subsFuncs) == 0 { + subsFuncs = []SubstituteFunc{ + softDefault, + hardDefault, + requiredNonEmpty, + required, + } + } var err error result := pattern.ReplaceAllStringFunc(template, func(substring string) string { matches := pattern.FindStringSubmatch(substring) @@ -116,7 +116,7 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su // Substitute variables in the string with their values func Substitute(template string, mapping Mapping) (string, error) { - return SubstituteWith(template, mapping, defaultPattern, DefaultSubstituteFuncs...) + return SubstituteWith(template, mapping, defaultPattern) } // ExtractVariables returns a map of all the variables defined in the specified @@ -215,6 +215,10 @@ func softDefault(substitution string, mapping Mapping) (string, bool, error) { return "", false, nil } name, defaultValue := partition(substitution, sep) + defaultValue, err := Substitute(defaultValue, mapping) + if err != nil { + return "", false, err + } value, ok := mapping(name) if !ok || value == "" { return defaultValue, true, nil @@ -229,6 +233,10 @@ func hardDefault(substitution string, mapping Mapping) (string, bool, error) { return "", false, nil } name, defaultValue := partition(substitution, sep) + defaultValue, err := Substitute(defaultValue, mapping) + if err != nil { + return "", false, err + } value, ok := mapping(name) if !ok { return defaultValue, true, nil @@ -249,6 +257,10 @@ func withRequired(substitution string, mapping Mapping, sep string, valid func(s return "", false, nil } name, errorMessage := partition(substitution, sep) + errorMessage, err := Substitute(errorMessage, mapping) + if err != nil { + return "", false, err + } value, ok := mapping(name) if !ok || !valid(value) { return "", true, &InvalidTemplateError{ diff --git a/vendor/github.com/compose-spec/compose-go/types/project.go b/vendor/github.com/compose-spec/compose-go/types/project.go index 155fad0b..6de8e61e 100644 --- a/vendor/github.com/compose-spec/compose-go/types/project.go +++ b/vendor/github.com/compose-spec/compose-go/types/project.go @@ -46,7 +46,7 @@ type Project struct { // ServiceNames return names for all services in this Compose config func (p Project) ServiceNames() []string { - names := []string{} + var names []string for _, s := range p.Services { names = append(names, s.Name) } @@ -56,7 +56,7 @@ func (p Project) ServiceNames() []string { // VolumeNames return names for all volumes in this Compose config func (p Project) VolumeNames() []string { - names := []string{} + var names []string for k := range p.Volumes { names = append(names, k) } @@ -66,7 +66,7 @@ func (p Project) VolumeNames() []string { // NetworkNames return names for all volumes in this Compose config func (p Project) NetworkNames() []string { - names := []string{} + var names []string for k := range p.Networks { names = append(names, k) } @@ -76,7 +76,7 @@ func (p Project) NetworkNames() []string { // SecretNames return names for all secrets in this Compose config func (p Project) SecretNames() []string { - names := []string{} + var names []string for k := range p.Secrets { names = append(names, k) } @@ -86,7 +86,7 @@ func (p Project) SecretNames() []string { // ConfigNames return names for all configs in this Compose config func (p Project) ConfigNames() []string { - names := []string{} + var names []string for k := range p.Configs { names = append(names, k) } @@ -179,12 +179,12 @@ func (p *Project) RelativePath(path string) string { } // HasProfile return true if service has no profile declared or has at least one profile matching -func (service ServiceConfig) HasProfile(profiles []string) bool { - if len(service.Profiles) == 0 { +func (s ServiceConfig) HasProfile(profiles []string) bool { + if len(s.Profiles) == 0 { return true } for _, p := range profiles { - for _, sp := range service.Profiles { + for _, sp := range s.Profiles { if sp == p { return true } @@ -327,7 +327,6 @@ func (p *Project) ResolveImages(resolver func(named reference.Named) (digest.Dig if err != nil { return err } - named, err = reference.WithDigest(named, digest) if err != nil { return err diff --git a/vendor/github.com/compose-spec/compose-go/types/types.go b/vendor/github.com/compose-spec/compose-go/types/types.go index 4d68f868..c19d0ebf 100644 --- a/vendor/github.com/compose-spec/compose-go/types/types.go +++ b/vendor/github.com/compose-spec/compose-go/types/types.go @@ -33,7 +33,7 @@ func (d Duration) String() string { return time.Duration(d).String() } -// ConvertDurationPtr converts a typedefined Duration pointer to a time.Duration pointer with the same value. +// ConvertDurationPtr converts a type defined Duration pointer to a time.Duration pointer with the same value. func ConvertDurationPtr(d *Duration) *time.Duration { if d == nil { return nil @@ -121,7 +121,7 @@ type ServiceConfig struct { Extends ExtendsConfig `yaml:"extends,omitempty" json:"extends,omitempty"` ExternalLinks []string `mapstructure:"external_links" yaml:"external_links,omitempty" json:"external_links,omitempty"` ExtraHosts HostsList `mapstructure:"extra_hosts" yaml:"extra_hosts,omitempty" json:"extra_hosts,omitempty"` - GroupAdd []string `mapstructure:"group_app" yaml:"group_add,omitempty" json:"group_add,omitempty"` + GroupAdd []string `mapstructure:"group_add" yaml:"group_add,omitempty" json:"group_add,omitempty"` Hostname string `yaml:",omitempty" json:"hostname,omitempty"` HealthCheck *HealthCheckConfig `yaml:",omitempty" json:"healthcheck,omitempty"` Image string `yaml:",omitempty" json:"image,omitempty"` @@ -208,7 +208,7 @@ const ( PullPolicyNever = "never" //PullPolicyIfNotPresent pull missing images PullPolicyIfNotPresent = "if_not_present" - //PullPolicyIfNotPresent pull missing images + //PullPolicyMissing pull missing images PullPolicyMissing = "missing" //PullPolicyBuild force building images PullPolicyBuild = "build" @@ -611,7 +611,7 @@ func ParsePortConfig(value string) ([]ServicePortConfig, error) { } func convertPortToPortConfig(port nat.Port, portBindings map[nat.Port][]nat.PortBinding) ([]ServicePortConfig, error) { - portConfigs := []ServicePortConfig{} + var portConfigs []ServicePortConfig for _, binding := range portBindings[port] { startHostPort, endHostPort, err := nat.ParsePortRange(binding.HostPort) @@ -647,13 +647,13 @@ type ServiceVolumeConfig struct { } const ( - // TypeBind is the type for mounting host dir + // VolumeTypeBind is the type for mounting host dir VolumeTypeBind = "bind" - // TypeVolume is the type for remote storage volumes + // VolumeTypeVolume is the type for remote storage volumes VolumeTypeVolume = "volume" - // TypeTmpfs is the type for mounting tmpfs + // VolumeTypeTmpfs is the type for mounting tmpfs VolumeTypeTmpfs = "tmpfs" - // TypeNamedPipe is the type for mounting Windows named pipes + // VolumeTypeNamedPipe is the type for mounting Windows named pipes VolumeTypeNamedPipe = "npipe" ) diff --git a/vendor/github.com/compose-spec/godotenv/godotenv.go b/vendor/github.com/compose-spec/godotenv/godotenv.go index 7c44ac53..4045e345 100644 --- a/vendor/github.com/compose-spec/godotenv/godotenv.go +++ b/vendor/github.com/compose-spec/godotenv/godotenv.go @@ -266,12 +266,12 @@ func parseLineWithLookup(line string, envMap map[string]string, lookupFn LookupF firstColon := strings.Index(line, ":") splitString := strings.SplitN(line, "=", 2) if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) { - //this is a yaml-style line + // This is a yaml-style line splitString = strings.SplitN(line, ":", 2) } if len(splitString) != 2 { - err = errors.New("Can't separate key from value") + err = errors.New("can't separate key from value") return } key = exportRegex.ReplaceAllString(splitString[0], "$1") @@ -341,15 +341,15 @@ func expandVariables(v string, envMap map[string]string, lookupFn LookupFn) stri if submatch[1] == "\\" || submatch[2] == "(" { return submatch[0][1:] } else if submatch[4] != "" { - //first check if we have defined this already earlier + // first check if we have defined this already earlier if envMap[submatch[4]] != "" { return envMap[submatch[4]] } if lookupFn == nil { return "" } - //if we have not defined it, check the lookup function provided - //by the user + // if we have not defined it, check the lookup function provided + // by the user s2, ok := lookupFn(submatch[4]) if ok { return s2 diff --git a/vendor/github.com/compose-spec/godotenv/parser.go b/vendor/github.com/compose-spec/godotenv/parser.go index dd8c4b56..1d144de0 100644 --- a/vendor/github.com/compose-spec/godotenv/parser.go +++ b/vendor/github.com/compose-spec/godotenv/parser.go @@ -127,15 +127,21 @@ loop: // extractVarValue extracts variable value and returns rest of slice func extractVarValue(src []byte, envMap map[string]string, lookupFn LookupFn) (value string, rest []byte, err error) { - quote, hasPrefix := hasQuotePrefix(src) - if !hasPrefix { - // unquoted value - read until whitespace - end := bytes.IndexFunc(src, unicode.IsSpace) - if end == -1 { - return expandVariables(string(src), envMap, lookupFn), nil, nil + quote, isQuoted := hasQuotePrefix(src) + if !isQuoted { + // unquoted value - read until new line + end := bytes.IndexFunc(src, isNewLine) + var rest []byte + var value string + if end < 0 { + value := strings.TrimRightFunc(string(src), unicode.IsSpace) + rest = nil + return expandVariables(value, envMap, lookupFn), rest, nil } - return expandVariables(string(src[0:end]), envMap, lookupFn), src[end:], nil + value = strings.TrimRightFunc(string(src[0:end]), unicode.IsSpace) + rest = src[end:] + return expandVariables(value, envMap, lookupFn), rest, nil } // lookup quoted string terminator @@ -192,7 +198,7 @@ func indexOfNonSpaceChar(src []byte) int { } // hasQuotePrefix reports whether charset starts with single or double quote and returns quote character -func hasQuotePrefix(src []byte) (prefix byte, isQuored bool) { +func hasQuotePrefix(src []byte) (quote byte, isQuoted bool) { if len(src) == 0 { return 0, false } @@ -221,3 +227,9 @@ func isSpace(r rune) bool { } return false } + + +// isNewLine reports whether the rune is a new line character +func isNewLine(r rune) bool { + return r == '\n' +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 360b2221..f8062e83 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -30,7 +30,7 @@ github.com/cenkalti/backoff/v4 github.com/cespare/xxhash/v2 # github.com/cloudflare/cfssl v0.0.0-20181213083726-b94e044bb51e ## explicit -# github.com/compose-spec/compose-go v1.0.5 +# github.com/compose-spec/compose-go v1.0.8 ## explicit github.com/compose-spec/compose-go/errdefs github.com/compose-spec/compose-go/interpolation @@ -38,7 +38,7 @@ github.com/compose-spec/compose-go/loader github.com/compose-spec/compose-go/schema github.com/compose-spec/compose-go/template github.com/compose-spec/compose-go/types -# github.com/compose-spec/godotenv v1.1.0 +# github.com/compose-spec/godotenv v1.1.1 github.com/compose-spec/godotenv # github.com/containerd/console v1.0.3 ## explicit