Skip to content

Instantly share code, notes, and snippets.

@tonistiigi
Created November 10, 2014 20:25
Show Gist options
  • Save tonistiigi/24f8cba92f581b4da007 to your computer and use it in GitHub Desktop.
Save tonistiigi/24f8cba92f581b4da007 to your computer and use it in GitHub Desktop.
integration-cli osx
diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go
index b9660d2..ea28942 100644
--- a/integration-cli/docker_utils.go
+++ b/integration-cli/docker_utils.go
@@ -9,6 +9,7 @@ import (
"net/http"
"net/http/httptest"
"net/http/httputil"
+ "net/url"
"os"
"os/exec"
"path"
@@ -232,9 +233,13 @@ func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
}
func sockRequest(method, endpoint string) ([]byte, error) {
- // FIX: the path to sock should not be hardcoded
- sock := filepath.Join("/", "var", "run", "docker.sock")
- c, err := net.DialTimeout("unix", sock, time.Duration(10*time.Second))
+ sock := os.Getenv("DOCKER_HOST")
+ if sock == "" {
+ sock = "unix:///var/run/docker.sock"
+ }
+ protoAddrParts := strings.SplitN(sock, "://", 2)
+
+ c, err := net.DialTimeout(protoAddrParts[0], protoAddrParts[1], time.Duration(10*time.Second))
if err != nil {
return nil, fmt.Errorf("could not dial docker sock at %s: %v", sock, err)
}
@@ -715,3 +720,15 @@ func readFile(src string, t *testing.T) (content string) {
}
return string(data)
}
+
+func cliIsLocal() bool {
+ sock := os.Getenv("DOCKER_HOST")
+ if sock == "" {
+ return true
+ }
+ parsed, err := url.Parse(sock)
+ if err != nil || parsed.Scheme == "unix" || (parsed.Host == "localhost" && parsed.Host == "127.0.0.1") {
+ return true
+ }
+ return false
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment