diff --git a/pkg/app/app.go b/pkg/app/app.go index 3d4192c6b..ce0c99fc1 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -226,9 +226,9 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) { komposeObject.Namespace = opt.Namespace // Get the directory of the compose file - composeFileDir, err := transformer.GetComposeFileDir(opt.InputFiles) + workDir, err := transformer.GetComposeFileDir(opt.InputFiles) if err != nil { - log.Fatalf(err.Error()) + log.Fatalf("Unable to get compose file directory: %s", err) } // convert env_file from absolute to relative path @@ -241,7 +241,7 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) { continue } - relPath, err := filepath.Rel(composeFileDir, envFile) + relPath, err := filepath.Rel(workDir, envFile) if err != nil { log.Fatalf(err.Error()) } diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 5e1a35203..bccc6c811 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -220,7 +220,10 @@ 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 { - workDir := filepath.Dir(opt.InputFiles[0]) + workDir, err := transformer.GetComposeFileDir(opt.InputFiles) + if err != nil { + log.Fatalf("Unable to get compose file directory: %s", err) + } envs, err := GetEnvsFromFile(filepath.Join(workDir, envFile)) if err != nil { log.Fatalf("Unable to retrieve env file: %s", err) @@ -1104,7 +1107,10 @@ func ConfigEnvs(service kobject.ServiceConfig, opt kobject.ConvertOptions) ([]ap envName := FormatEnvName(file) // Load environment variables from file - workDir := filepath.Dir(opt.InputFiles[0]) + workDir, err := transformer.GetComposeFileDir(opt.InputFiles) + if err != nil { + log.Fatalf("Unable to get compose file directory: %s", err) + } envLoad, err := GetEnvsFromFile(filepath.Join(workDir, file)) if err != nil { return envs, errors.Wrap(err, "Unable to read env_file")