diff --git a/vendor/github.com/docker/libcompose/config/interpolation.go b/vendor/github.com/docker/libcompose/config/interpolation.go index fc420de9a..66c987a71 100644 --- a/vendor/github.com/docker/libcompose/config/interpolation.go +++ b/vendor/github.com/docker/libcompose/config/interpolation.go @@ -102,7 +102,7 @@ func parseLine(line string, mapping func(string) string) (string, bool) { return buffer.String(), true } -func parseConfig(option, service string, data *interface{}, mapping func(string) string) error { +func parseConfig(key string, data *interface{}, mapping func(string) string) error { switch typedData := (*data).(type) { case string: var success bool @@ -110,11 +110,11 @@ func parseConfig(option, service string, data *interface{}, mapping func(string) *data, success = parseLine(typedData, mapping) if !success { - return fmt.Errorf("Invalid interpolation format for \"%s\" option in service \"%s\": \"%s\"", option, service, typedData) + return fmt.Errorf("Invalid interpolation format for key \"%s\": \"%s\"", key, typedData) } case []interface{}: for k, v := range typedData { - err := parseConfig(option, service, &v, mapping) + err := parseConfig(key, &v, mapping) if err != nil { return err @@ -124,7 +124,7 @@ func parseConfig(option, service string, data *interface{}, mapping func(string) } case map[interface{}]interface{}: for k, v := range typedData { - err := parseConfig(option, service, &v, mapping) + err := parseConfig(key, &v, mapping) if err != nil { return err @@ -137,33 +137,21 @@ func parseConfig(option, service string, data *interface{}, mapping func(string) return nil } -// Interpolate replaces variables in the raw map representation of the project file -func Interpolate(environmentLookup EnvironmentLookup, config *RawServiceMap) error { - for k, v := range *config { - for k2, v2 := range v { - err := parseConfig(k2, k, &v2, func(s string) string { - values := environmentLookup.Lookup(s, k, nil) +// Interpolate replaces variables in a map entry +func Interpolate(key string, data *interface{}, environmentLookup EnvironmentLookup) error { + return parseConfig(key, data, func(s string) string { + values := environmentLookup.Lookup(s, nil) - if len(values) == 0 { - logrus.Warnf("The %s variable is not set. Substituting a blank string.", s) - return "" - } - - // Use first result if many are given - value := values[0] - - // Environment variables come in key=value format - // Return everything past first '=' - return strings.SplitN(value, "=", 2)[1] - }) - - if err != nil { - return err - } - - (*config)[k][k2] = v2 + if len(values) == 0 { + logrus.Warnf("The %s variable is not set. Substituting a blank string.", s) + return "" } - } - return nil + // Use first result if many are given + value := values[0] + + // Environment variables come in key=value format + // Return everything past first '=' + return strings.SplitN(value, "=", 2)[1] + }) } diff --git a/vendor/github.com/docker/libcompose/config/merge.go b/vendor/github.com/docker/libcompose/config/merge.go index 1c56d7be0..eb4f229a1 100644 --- a/vendor/github.com/docker/libcompose/config/merge.go +++ b/vendor/github.com/docker/libcompose/config/merge.go @@ -29,18 +29,8 @@ func CreateConfig(bytes []byte) (*Config, error) { if err := yaml.Unmarshal(bytes, &config); err != nil { return nil, err } - if config.Version == "2" { - for key, value := range config.Networks { - if value == nil { - config.Networks[key] = &NetworkConfig{} - } - } - for key, value := range config.Volumes { - if value == nil { - config.Volumes[key] = &VolumeConfig{} - } - } - } else { + + if config.Version != "2" { var baseRawServices RawServiceMap if err := yaml.Unmarshal(bytes, &baseRawServices); err != nil { return nil, err @@ -48,6 +38,13 @@ func CreateConfig(bytes []byte) (*Config, error) { config.Services = baseRawServices } + if config.Volumes == nil { + config.Volumes = make(map[string]interface{}) + } + if config.Networks == nil { + config.Networks = make(map[string]interface{}) + } + return &config, nil } @@ -63,6 +60,34 @@ func Merge(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup } baseRawServices := config.Services + if options.Interpolate { + if err := InterpolateRawServiceMap(&baseRawServices, environmentLookup); err != nil { + return "", nil, nil, nil, err + } + + for k, v := range config.Volumes { + if err := Interpolate(k, &v, environmentLookup); err != nil { + return "", nil, nil, nil, err + } + config.Volumes[k] = v + } + + for k, v := range config.Networks { + if err := Interpolate(k, &v, environmentLookup); err != nil { + return "", nil, nil, nil, err + } + config.Networks[k] = v + } + } + + if options.Preprocess != nil { + var err error + baseRawServices, err = options.Preprocess(baseRawServices) + if err != nil { + return "", nil, nil, nil, err + } + } + var serviceConfigs map[string]*ServiceConfig if config.Version == "2" { var err error @@ -91,7 +116,28 @@ func Merge(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup } } - return config.Version, serviceConfigs, config.Volumes, config.Networks, nil + var volumes map[string]*VolumeConfig + var networks map[string]*NetworkConfig + if err := utils.Convert(config.Volumes, &volumes); err != nil { + return "", nil, nil, nil, err + } + if err := utils.Convert(config.Networks, &networks); err != nil { + return "", nil, nil, nil, err + } + + return config.Version, serviceConfigs, volumes, networks, nil +} + +func InterpolateRawServiceMap(baseRawServices *RawServiceMap, environmentLookup EnvironmentLookup) error { + for k, v := range *baseRawServices { + for k2, v2 := range v { + if err := Interpolate(k2, &v2, environmentLookup); err != nil { + return err + } + (*baseRawServices)[k][k2] = v2 + } + } + return nil } func adjustValues(configs map[string]*ServiceConfig) { diff --git a/vendor/github.com/docker/libcompose/config/merge_v1.go b/vendor/github.com/docker/libcompose/config/merge_v1.go index c1eeeae73..dab39144f 100644 --- a/vendor/github.com/docker/libcompose/config/merge_v1.go +++ b/vendor/github.com/docker/libcompose/config/merge_v1.go @@ -10,20 +10,6 @@ import ( // MergeServicesV1 merges a v1 compose file into an existing set of service configs func MergeServicesV1(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, datas RawServiceMap, options *ParseOptions) (map[string]*ServiceConfigV1, error) { - if options.Interpolate { - if err := Interpolate(environmentLookup, &datas); err != nil { - return nil, err - } - } - - if options.Preprocess != nil { - var err error - datas, err = options.Preprocess(datas) - if err != nil { - return nil, err - } - } - if options.Validate { if err := validate(datas); err != nil { return nil, err @@ -117,8 +103,7 @@ func parseV1(resourceLookup ResourceLookup, environmentLookup EnvironmentLookup, baseRawServices := config.Services if options.Interpolate { - err = Interpolate(environmentLookup, &baseRawServices) - if err != nil { + if err = InterpolateRawServiceMap(&baseRawServices, environmentLookup); err != nil { return nil, err } } diff --git a/vendor/github.com/docker/libcompose/config/merge_v2.go b/vendor/github.com/docker/libcompose/config/merge_v2.go index e9e5678ba..085829e41 100644 --- a/vendor/github.com/docker/libcompose/config/merge_v2.go +++ b/vendor/github.com/docker/libcompose/config/merge_v2.go @@ -10,20 +10,6 @@ import ( // MergeServicesV2 merges a v2 compose file into an existing set of service configs func MergeServicesV2(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, datas RawServiceMap, options *ParseOptions) (map[string]*ServiceConfig, error) { - if options.Interpolate { - if err := Interpolate(environmentLookup, &datas); err != nil { - return nil, err - } - } - - if options.Preprocess != nil { - var err error - datas, err = options.Preprocess(datas) - if err != nil { - return nil, err - } - } - if options.Validate { if err := validateV2(datas); err != nil { return nil, err @@ -108,8 +94,7 @@ func parseV2(resourceLookup ResourceLookup, environmentLookup EnvironmentLookup, baseRawServices := config.Services if options.Interpolate { - err = Interpolate(environmentLookup, &baseRawServices) - if err != nil { + if err = InterpolateRawServiceMap(&baseRawServices, environmentLookup); err != nil { return nil, err } } diff --git a/vendor/github.com/docker/libcompose/config/types.go b/vendor/github.com/docker/libcompose/config/types.go index e28f49fbc..ac8d156c6 100644 --- a/vendor/github.com/docker/libcompose/config/types.go +++ b/vendor/github.com/docker/libcompose/config/types.go @@ -8,7 +8,7 @@ import ( // EnvironmentLookup defines methods to provides environment variable loading. type EnvironmentLookup interface { - Lookup(key, serviceName string, config *ServiceConfig) []string + Lookup(key string, config *ServiceConfig) []string } // ResourceLookup defines methods to provides file loading. @@ -190,10 +190,10 @@ type NetworkConfig struct { // Config holds libcompose top level configuration type Config struct { - Version string `yaml:"version,omitempty"` - Services RawServiceMap `yaml:"services,omitempty"` - Volumes map[string]*VolumeConfig `yaml:"volumes,omitempty"` - Networks map[string]*NetworkConfig `yaml:"networks,omitempty"` + Version string `yaml:"version,omitempty"` + Services RawServiceMap `yaml:"services,omitempty"` + Volumes map[string]interface{} `yaml:"volumes,omitempty"` + Networks map[string]interface{} `yaml:"networks,omitempty"` } // NewServiceConfigs initializes a new Configs struct diff --git a/vendor/github.com/docker/libcompose/lookup/composable.go b/vendor/github.com/docker/libcompose/lookup/composable.go index c48987fef..ff76480b3 100644 --- a/vendor/github.com/docker/libcompose/lookup/composable.go +++ b/vendor/github.com/docker/libcompose/lookup/composable.go @@ -13,10 +13,10 @@ type ComposableEnvLookup struct { // Lookup creates a string slice of string containing a "docker-friendly" environment string // in the form of 'key=value'. It loop through the lookups and returns the latest value if // more than one lookup return a result. -func (l *ComposableEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string { +func (l *ComposableEnvLookup) Lookup(key string, config *config.ServiceConfig) []string { result := []string{} for _, lookup := range l.Lookups { - env := lookup.Lookup(key, serviceName, config) + env := lookup.Lookup(key, config) if len(env) == 1 { result = env } diff --git a/vendor/github.com/docker/libcompose/lookup/envfile.go b/vendor/github.com/docker/libcompose/lookup/envfile.go index 65bd98674..62241255c 100644 --- a/vendor/github.com/docker/libcompose/lookup/envfile.go +++ b/vendor/github.com/docker/libcompose/lookup/envfile.go @@ -16,7 +16,7 @@ type EnvfileLookup struct { // Lookup creates a string slice of string containing a "docker-friendly" environment string // in the form of 'key=value'. It gets environment values using a '.env' file in the specified // path. -func (l *EnvfileLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string { +func (l *EnvfileLookup) Lookup(key string, config *config.ServiceConfig) []string { envs, err := opts.ParseEnvFile(l.Path) if err != nil { return []string{} diff --git a/vendor/github.com/docker/libcompose/lookup/simple_env.go b/vendor/github.com/docker/libcompose/lookup/simple_env.go index 6f8c25bf2..40ce12843 100644 --- a/vendor/github.com/docker/libcompose/lookup/simple_env.go +++ b/vendor/github.com/docker/libcompose/lookup/simple_env.go @@ -15,7 +15,7 @@ type OsEnvLookup struct { // in the form of 'key=value'. It gets environment values using os.Getenv. // If the os environment variable does not exists, the slice is empty. serviceName and config // are not used at all in this implementation. -func (o *OsEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string { +func (o *OsEnvLookup) Lookup(key string, config *config.ServiceConfig) []string { ret := os.Getenv(key) if ret == "" { return []string{} diff --git a/vendor/github.com/docker/libcompose/project/project.go b/vendor/github.com/docker/libcompose/project/project.go index a0f25c698..b07de8271 100644 --- a/vendor/github.com/docker/libcompose/project/project.go +++ b/vendor/github.com/docker/libcompose/project/project.go @@ -141,7 +141,7 @@ func (p *Project) CreateService(name string) (Service, error) { env = parts[0] } - for _, value := range p.context.EnvironmentLookup.Lookup(env, name, &config) { + for _, value := range p.context.EnvironmentLookup.Lookup(env, &config) { parsedEnv = append(parsedEnv, value) } } @@ -151,7 +151,7 @@ func (p *Project) CreateService(name string) (Service, error) { // check the environment for extra build Args that are set but not given a value in the compose file for arg, value := range config.Build.Args { if value == "\x00" { - envValue := p.context.EnvironmentLookup.Lookup(arg, name, &config) + envValue := p.context.EnvironmentLookup.Lookup(arg, &config) // depending on what we get back we do different things switch l := len(envValue); l { case 0: diff --git a/vendor/github.com/rancher/rancher-compose/lookup/env.go b/vendor/github.com/rancher/rancher-compose/lookup/env.go index efc892919..afde3cae7 100644 --- a/vendor/github.com/rancher/rancher-compose/lookup/env.go +++ b/vendor/github.com/rancher/rancher-compose/lookup/env.go @@ -46,7 +46,7 @@ func NewFileEnvLookup(file string, parent config.EnvironmentLookup) (*FileEnvLoo }, nil } -func (f *FileEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string { +func (f *FileEnvLookup) Lookup(key string, config *config.ServiceConfig) []string { if v, ok := f.variables[key]; ok { return []string{fmt.Sprintf("%s=%s", key, v)} } @@ -55,5 +55,5 @@ func (f *FileEnvLookup) Lookup(key, serviceName string, config *config.ServiceCo return nil } - return f.parent.Lookup(key, serviceName, config) + return f.parent.Lookup(key, config) } diff --git a/vendor/github.com/rancher/rancher-compose/lookup/map_env.go b/vendor/github.com/rancher/rancher-compose/lookup/map_env.go index 01e9986af..5aa007984 100644 --- a/vendor/github.com/rancher/rancher-compose/lookup/map_env.go +++ b/vendor/github.com/rancher/rancher-compose/lookup/map_env.go @@ -10,7 +10,7 @@ type MapEnvLookup struct { Env map[string]interface{} } -func (m *MapEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string { +func (m *MapEnvLookup) Lookup(key string, config *config.ServiceConfig) []string { if v, ok := m.Env[key]; ok { return []string{fmt.Sprintf("%s=%v", key, v)} } diff --git a/vendor/github.com/rancher/rancher-compose/lookup/questions.go b/vendor/github.com/rancher/rancher-compose/lookup/questions.go index 067dd366f..2a0fa5061 100644 --- a/vendor/github.com/rancher/rancher-compose/lookup/questions.go +++ b/vendor/github.com/rancher/rancher-compose/lookup/questions.go @@ -107,7 +107,7 @@ func join(key, v string) []string { return []string{fmt.Sprintf("%s=%s", key, v)} } -func (f *QuestionLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string { +func (f *QuestionLookup) Lookup(key string, config *config.ServiceConfig) []string { if v, ok := f.variables[key]; ok { return join(key, v) } @@ -122,7 +122,7 @@ func (f *QuestionLookup) Lookup(key, serviceName string, config *config.ServiceC } if f.parent != nil { - parentResult := f.parent.Lookup(key, serviceName, config) + parentResult := f.parent.Lookup(key, config) if len(parentResult) > 0 { return parentResult } diff --git a/vendor/github.com/rancher/rancher-compose/rancher/certs.go b/vendor/github.com/rancher/rancher-compose/rancher/certs.go index 03e1a6f06..6f39e0b4a 100644 --- a/vendor/github.com/rancher/rancher-compose/rancher/certs.go +++ b/vendor/github.com/rancher/rancher-compose/rancher/certs.go @@ -12,7 +12,7 @@ func populateCerts(apiClient *client.RancherClient, lbService *CompositeService, if err != nil { return err } - lbService.LbConfig.DefaultCertificateId = certId + lbService.RealLbConfig.DefaultCertificateId = certId } certIds := []string{} @@ -23,7 +23,7 @@ func populateCerts(apiClient *client.RancherClient, lbService *CompositeService, } certIds = append(certIds, certId) } - lbService.LbConfig.CertificateIds = certIds + lbService.RealLbConfig.CertificateIds = certIds return nil } diff --git a/vendor/github.com/rancher/rancher-compose/rancher/context.go b/vendor/github.com/rancher/rancher-compose/rancher/context.go index d8037fcbb..18aab0918 100644 --- a/vendor/github.com/rancher/rancher-compose/rancher/context.go +++ b/vendor/github.com/rancher/rancher-compose/rancher/context.go @@ -196,7 +196,7 @@ func (c *Context) unmarshalBytes(composeBytes, bytes []byte) error { } func (c *Context) fillInRancherConfig(rawServiceMap config.RawServiceMap) error { - if err := config.Interpolate(c.EnvironmentLookup, &rawServiceMap); err != nil { + if err := config.InterpolateRawServiceMap(&rawServiceMap, c.EnvironmentLookup); err != nil { return err } diff --git a/vendor/github.com/rancher/rancher-compose/rancher/lb_service.go b/vendor/github.com/rancher/rancher-compose/rancher/lb_service.go index 0569dbd0d..abfa6c072 100644 --- a/vendor/github.com/rancher/rancher-compose/rancher/lb_service.go +++ b/vendor/github.com/rancher/rancher-compose/rancher/lb_service.go @@ -14,7 +14,20 @@ func populateLbFields(r *RancherService, launchConfig *client.LaunchConfig, serv serviceType := FindServiceType(r) config, ok := r.context.RancherConfig[r.name] - if !ok { + if ok { + if serviceType == RancherType && config.LbConfig != nil { + service.LbConfig = &client.LbTargetConfig{} + service.LbConfig.PortRules = []client.TargetPortRule{} + for _, portRule := range config.LbConfig.PortRules { + service.LbConfig.PortRules = append(service.LbConfig.PortRules, client.TargetPortRule{ + BackendName: portRule.BackendName, + Hostname: portRule.Hostname, + Path: portRule.Path, + TargetPort: int64(portRule.TargetPort), + }) + } + } + } else { if serviceType == LegacyLbServiceType { r.context.RancherConfig[r.name] = RancherConfig{} config = r.context.RancherConfig[r.name] @@ -36,13 +49,13 @@ func populateLbFields(r *RancherService, launchConfig *client.LaunchConfig, serv existingHAProxyConfig = generateHAProxyConf(config.LegacyLoadBalancerConfig.HaproxyConfig.Global, config.LegacyLoadBalancerConfig.HaproxyConfig.Defaults) } } - service.LbConfig = &client.LbConfig{ + service.RealLbConfig = &client.LbConfig{ CertificateIds: config.Certs, Config: string(existingHAProxyConfig), DefaultCertificateId: config.DefaultCert, } if legacyStickinessPolicy != nil { - service.LbConfig.StickinessPolicy = &client.LoadBalancerCookieStickinessPolicy{ + service.RealLbConfig.StickinessPolicy = &client.LoadBalancerCookieStickinessPolicy{ Cookie: legacyStickinessPolicy.Cookie, Domain: legacyStickinessPolicy.Domain, Indirect: legacyStickinessPolicy.Indirect, @@ -94,7 +107,7 @@ func populateLbFields(r *RancherService, launchConfig *client.LaunchConfig, serv if label, ok := r.serviceConfig.Labels[labelName]; ok { split := strings.Split(label, ",") for _, portString := range split { - service.LbConfig.Config += fmt.Sprintf(` + service.RealLbConfig.Config += fmt.Sprintf(` frontend %s accept-proxy`, portString) } @@ -107,7 +120,7 @@ frontend %s if targetService == nil { return fmt.Errorf("Failed to find existing service: %s", portRule.Service) } - service.LbConfig.PortRules = append(service.LbConfig.PortRules, client.PortRule{ + service.RealLbConfig.PortRules = append(service.RealLbConfig.PortRules, client.PortRule{ SourcePort: int64(portRule.SourcePort), Protocol: portRule.Protocol, Path: portRule.Path, @@ -130,12 +143,12 @@ frontend %s return populateCerts(r.context.Client, service, config.DefaultCert, config.Certs) } else if serviceType == LbServiceType { - service.LbConfig = &client.LbConfig{ + service.RealLbConfig = &client.LbConfig{ Config: config.LbConfig.Config, } stickinessPolicy := config.LbConfig.StickinessPolicy if stickinessPolicy != nil { - service.LbConfig.StickinessPolicy = &client.LoadBalancerCookieStickinessPolicy{ + service.RealLbConfig.StickinessPolicy = &client.LoadBalancerCookieStickinessPolicy{ Name: stickinessPolicy.Name, Cookie: stickinessPolicy.Cookie, Domain: stickinessPolicy.Domain, @@ -168,7 +181,7 @@ frontend %s finalPortRule.ServiceId = targetService.Id } - service.LbConfig.PortRules = append(service.LbConfig.PortRules, finalPortRule) + service.RealLbConfig.PortRules = append(service.RealLbConfig.PortRules, finalPortRule) } launchConfig.Ports = r.serviceConfig.Ports diff --git a/vendor/github.com/rancher/rancher-compose/rancher/types.go b/vendor/github.com/rancher/rancher-compose/rancher/types.go index af6d52ab0..8e26c69c2 100644 --- a/vendor/github.com/rancher/rancher-compose/rancher/types.go +++ b/vendor/github.com/rancher/rancher-compose/rancher/types.go @@ -25,7 +25,7 @@ func FindServiceType(r *RancherService) ServiceType { return ExternalServiceType } else if r.serviceConfig.Image == LB_IMAGE { return LegacyLbServiceType - } else if r.RancherConfig().LbConfig != nil { + } else if isLbServiceType(r.RancherConfig().LbConfig) { return LbServiceType } else if r.serviceConfig.Image == DNS_IMAGE { return DnsServiceType @@ -38,12 +38,26 @@ func FindServiceType(r *RancherService) ServiceType { return RancherType } +func isLbServiceType(lbConfig *LBConfig) bool { + if lbConfig == nil { + return false + } + + for _, portRule := range lbConfig.PortRules { + if portRule.SourcePort != 0 { + return true + } + } + + return false +} + type CompositeService struct { client.Service StorageDriver *client.StorageDriver `json:"storageDriver,omitempty" yaml:"storageDriver,omitempty"` NetworkDriver *client.NetworkDriver `json:"networkDriver,omitempty" yaml:"networkDriver,omitempty"` - LbConfig *client.LbConfig `json:"lbConfig,omitempty" yaml:"lb_config,omitempty"` + RealLbConfig *client.LbConfig `json:"lbConfig,omitempty" yaml:"lb_config,omitempty"` // External Service Fields ExternalIpAddresses []string `json:"externalIpAddresses,omitempty" yaml:"external_ip_addresses,omitempty"` diff --git a/vendor/github.com/rancher/rancher-compose/trash.conf b/vendor/github.com/rancher/rancher-compose/trash.conf index 477484c3b..ec68c2d87 100644 --- a/vendor/github.com/rancher/rancher-compose/trash.conf +++ b/vendor/github.com/rancher/rancher-compose/trash.conf @@ -4,7 +4,7 @@ github.com/urfave/cli v1.18.0 github.com/docker/distribution 77b9d2997abcded79a5314970fe69a44c93c25fb github.com/docker/docker 8658748ef716e43a5f6d834825d818012ed6e2c4 github.com/docker/go-connections 988efe982fdecb46f01d53465878ff1f2ff411ce -github.com/docker/libcompose 81ab85ad1c6cbc4395775d9649d4d92994a2e412 https://github.com/rancher/libcompose +github.com/docker/libcompose 6d5e31da6e294b6d2922434a68e19538038f4243 https://github.com/rancher/libcompose github.com/flynn/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff github.com/gorilla/context 14f550f51a github.com/gorilla/mux e444e69cbd