Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

env emits DOCKER_HOST_IP #3057

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ .Prefix }}DOCKER_MACHINE_NAME{{ .Delimiter }}{{ .MachineName }}{{ .Suffix }}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}`
envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST_IP{{ .Delimiter }}{{ .DockerHostIP }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ .Prefix }}DOCKER_MACHINE_NAME{{ .Delimiter }}{{ .MachineName }}{{ .Suffix }}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}`
)

var (
Expand All @@ -34,6 +34,7 @@ type ShellConfig struct {
Suffix string
DockerCertPath string
DockerHost string
DockerHostIP string
DockerTLSVerify string
UsageHint string
MachineName string
Expand Down Expand Up @@ -86,6 +87,14 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) {
return nil, fmt.Errorf("Error checking TLS connection: %s", err)
}

dockerHostIP := ""
if host != nil && host.Driver != nil {
dockerHostIP, err = host.Driver.GetIP()
if err != nil {
return nil, err
}
}

userShell, err := getShell(c.String("shell"))
if err != nil {
return nil, err
Expand All @@ -94,6 +103,7 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) {
shellCfg := &ShellConfig{
DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), host.Name),
DockerHost: dockerHost,
DockerHostIP: dockerHostIP,
DockerTLSVerify: "1",
UsageHint: defaultUsageHinter.GenerateUsageHint(userShell, os.Args),
MachineName: host.Name,
Expand Down
2 changes: 2 additions & 0 deletions commands/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func TestShellCfgSet(t *testing.T) {
Suffix: "\"\n",
DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"),
DockerHost: "tcp://1.2.3.4:2376",
DockerHostIP: "1.2.3.4",
DockerTLSVerify: "1",
UsageHint: usageHint,
NoProxyVar: "NO_PROXY",
Expand Down Expand Up @@ -414,6 +415,7 @@ func TestShellCfgSet(t *testing.T) {
Suffix: "\"\n",
DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"),
DockerHost: "tcp://1.2.3.4:2376",
DockerHostIP: "1.2.3.4",
DockerTLSVerify: "1",
UsageHint: usageHint,
NoProxyVar: "no_proxy",
Expand Down