fixtures.go 1.5 KB

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