Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit c92c70e

Browse files
authored
Merge pull request #307 from dtan4/multiple-env-type
Load multiple type of env_file and environments
2 parents a12288b + dbcfbf6 commit c92c70e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

config/merge.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
yaml "github.com/cloudfoundry-incubator/candiedyaml"
1010
"github.com/docker/docker/pkg/urlutil"
11+
"github.com/docker/libcompose/utils"
12+
composeYaml "github.com/docker/libcompose/yaml"
1113
)
1214

1315
var (
@@ -86,7 +88,13 @@ func readEnvFile(resourceLookup ResourceLookup, inFile string, serviceData RawSe
8688
if _, ok := serviceData["env_file"]; !ok {
8789
return serviceData, nil
8890
}
89-
envFiles := serviceData["env_file"].([]interface{})
91+
92+
var envFiles composeYaml.Stringorslice
93+
94+
if err := utils.Convert(serviceData["env_file"], &envFiles); err != nil {
95+
return nil, err
96+
}
97+
9098
if len(envFiles) == 0 {
9199
return serviceData, nil
92100
}
@@ -95,13 +103,16 @@ func readEnvFile(resourceLookup ResourceLookup, inFile string, serviceData RawSe
95103
return nil, fmt.Errorf("Can not use env_file in file %s no mechanism provided to load files", inFile)
96104
}
97105

98-
var vars []interface{}
106+
var vars composeYaml.MaporEqualSlice
107+
99108
if _, ok := serviceData["environment"]; ok {
100-
vars = serviceData["environment"].([]interface{})
109+
if err := utils.Convert(serviceData["environment"], &vars); err != nil {
110+
return nil, err
111+
}
101112
}
102113

103114
for i := len(envFiles) - 1; i >= 0; i-- {
104-
envFile := envFiles[i].(string)
115+
envFile := envFiles[i]
105116
content, _, err := resourceLookup.Lookup(envFile, inFile)
106117
if err != nil {
107118
return nil, err
@@ -118,7 +129,7 @@ func readEnvFile(resourceLookup ResourceLookup, inFile string, serviceData RawSe
118129

119130
found := false
120131
for _, v := range vars {
121-
if strings.HasPrefix(v.(string), key) {
132+
if strings.HasPrefix(v, key) {
122133
found = true
123134
break
124135
}

0 commit comments

Comments
 (0)