2016-08-31 15:31:06 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ensureHTTPServerOnce sync.Once
|
|
|
|
|
2017-03-01 12:45:04 -05:00
|
|
|
func ensureHTTPServerImage(t testingT) {
|
2016-08-31 15:31:06 -04:00
|
|
|
var doIt bool
|
|
|
|
ensureHTTPServerOnce.Do(func() {
|
|
|
|
doIt = true
|
|
|
|
})
|
|
|
|
|
|
|
|
if !doIt {
|
2017-03-01 12:45:04 -05:00
|
|
|
return
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
|
2017-03-01 12:45:04 -05:00
|
|
|
defer testEnv.ProtectImage(t, "httpserver:latest")
|
2016-08-31 15:31:06 -04:00
|
|
|
|
|
|
|
tmp, err := ioutil.TempDir("", "docker-http-server-test")
|
|
|
|
if err != nil {
|
2017-03-01 12:45:04 -05:00
|
|
|
t.Fatalf("could not build http server: %v", err)
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmp)
|
|
|
|
|
2017-01-13 11:23:28 -05:00
|
|
|
goos := testEnv.DaemonPlatform()
|
2016-08-31 15:31:06 -04:00
|
|
|
if goos == "" {
|
|
|
|
goos = "linux"
|
|
|
|
}
|
|
|
|
goarch := os.Getenv("DOCKER_ENGINE_GOARCH")
|
|
|
|
if goarch == "" {
|
|
|
|
goarch = "amd64"
|
|
|
|
}
|
|
|
|
|
|
|
|
goCmd, lookErr := exec.LookPath("go")
|
|
|
|
if lookErr != nil {
|
2017-03-01 12:45:04 -05:00
|
|
|
t.Fatalf("could not build http server: %v", lookErr)
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver")
|
|
|
|
cmd.Env = append(os.Environ(), []string{
|
|
|
|
"CGO_ENABLED=0",
|
|
|
|
"GOOS=" + goos,
|
|
|
|
"GOARCH=" + goarch,
|
|
|
|
}...)
|
|
|
|
var out []byte
|
|
|
|
if out, err = cmd.CombinedOutput(); err != nil {
|
2017-03-01 12:45:04 -05:00
|
|
|
t.Fatalf("could not build http server: %s", string(out))
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cpCmd, lookErr := exec.LookPath("cp")
|
|
|
|
if lookErr != nil {
|
2017-03-01 12:45:04 -05:00
|
|
|
t.Fatalf("could not build http server: %v", lookErr)
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil {
|
2017-03-01 12:45:04 -05:00
|
|
|
t.Fatalf("could not build http server: %v", string(out))
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if out, err = exec.Command(dockerBinary, "build", "-q", "-t", "httpserver", tmp).CombinedOutput(); err != nil {
|
2017-03-01 12:45:04 -05:00
|
|
|
t.Fatalf("could not build http server: %v", string(out))
|
2016-08-31 15:31:06 -04:00
|
|
|
}
|
|
|
|
}
|