github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/integration-cli/cli/build/fakestorage/fixtures.go (about) 1 package fakestorage 2 3 import ( 4 "io/ioutil" 5 "os" 6 "os/exec" 7 "path/filepath" 8 "sync" 9 10 "github.com/docker/docker/integration-cli/cli" 11 ) 12 13 var ensureHTTPServerOnce sync.Once 14 15 func ensureHTTPServerImage(t testingT) { 16 var doIt bool 17 ensureHTTPServerOnce.Do(func() { 18 doIt = true 19 }) 20 21 if !doIt { 22 return 23 } 24 25 defer testEnv.ProtectImage(t, "httpserver:latest") 26 27 tmp, err := ioutil.TempDir("", "docker-http-server-test") 28 if err != nil { 29 t.Fatalf("could not build http server: %v", err) 30 } 31 defer os.RemoveAll(tmp) 32 33 goos := testEnv.DaemonPlatform() 34 if goos == "" { 35 goos = "linux" 36 } 37 goarch := os.Getenv("DOCKER_ENGINE_GOARCH") 38 if goarch == "" { 39 goarch = "amd64" 40 } 41 42 goCmd, lookErr := exec.LookPath("go") 43 if lookErr != nil { 44 t.Fatalf("could not build http server: %v", lookErr) 45 } 46 47 cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver") 48 cmd.Env = append(os.Environ(), []string{ 49 "CGO_ENABLED=0", 50 "GOOS=" + goos, 51 "GOARCH=" + goarch, 52 }...) 53 var out []byte 54 if out, err = cmd.CombinedOutput(); err != nil { 55 t.Fatalf("could not build http server: %s", string(out)) 56 } 57 58 cpCmd, lookErr := exec.LookPath("cp") 59 if lookErr != nil { 60 t.Fatalf("could not build http server: %v", lookErr) 61 } 62 if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil { 63 t.Fatalf("could not build http server: %v", string(out)) 64 } 65 66 cli.DockerCmd(t, "build", "-q", "-t", "httpserver", tmp) 67 }