github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/integration-cli/fixtures_linux_daemon_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "os/exec" 8 "path/filepath" 9 "runtime" 10 "strings" 11 "sync" 12 13 "github.com/docker/docker/integration-cli/checker" 14 "github.com/docker/docker/integration-cli/fixtures/load" 15 "github.com/go-check/check" 16 ) 17 18 type testingT interface { 19 logT 20 Fatalf(string, ...interface{}) 21 } 22 23 type logT interface { 24 Logf(string, ...interface{}) 25 } 26 27 var ensureSyscallTestOnce sync.Once 28 29 func ensureSyscallTest(c *check.C) { 30 var doIt bool 31 ensureSyscallTestOnce.Do(func() { 32 doIt = true 33 }) 34 if !doIt { 35 return 36 } 37 defer testEnv.ProtectImage(c, "syscall-test:latest") 38 39 // if no match, must build in docker, which is significantly slower 40 // (slower mostly because of the vfs graphdriver) 41 if testEnv.DaemonPlatform() != runtime.GOOS { 42 ensureSyscallTestBuild(c) 43 return 44 } 45 46 tmp, err := ioutil.TempDir("", "syscall-test-build") 47 c.Assert(err, checker.IsNil, check.Commentf("couldn't create temp dir")) 48 defer os.RemoveAll(tmp) 49 50 gcc, err := exec.LookPath("gcc") 51 c.Assert(err, checker.IsNil, check.Commentf("could not find gcc")) 52 53 tests := []string{"userns", "ns", "acct", "setuid", "setgid", "socket", "raw"} 54 for _, test := range tests { 55 out, err := exec.Command(gcc, "-g", "-Wall", "-static", fmt.Sprintf("../contrib/syscall-test/%s.c", test), "-o", fmt.Sprintf("%s/%s-test", tmp, test)).CombinedOutput() 56 c.Assert(err, checker.IsNil, check.Commentf(string(out))) 57 } 58 59 if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" { 60 out, err := exec.Command(gcc, "-s", "-m32", "-nostdlib", "-static", "../contrib/syscall-test/exit32.s", "-o", tmp+"/"+"exit32-test").CombinedOutput() 61 c.Assert(err, checker.IsNil, check.Commentf(string(out))) 62 } 63 64 dockerFile := filepath.Join(tmp, "Dockerfile") 65 content := []byte(` 66 FROM debian:jessie 67 COPY . /usr/bin/ 68 `) 69 err = ioutil.WriteFile(dockerFile, content, 600) 70 c.Assert(err, checker.IsNil) 71 72 var buildArgs []string 73 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 74 buildArgs = strings.Split(arg, " ") 75 } 76 buildArgs = append(buildArgs, []string{"-q", "-t", "syscall-test", tmp}...) 77 buildArgs = append([]string{"build"}, buildArgs...) 78 dockerCmd(c, buildArgs...) 79 } 80 81 func ensureSyscallTestBuild(c *check.C) { 82 err := load.FrozenImagesLinux(testEnv.APIClient(), "buildpack-deps:jessie") 83 c.Assert(err, checker.IsNil) 84 85 var buildArgs []string 86 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 87 buildArgs = strings.Split(arg, " ") 88 } 89 buildArgs = append(buildArgs, []string{"-q", "-t", "syscall-test", "../contrib/syscall-test"}...) 90 buildArgs = append([]string{"build"}, buildArgs...) 91 dockerCmd(c, buildArgs...) 92 } 93 94 func ensureNNPTest(c *check.C) { 95 defer testEnv.ProtectImage(c, "nnp-test:latest") 96 if testEnv.DaemonPlatform() != runtime.GOOS { 97 ensureNNPTestBuild(c) 98 return 99 } 100 101 tmp, err := ioutil.TempDir("", "docker-nnp-test") 102 c.Assert(err, checker.IsNil) 103 104 gcc, err := exec.LookPath("gcc") 105 c.Assert(err, checker.IsNil, check.Commentf("could not find gcc")) 106 107 out, err := exec.Command(gcc, "-g", "-Wall", "-static", "../contrib/nnp-test/nnp-test.c", "-o", filepath.Join(tmp, "nnp-test")).CombinedOutput() 108 c.Assert(err, checker.IsNil, check.Commentf(string(out))) 109 110 dockerfile := filepath.Join(tmp, "Dockerfile") 111 content := ` 112 FROM debian:jessie 113 COPY . /usr/bin 114 RUN chmod +s /usr/bin/nnp-test 115 ` 116 err = ioutil.WriteFile(dockerfile, []byte(content), 600) 117 c.Assert(err, checker.IsNil, check.Commentf("could not write Dockerfile for nnp-test image")) 118 119 var buildArgs []string 120 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 121 buildArgs = strings.Split(arg, " ") 122 } 123 buildArgs = append(buildArgs, []string{"-q", "-t", "nnp-test", tmp}...) 124 buildArgs = append([]string{"build"}, buildArgs...) 125 dockerCmd(c, buildArgs...) 126 } 127 128 func ensureNNPTestBuild(c *check.C) { 129 err := load.FrozenImagesLinux(testEnv.APIClient(), "buildpack-deps:jessie") 130 c.Assert(err, checker.IsNil) 131 132 var buildArgs []string 133 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 134 buildArgs = strings.Split(arg, " ") 135 } 136 buildArgs = append(buildArgs, []string{"-q", "-t", "npp-test", "../contrib/nnp-test"}...) 137 buildArgs = append([]string{"build"}, buildArgs...) 138 dockerCmd(c, buildArgs...) 139 }