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