Fix loading env file (#1679)
* fix: update loading 'env_file' of docker_compose Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com> * test: add functional tests for loading env_file Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com> --------- Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
@@ -829,16 +829,9 @@ func DurationStrToSecondsInt(s string) (*int64, error) {
|
||||
}
|
||||
|
||||
// GetEnvsFromFile get env vars from env_file
|
||||
func GetEnvsFromFile(file string, opt kobject.ConvertOptions) (map[string]string, error) {
|
||||
// Get the correct file context / directory
|
||||
composeDir, err := transformer.GetComposeFileDir(opt.InputFiles)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Unable to load file context")
|
||||
}
|
||||
fileLocation := path.Join(composeDir, file)
|
||||
func GetEnvsFromFile(file string) (map[string]string, error) {
|
||||
|
||||
// Load environment variables from file
|
||||
envLoad, err := godotenv.Read(fileLocation)
|
||||
envLoad, err := godotenv.Read(file)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Unable to read env_file")
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Se
|
||||
|
||||
// InitConfigMapForEnv initializes a ConfigMap object
|
||||
func (k *Kubernetes) InitConfigMapForEnv(name string, opt kobject.ConvertOptions, envFile string) *api.ConfigMap {
|
||||
envs, err := GetEnvsFromFile(envFile, opt)
|
||||
envs, err := GetEnvsFromFile(envFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to retrieve env file: %s", err)
|
||||
}
|
||||
@@ -1099,12 +1099,11 @@ func ConfigEnvs(service kobject.ServiceConfig, opt kobject.ConvertOptions) ([]ap
|
||||
|
||||
if len(service.EnvFile) > 0 {
|
||||
// Load each env_file
|
||||
|
||||
for _, file := range service.EnvFile {
|
||||
envName := FormatEnvName(file)
|
||||
|
||||
// Load environment variables from file
|
||||
envLoad, err := GetEnvsFromFile(file, opt)
|
||||
envLoad, err := GetEnvsFromFile(file)
|
||||
if err != nil {
|
||||
return envs, errors.Wrap(err, "Unable to read env_file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user