Skip to content

Commit

Permalink
use fixed GetComposeFileDir instead of filepath.Dir
Browse files Browse the repository at this point in the history
  • Loading branch information
realgam3 committed Dec 16, 2023
1 parent a5b5049 commit 677b91a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 677b91a

Please sign in to comment.