Skip to content

Commit

Permalink
fix: update loading 'env_file' of docker_compose
Browse files Browse the repository at this point in the history
Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
  • Loading branch information
TessaIO committed Jul 23, 2023
1 parent 2150982 commit f2ac606
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 584 deletions.
11 changes: 2 additions & 9 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,16 +824,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")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions script/test/cmd/tests_new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,5 @@ convert::expect_success "$os_cmd" "$os_output"
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/custom-build-push/docker-compose.yaml convert --build-command 'docker build -t ahmedgrati/kompose-test ./script/test/fixtures/custom-build-push' --push-command 'docker push ahmedgrati/kompose-test' --stdout --with-kompose-annotation=false"
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/custom-build-push/output-k8s.yaml"
convert::expect_success "$os_cmd" "$os_output"

# Test env_file support
246 changes: 0 additions & 246 deletions script/test/fixtures/env/output-k8s.json

This file was deleted.

Loading

0 comments on commit f2ac606

Please sign in to comment.