mirror of https://github.com/docker/compose.git
Check -H flags and DOCKER_HOST/DOCKER_CONTEXT vars when determining current context
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
29cc59cf42
commit
f1f4ca4833
36
cli/main.go
36
cli/main.go
|
@ -191,10 +191,11 @@ func main() {
|
||||||
if opts.Config == "" {
|
if opts.Config == "" {
|
||||||
fatal(errors.New("config path cannot be empty"))
|
fatal(errors.New("config path cannot be empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
configDir := opts.Config
|
configDir := opts.Config
|
||||||
ctx = config.WithDir(ctx, configDir)
|
ctx = config.WithDir(ctx, configDir)
|
||||||
|
|
||||||
currentContext := determineCurrentContext(opts.Context, configDir)
|
currentContext := determineCurrentContext(opts.Context, configDir, opts.Hosts)
|
||||||
|
|
||||||
s, err := store.New(configDir)
|
s, err := store.New(configDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -213,11 +214,6 @@ func main() {
|
||||||
volume.Command(ctype),
|
volume.Command(ctype),
|
||||||
)
|
)
|
||||||
if ctype == store.DefaultContextType || ctype == store.LocalContextType {
|
if ctype == store.DefaultContextType || ctype == store.LocalContextType {
|
||||||
if len(opts.Hosts) > 0 {
|
|
||||||
opts.Context = ""
|
|
||||||
currentContext = "default"
|
|
||||||
}
|
|
||||||
|
|
||||||
cnxOptions := cliflags.CommonOptions{
|
cnxOptions := cliflags.CommonOptions{
|
||||||
Context: opts.Context,
|
Context: opts.Context,
|
||||||
Debug: opts.Debug,
|
Debug: opts.Debug,
|
||||||
|
@ -320,15 +316,31 @@ func newSigContext() (context.Context, func()) {
|
||||||
return ctx, cancel
|
return ctx, cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
func determineCurrentContext(flag string, configDir string) string {
|
func determineCurrentContext(flag string, configDir string, hosts []string) string {
|
||||||
|
// host and context flags cannot be both set at the same time -- the local backend enforces this when resolving hostname
|
||||||
|
// -H flag disables context --> set default as current
|
||||||
|
if len(hosts) > 0 {
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
|
// DOCKER_HOST disables context --> set default as current
|
||||||
|
if _, present := os.LookupEnv("DOCKER_HOST"); present {
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
res := flag
|
res := flag
|
||||||
if res == "" {
|
if res == "" {
|
||||||
config, err := config.LoadFile(configDir)
|
// check if DOCKER_CONTEXT env variable was set
|
||||||
if err != nil {
|
if _, present := os.LookupEnv("DOCKER_CONTEXT"); present {
|
||||||
fmt.Fprintln(os.Stderr, errors.Wrap(err, "WARNING"))
|
res = os.Getenv("DOCKER_CONTEXT")
|
||||||
return "default"
|
}
|
||||||
|
|
||||||
|
if res == "" {
|
||||||
|
config, err := config.LoadFile(configDir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, errors.Wrap(err, "WARNING"))
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
|
res = config.CurrentContext
|
||||||
}
|
}
|
||||||
res = config.CurrentContext
|
|
||||||
}
|
}
|
||||||
if res == "" {
|
if res == "" {
|
||||||
res = "default"
|
res = "default"
|
||||||
|
|
Loading…
Reference in New Issue