forked from LaconicNetwork/kompose
fix load environment function, not using UnmarshalYAML
This commit is contained in:
parent
f800f542f8
commit
b72980fade
@ -543,40 +543,15 @@ func loadEnvVars(service bundlefile.Service) ([]EnvVar, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load Environment Variable from compose file
|
// load Environment Variable from compose file
|
||||||
func loadEnvVarsFromCompose(e []string) ([]EnvVar, string) {
|
func loadEnvVarsFromCompose(e map[string]string) ([]EnvVar) {
|
||||||
envs := []EnvVar{}
|
envs := []EnvVar{}
|
||||||
for _, env := range e {
|
for k, v := range e {
|
||||||
character := "="
|
envs = append(envs, EnvVar{
|
||||||
if strings.Contains(env, character) {
|
Name: k,
|
||||||
value := env[strings.Index(env, character)+1:]
|
Value: v,
|
||||||
name := env[0:strings.Index(env, character)]
|
})
|
||||||
name = strings.TrimSpace(name)
|
|
||||||
value = strings.TrimSpace(value)
|
|
||||||
envs = append(envs, EnvVar{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
character = ":"
|
|
||||||
if strings.Contains(env, character) {
|
|
||||||
charQuote := "'"
|
|
||||||
value := env[strings.Index(env, character)+1:]
|
|
||||||
name := env[0:strings.Index(env, character)]
|
|
||||||
name = strings.TrimSpace(name)
|
|
||||||
value = strings.TrimSpace(value)
|
|
||||||
if strings.Contains(value, charQuote) {
|
|
||||||
value = strings.Trim(value, "'")
|
|
||||||
}
|
|
||||||
envs = append(envs, EnvVar{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return envs, "Invalid container env " + env
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return envs, ""
|
return envs
|
||||||
}
|
}
|
||||||
|
|
||||||
// load Ports from bundles file
|
// load Ports from bundles file
|
||||||
@ -725,16 +700,7 @@ func loadComposeFile(file string, c *cli.Context) KomposeObject {
|
|||||||
serviceConfig.ContainerName = composeServiceConfig.ContainerName
|
serviceConfig.ContainerName = composeServiceConfig.ContainerName
|
||||||
|
|
||||||
// load environment variables
|
// load environment variables
|
||||||
environments := composeServiceConfig.Environment
|
envs := loadEnvVarsFromCompose(composeServiceConfig.Environment.ToMap())
|
||||||
if environments != nil {
|
|
||||||
if err := environments.UnmarshalYAML("", environments); err != nil {
|
|
||||||
logrus.Fatalf("Failed to load envvar from compose file: ", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
envs, err := loadEnvVarsFromCompose(environments)
|
|
||||||
if err != "" {
|
|
||||||
logrus.Fatalf("Failed to load envvar from compose file: " + err)
|
|
||||||
}
|
|
||||||
serviceConfig.Environment = envs
|
serviceConfig.Environment = envs
|
||||||
|
|
||||||
// load ports
|
// load ports
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user