github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+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 "testing" 12 13 "github.com/docker/docker/testutil/fixtures/load" 14 "gotest.tools/v3/assert" 15 ) 16 17 func ensureSyscallTest(c *testing.T) { 18 defer testEnv.ProtectImage(c, "syscall-test:latest") 19 20 // If the image already exists, there's nothing left to do. 21 if testEnv.HasExistingImage(c, "syscall-test:latest") { 22 return 23 } 24 25 // if no match, must build in docker, which is significantly slower 26 // (slower mostly because of the vfs graphdriver) 27 if testEnv.OSType != runtime.GOOS { 28 ensureSyscallTestBuild(c) 29 return 30 } 31 32 tmp, err := ioutil.TempDir("", "syscall-test-build") 33 assert.NilError(c, err, "couldn't create temp dir") 34 defer os.RemoveAll(tmp) 35 36 gcc, err := exec.LookPath("gcc") 37 assert.NilError(c, err, "could not find gcc") 38 39 tests := []string{"userns", "ns", "acct", "setuid", "setgid", "socket", "raw"} 40 for _, test := range tests { 41 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() 42 assert.NilError(c, err, string(out)) 43 } 44 45 if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" { 46 out, err := exec.Command(gcc, "-s", "-m32", "-nostdlib", "-static", "../contrib/syscall-test/exit32.s", "-o", tmp+"/"+"exit32-test").CombinedOutput() 47 assert.NilError(c, err, string(out)) 48 } 49 50 dockerFile := filepath.Join(tmp, "Dockerfile") 51 content := []byte(` 52 FROM debian:jessie 53 COPY . /usr/bin/ 54 `) 55 err = ioutil.WriteFile(dockerFile, content, 0600) 56 assert.NilError(c, err) 57 58 var buildArgs []string 59 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 60 buildArgs = strings.Split(arg, " ") 61 } 62 buildArgs = append(buildArgs, []string{"-q", "-t", "syscall-test", tmp}...) 63 buildArgs = append([]string{"build"}, buildArgs...) 64 dockerCmd(c, buildArgs...) 65 } 66 67 func ensureSyscallTestBuild(c *testing.T) { 68 err := load.FrozenImagesLinux(testEnv.APIClient(), "buildpack-deps:jessie") 69 assert.NilError(c, err) 70 71 var buildArgs []string 72 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 73 buildArgs = strings.Split(arg, " ") 74 } 75 buildArgs = append(buildArgs, []string{"-q", "-t", "syscall-test", "../contrib/syscall-test"}...) 76 buildArgs = append([]string{"build"}, buildArgs...) 77 dockerCmd(c, buildArgs...) 78 } 79 80 func ensureNNPTest(c *testing.T) { 81 defer testEnv.ProtectImage(c, "nnp-test:latest") 82 83 // If the image already exists, there's nothing left to do. 84 if testEnv.HasExistingImage(c, "nnp-test:latest") { 85 return 86 } 87 88 // if no match, must build in docker, which is significantly slower 89 // (slower mostly because of the vfs graphdriver) 90 if testEnv.OSType != runtime.GOOS { 91 ensureNNPTestBuild(c) 92 return 93 } 94 95 tmp, err := ioutil.TempDir("", "docker-nnp-test") 96 assert.NilError(c, err) 97 98 gcc, err := exec.LookPath("gcc") 99 assert.NilError(c, err, "could not find gcc") 100 101 out, err := exec.Command(gcc, "-g", "-Wall", "-static", "../contrib/nnp-test/nnp-test.c", "-o", filepath.Join(tmp, "nnp-test")).CombinedOutput() 102 assert.NilError(c, err, string(out)) 103 104 dockerfile := filepath.Join(tmp, "Dockerfile") 105 content := ` 106 FROM debian:jessie 107 COPY . /usr/bin 108 RUN chmod +s /usr/bin/nnp-test 109 ` 110 err = ioutil.WriteFile(dockerfile, []byte(content), 0600) 111 assert.NilError(c, err, "could not write Dockerfile for nnp-test image") 112 113 var buildArgs []string 114 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 115 buildArgs = strings.Split(arg, " ") 116 } 117 buildArgs = append(buildArgs, []string{"-q", "-t", "nnp-test", tmp}...) 118 buildArgs = append([]string{"build"}, buildArgs...) 119 dockerCmd(c, buildArgs...) 120 } 121 122 func ensureNNPTestBuild(c *testing.T) { 123 err := load.FrozenImagesLinux(testEnv.APIClient(), "buildpack-deps:jessie") 124 assert.NilError(c, err) 125 126 var buildArgs []string 127 if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { 128 buildArgs = strings.Split(arg, " ") 129 } 130 buildArgs = append(buildArgs, []string{"-q", "-t", "npp-test", "../contrib/nnp-test"}...) 131 buildArgs = append([]string{"build"}, buildArgs...) 132 dockerCmd(c, buildArgs...) 133 }