forked from LaconicNetwork/kompose
choose separator which happens first
This commit is contained in:
parent
1fdaffe540
commit
df533a2bd7
@ -38,23 +38,36 @@ type Compose struct {
|
|||||||
// load environment variables from compose file
|
// load environment variables from compose file
|
||||||
func loadEnvVars(envars []string) []kobject.EnvVar {
|
func loadEnvVars(envars []string) []kobject.EnvVar {
|
||||||
envs := []kobject.EnvVar{}
|
envs := []kobject.EnvVar{}
|
||||||
var character string
|
|
||||||
for _, e := range envars {
|
for _, e := range envars {
|
||||||
//FIXME:(tuna) if envvar string contains both = and :, then = will be first pick up. Consider the case: URL=http://examples.com
|
character := ""
|
||||||
if strings.Contains(e, "=") {
|
equalPos := strings.Index(e, "=")
|
||||||
character = "="
|
colonPos := strings.Index(e, ":")
|
||||||
} else if strings.Contains(e, ":") {
|
switch {
|
||||||
|
case equalPos == -1 && colonPos == -1:
|
||||||
|
character = ""
|
||||||
|
case equalPos == -1 && colonPos != -1:
|
||||||
character = ":"
|
character = ":"
|
||||||
} else {
|
case equalPos != -1 && colonPos == -1:
|
||||||
logrus.Errorf("Invalid environment variable format, only : and = separators are supported")
|
character = "="
|
||||||
return []kobject.EnvVar{}
|
case equalPos != -1 && colonPos != -1:
|
||||||
|
if equalPos > colonPos {
|
||||||
|
character = ":"
|
||||||
|
} else {
|
||||||
|
character = "="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
values := strings.Split(e, character)
|
if character == "" {
|
||||||
envs = append(envs, kobject.EnvVar{
|
envs = append(envs, kobject.EnvVar{
|
||||||
Name: values[0],
|
Name: e,
|
||||||
Value: values[1],
|
})
|
||||||
})
|
} else {
|
||||||
|
values := strings.SplitN(e, character, 2)
|
||||||
|
envs = append(envs, kobject.EnvVar{
|
||||||
|
Name: values[0],
|
||||||
|
Value: values[1],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return envs
|
return envs
|
||||||
@ -176,7 +189,6 @@ func (c *Compose) LoadFile(file string) kobject.KomposeObject {
|
|||||||
serviceConfig.Command = composeServiceConfig.Entrypoint
|
serviceConfig.Command = composeServiceConfig.Entrypoint
|
||||||
serviceConfig.Args = composeServiceConfig.Command
|
serviceConfig.Args = composeServiceConfig.Command
|
||||||
|
|
||||||
//envs := loadEnvVars(composeServiceConfig.Environment.ToMap())
|
|
||||||
envs := loadEnvVars(composeServiceConfig.Environment)
|
envs := loadEnvVars(composeServiceConfig.Environment)
|
||||||
serviceConfig.Environment = envs
|
serviceConfig.Environment = envs
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user