mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix environment resolving.
Load from env should only happen if the value is unset. Extract a buildEnvironment function and revert some changes to tests. Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
ea43c33330
commit
a9c86b63c0
9 changed files with 147 additions and 118 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
composetypes "github.com/docker/docker/cli/compose/types"
|
||||
apiclient "github.com/docker/docker/client"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -115,17 +116,24 @@ func getConfigDetails(opts deployOptions) (composetypes.ConfigDetails, error) {
|
|||
}
|
||||
// TODO: support multiple files
|
||||
details.ConfigFiles = []composetypes.ConfigFile{*configFile}
|
||||
env := os.Environ()
|
||||
details.Environment = make(map[string]string, len(env))
|
||||
details.Environment, err = buildEnvironment(os.Environ())
|
||||
if err != nil {
|
||||
return details, err
|
||||
}
|
||||
return details, nil
|
||||
}
|
||||
|
||||
func buildEnvironment(env []string) (map[string]string, error) {
|
||||
result := make(map[string]string, len(env))
|
||||
for _, s := range env {
|
||||
// if value is empty, s is like "K=", not "K".
|
||||
if !strings.Contains(s, "=") {
|
||||
return details, fmt.Errorf("unexpected environment %q", s)
|
||||
return result, errors.Errorf("unexpected environment %q", s)
|
||||
}
|
||||
kv := strings.SplitN(s, "=", 2)
|
||||
details.Environment[kv[0]] = kv[1]
|
||||
result[kv[0]] = kv[1]
|
||||
}
|
||||
return details, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getConfigFile(filename string) (*composetypes.ConfigFile, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue