github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/build_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 "runtime" 9 "strings" 10 11 "github.com/containers/buildah" 12 . "github.com/containers/podman/v3/test/utils" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gexec" 16 ) 17 18 var _ = Describe("Podman build", func() { 19 var ( 20 tempdir string 21 err error 22 podmanTest *PodmanTestIntegration 23 ) 24 25 BeforeEach(func() { 26 tempdir, err = CreateTempDirInTempDir() 27 if err != nil { 28 os.Exit(1) 29 } 30 podmanTest = PodmanTestCreate(tempdir) 31 podmanTest.Setup() 32 }) 33 34 AfterEach(func() { 35 podmanTest.Cleanup() 36 f := CurrentGinkgoTestDescription() 37 processTestResult(f) 38 }) 39 40 // Let's first do the most simple build possible to make sure stuff is 41 // happy and then clean up after ourselves to make sure that works too. 42 It("podman build and remove basic alpine", func() { 43 podmanTest.AddImageToRWStore(ALPINE) 44 session := podmanTest.Podman([]string{"build", "--pull-never", "build/basicalpine"}) 45 session.WaitWithDefaultTimeout() 46 Expect(session).Should(Exit(0)) 47 48 iid := session.OutputToStringArray()[len(session.OutputToStringArray())-1] 49 50 // Verify that OS and Arch are being set 51 inspect := podmanTest.Podman([]string{"inspect", iid}) 52 inspect.WaitWithDefaultTimeout() 53 data := inspect.InspectImageJSON() 54 Expect(data[0].Os).To(Equal(runtime.GOOS)) 55 Expect(data[0].Architecture).To(Equal(runtime.GOARCH)) 56 57 session = podmanTest.Podman([]string{"rmi", ALPINE}) 58 session.WaitWithDefaultTimeout() 59 Expect(session).Should(Exit(0)) 60 }) 61 62 It("podman build with logfile", func() { 63 logfile := filepath.Join(podmanTest.TempDir, "logfile") 64 session := podmanTest.Podman([]string{"build", "--pull-never", "--tag", "test", "--logfile", logfile, "build/basicalpine"}) 65 session.WaitWithDefaultTimeout() 66 Expect(session).Should(Exit(0)) 67 68 // Verify that OS and Arch are being set 69 inspect := podmanTest.Podman([]string{"inspect", "test"}) 70 inspect.WaitWithDefaultTimeout() 71 data := inspect.InspectImageJSON() 72 Expect(data[0].Os).To(Equal(runtime.GOOS)) 73 Expect(data[0].Architecture).To(Equal(runtime.GOARCH)) 74 75 st, err := os.Stat(logfile) 76 Expect(err).To(BeNil()) 77 Expect(st.Size()).To(Not(Equal(int64(0)))) 78 79 session = podmanTest.Podman([]string{"rmi", "test"}) 80 session.WaitWithDefaultTimeout() 81 Expect(session).Should(Exit(0)) 82 }) 83 84 // If the context directory is pointing at a file and not a directory, 85 // that's a no no, fail out. 86 It("podman build context directory a file", func() { 87 session := podmanTest.Podman([]string{"build", "--pull-never", "build/context_dir_a_file"}) 88 session.WaitWithDefaultTimeout() 89 Expect(session).Should(Exit(125)) 90 }) 91 92 // Check that builds with different values for the squash options 93 // create the appropriate number of layers, then clean up after. 94 It("podman build basic alpine with squash", func() { 95 session := podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-a", "-t", "test-squash-a:latest", "build/squash"}) 96 session.WaitWithDefaultTimeout() 97 Expect(session).Should(Exit(0)) 98 99 session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-a"}) 100 session.WaitWithDefaultTimeout() 101 Expect(session).Should(Exit(0)) 102 // Check for two layers 103 Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2)) 104 105 session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-b", "--squash", "-t", "test-squash-b:latest", "build/squash"}) 106 session.WaitWithDefaultTimeout() 107 Expect(session).Should(Exit(0)) 108 109 session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-b"}) 110 session.WaitWithDefaultTimeout() 111 Expect(session).Should(Exit(0)) 112 // Check for three layers 113 Expect(len(strings.Fields(session.OutputToString()))).To(Equal(3)) 114 115 session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-c", "--squash", "-t", "test-squash-c:latest", "build/squash"}) 116 session.WaitWithDefaultTimeout() 117 Expect(session).Should(Exit(0)) 118 119 session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-c"}) 120 session.WaitWithDefaultTimeout() 121 Expect(session).Should(Exit(0)) 122 // Check for two layers 123 Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2)) 124 125 session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-c", "--squash-all", "-t", "test-squash-d:latest", "build/squash"}) 126 session.WaitWithDefaultTimeout() 127 Expect(session).Should(Exit(0)) 128 129 session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-d"}) 130 session.WaitWithDefaultTimeout() 131 Expect(session).Should(Exit(0)) 132 // Check for one layers 133 Expect(len(strings.Fields(session.OutputToString()))).To(Equal(1)) 134 135 session = podmanTest.Podman([]string{"rm", "-a"}) 136 session.WaitWithDefaultTimeout() 137 Expect(session).Should(Exit(0)) 138 }) 139 140 It("podman build Containerfile locations", func() { 141 // Given 142 // Switch to temp dir and restore it afterwards 143 cwd, err := os.Getwd() 144 Expect(err).To(BeNil()) 145 Expect(os.Chdir(os.TempDir())).To(BeNil()) 146 defer Expect(os.Chdir(cwd)).To(BeNil()) 147 148 // Write target and fake files 149 targetPath, err := CreateTempDirInTempDir() 150 if err != nil { 151 os.Exit(1) 152 } 153 154 fakeFile := filepath.Join(os.TempDir(), "Containerfile") 155 Expect(ioutil.WriteFile(fakeFile, []byte(fmt.Sprintf("FROM %s", ALPINE)), 0755)).To(BeNil()) 156 157 targetFile := filepath.Join(targetPath, "Containerfile") 158 Expect(ioutil.WriteFile(targetFile, []byte("FROM scratch"), 0755)).To(BeNil()) 159 160 defer func() { 161 Expect(os.RemoveAll(fakeFile)).To(BeNil()) 162 Expect(os.RemoveAll(targetFile)).To(BeNil()) 163 }() 164 165 // When 166 session := podmanTest.Podman([]string{ 167 "build", "--pull-never", "-f", targetFile, "-t", "test-locations", 168 }) 169 session.WaitWithDefaultTimeout() 170 171 // Then 172 Expect(session).Should(Exit(0)) 173 Expect(strings.Fields(session.OutputToString())). 174 To(ContainElement("scratch")) 175 }) 176 177 It("podman build basic alpine and print id to external file", func() { 178 // Switch to temp dir and restore it afterwards 179 cwd, err := os.Getwd() 180 Expect(err).To(BeNil()) 181 Expect(os.Chdir(os.TempDir())).To(BeNil()) 182 defer Expect(os.Chdir(cwd)).To(BeNil()) 183 184 targetPath, err := CreateTempDirInTempDir() 185 if err != nil { 186 os.Exit(1) 187 } 188 targetFile := filepath.Join(targetPath, "idFile") 189 190 session := podmanTest.Podman([]string{"build", "--pull-never", "build/basicalpine", "--iidfile", targetFile}) 191 session.WaitWithDefaultTimeout() 192 Expect(session).Should(Exit(0)) 193 id, _ := ioutil.ReadFile(targetFile) 194 195 // Verify that id is correct 196 inspect := podmanTest.Podman([]string{"inspect", string(id)}) 197 inspect.WaitWithDefaultTimeout() 198 data := inspect.InspectImageJSON() 199 Expect("sha256:" + data[0].ID).To(Equal(string(id))) 200 }) 201 202 It("podman Test PATH in built image", func() { 203 path := "/tmp:/bin:/usr/bin:/usr/sbin" 204 session := podmanTest.Podman([]string{ 205 "build", "--pull-never", "-f", "build/basicalpine/Containerfile.path", "-t", "test-path", 206 }) 207 session.WaitWithDefaultTimeout() 208 Expect(session).Should(Exit(0)) 209 210 session = podmanTest.Podman([]string{"run", "test-path", "printenv", "PATH"}) 211 session.WaitWithDefaultTimeout() 212 Expect(session).Should(Exit(0)) 213 stdoutLines := session.OutputToStringArray() 214 Expect(stdoutLines[0]).Should(Equal(path)) 215 }) 216 217 It("podman build --http_proxy flag", func() { 218 os.Setenv("http_proxy", "1.2.3.4") 219 if IsRemote() { 220 podmanTest.StopRemoteService() 221 podmanTest.StartRemoteService() 222 } 223 podmanTest.AddImageToRWStore(ALPINE) 224 dockerfile := fmt.Sprintf(`FROM %s 225 RUN printenv http_proxy`, ALPINE) 226 227 dockerfilePath := filepath.Join(podmanTest.TempDir, "Dockerfile") 228 err := ioutil.WriteFile(dockerfilePath, []byte(dockerfile), 0755) 229 Expect(err).To(BeNil()) 230 session := podmanTest.Podman([]string{"build", "--pull-never", "--http-proxy", "--file", dockerfilePath, podmanTest.TempDir}) 231 session.Wait(120) 232 Expect(session).Should(Exit(0)) 233 ok, _ := session.GrepString("1.2.3.4") 234 Expect(ok).To(BeTrue()) 235 os.Unsetenv("http_proxy") 236 }) 237 238 It("podman build and check identity", func() { 239 session := podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/basicalpine/Containerfile.path", "--no-cache", "-t", "test", "build/basicalpine"}) 240 session.WaitWithDefaultTimeout() 241 Expect(session).Should(Exit(0)) 242 243 // Verify that OS and Arch are being set 244 inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ index .Config.Labels }}", "test"}) 245 inspect.WaitWithDefaultTimeout() 246 data := inspect.OutputToString() 247 Expect(data).To(ContainSubstring(buildah.Version)) 248 }) 249 250 It("podman remote test container/docker file is not inside context dir", func() { 251 // Given 252 // Switch to temp dir and restore it afterwards 253 cwd, err := os.Getwd() 254 Expect(err).To(BeNil()) 255 256 podmanTest.AddImageToRWStore(ALPINE) 257 258 // Write target and fake files 259 targetPath, err := CreateTempDirInTempDir() 260 Expect(err).To(BeNil()) 261 targetSubPath := filepath.Join(targetPath, "subdir") 262 err = os.Mkdir(targetSubPath, 0755) 263 Expect(err).To(BeNil()) 264 dummyFile := filepath.Join(targetSubPath, "dummy") 265 err = ioutil.WriteFile(dummyFile, []byte("dummy"), 0644) 266 Expect(err).To(BeNil()) 267 268 containerfile := fmt.Sprintf(`FROM %s 269 ADD . /test 270 RUN find /test`, ALPINE) 271 272 containerfilePath := filepath.Join(targetPath, "Containerfile") 273 err = ioutil.WriteFile(containerfilePath, []byte(containerfile), 0644) 274 Expect(err).To(BeNil()) 275 276 defer func() { 277 Expect(os.Chdir(cwd)).To(BeNil()) 278 Expect(os.RemoveAll(targetPath)).To(BeNil()) 279 }() 280 281 // make cwd as context root path 282 Expect(os.Chdir(targetPath)).To(BeNil()) 283 284 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "Containerfile", targetSubPath}) 285 session.WaitWithDefaultTimeout() 286 Expect(session).Should(Exit(0)) 287 ok, _ := session.GrepString("/test/dummy") 288 Expect(ok).To(BeTrue()) 289 }) 290 291 It("podman remote test container/docker file is not at root of context dir", func() { 292 if IsRemote() { 293 podmanTest.StopRemoteService() 294 podmanTest.StartRemoteService() 295 } else { 296 Skip("Only valid at remote test") 297 } 298 // Given 299 // Switch to temp dir and restore it afterwards 300 cwd, err := os.Getwd() 301 Expect(err).To(BeNil()) 302 303 podmanTest.AddImageToRWStore(ALPINE) 304 305 // Write target and fake files 306 targetPath, err := CreateTempDirInTempDir() 307 Expect(err).To(BeNil()) 308 targetSubPath := filepath.Join(targetPath, "subdir") 309 err = os.Mkdir(targetSubPath, 0755) 310 Expect(err).To(BeNil()) 311 312 containerfile := fmt.Sprintf("FROM %s", ALPINE) 313 314 containerfilePath := filepath.Join(targetSubPath, "Containerfile") 315 err = ioutil.WriteFile(containerfilePath, []byte(containerfile), 0644) 316 Expect(err).To(BeNil()) 317 318 defer func() { 319 Expect(os.Chdir(cwd)).To(BeNil()) 320 Expect(os.RemoveAll(targetPath)).To(BeNil()) 321 }() 322 323 // make cwd as context root path 324 Expect(os.Chdir(targetPath)).To(BeNil()) 325 326 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "subdir/Containerfile", "."}) 327 session.WaitWithDefaultTimeout() 328 Expect(session).Should(Exit(0)) 329 }) 330 331 It("podman remote test .dockerignore", func() { 332 if IsRemote() { 333 podmanTest.StopRemoteService() 334 podmanTest.StartRemoteService() 335 } else { 336 Skip("Only valid at remote test") 337 } 338 // Given 339 // Switch to temp dir and restore it afterwards 340 cwd, err := os.Getwd() 341 Expect(err).To(BeNil()) 342 343 podmanTest.AddImageToRWStore(ALPINE) 344 345 // Write target and fake files 346 targetPath, err := CreateTempDirInTempDir() 347 Expect(err).To(BeNil()) 348 349 containerfile := fmt.Sprintf(`FROM %s 350 ADD . /testfilter/ 351 RUN find /testfilter/`, ALPINE) 352 353 containerfilePath := filepath.Join(targetPath, "Containerfile") 354 err = ioutil.WriteFile(containerfilePath, []byte(containerfile), 0644) 355 Expect(err).To(BeNil()) 356 357 targetSubPath := filepath.Join(targetPath, "subdir") 358 err = os.Mkdir(targetSubPath, 0755) 359 Expect(err).To(BeNil()) 360 361 dummyFile1 := filepath.Join(targetPath, "dummy1") 362 err = ioutil.WriteFile(dummyFile1, []byte("dummy1"), 0644) 363 Expect(err).To(BeNil()) 364 365 dummyFile2 := filepath.Join(targetPath, "dummy2") 366 err = ioutil.WriteFile(dummyFile2, []byte("dummy2"), 0644) 367 Expect(err).To(BeNil()) 368 369 dummyFile3 := filepath.Join(targetSubPath, "dummy3") 370 err = ioutil.WriteFile(dummyFile3, []byte("dummy3"), 0644) 371 Expect(err).To(BeNil()) 372 373 defer func() { 374 Expect(os.Chdir(cwd)).To(BeNil()) 375 Expect(os.RemoveAll(targetPath)).To(BeNil()) 376 }() 377 378 // make cwd as context root path 379 Expect(os.Chdir(targetPath)).To(BeNil()) 380 381 dockerignoreContent := `dummy1 382 subdir**` 383 dockerignoreFile := filepath.Join(targetPath, ".dockerignore") 384 385 // test .dockerignore 386 By("Test .dockererignore") 387 err = ioutil.WriteFile(dockerignoreFile, []byte(dockerignoreContent), 0644) 388 Expect(err).To(BeNil()) 389 390 session := podmanTest.Podman([]string{"build", "-t", "test", "."}) 391 session.WaitWithDefaultTimeout() 392 Expect(session).Should(Exit(0)) 393 ok, _ := session.GrepString("/testfilter/dummy1") 394 Expect(ok).NotTo(BeTrue()) 395 ok, _ = session.GrepString("/testfilter/dummy2") 396 Expect(ok).To(BeTrue()) 397 ok, _ = session.GrepString("/testfilter/subdir") 398 Expect(ok).NotTo(BeTrue()) //.dockerignore filters both subdir and inside subdir 399 ok, _ = session.GrepString("/testfilter/subdir/dummy3") 400 Expect(ok).NotTo(BeTrue()) 401 }) 402 403 It("podman remote test context dir contains empty dirs and symlinks", func() { 404 if IsRemote() { 405 podmanTest.StopRemoteService() 406 podmanTest.StartRemoteService() 407 } else { 408 Skip("Only valid at remote test") 409 } 410 // Given 411 // Switch to temp dir and restore it afterwards 412 cwd, err := os.Getwd() 413 Expect(err).To(BeNil()) 414 415 podmanTest.AddImageToRWStore(ALPINE) 416 417 // Write target and fake files 418 targetPath, err := CreateTempDirInTempDir() 419 Expect(err).To(BeNil()) 420 targetSubPath := filepath.Join(targetPath, "subdir") 421 err = os.Mkdir(targetSubPath, 0755) 422 Expect(err).To(BeNil()) 423 dummyFile := filepath.Join(targetSubPath, "dummy") 424 err = ioutil.WriteFile(dummyFile, []byte("dummy"), 0644) 425 Expect(err).To(BeNil()) 426 427 emptyDir := filepath.Join(targetSubPath, "emptyDir") 428 err = os.Mkdir(emptyDir, 0755) 429 Expect(err).To(BeNil()) 430 Expect(os.Chdir(targetSubPath)).To(BeNil()) 431 Expect(os.Symlink("dummy", "dummy-symlink")).To(BeNil()) 432 433 containerfile := fmt.Sprintf(`FROM %s 434 ADD . /test 435 RUN find /test 436 RUN [[ -L /test/dummy-symlink ]] && echo SYMLNKOK || echo SYMLNKERR`, ALPINE) 437 438 containerfilePath := filepath.Join(targetSubPath, "Containerfile") 439 err = ioutil.WriteFile(containerfilePath, []byte(containerfile), 0644) 440 Expect(err).To(BeNil()) 441 442 defer func() { 443 Expect(os.Chdir(cwd)).To(BeNil()) 444 Expect(os.RemoveAll(targetPath)).To(BeNil()) 445 }() 446 447 // make cwd as context root path 448 Expect(os.Chdir(targetPath)).To(BeNil()) 449 450 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", targetSubPath}) 451 session.WaitWithDefaultTimeout() 452 Expect(session).Should(Exit(0)) 453 ok, _ := session.GrepString("/test/dummy") 454 Expect(ok).To(BeTrue()) 455 ok, _ = session.GrepString("/test/emptyDir") 456 Expect(ok).To(BeTrue()) 457 ok, _ = session.GrepString("/test/dummy-symlink") 458 Expect(ok).To(BeTrue()) 459 ok, _ = session.GrepString("SYMLNKOK") 460 Expect(ok).To(BeTrue()) 461 }) 462 463 It("podman build --from, --add-host, --cap-drop, --cap-add", func() { 464 targetPath, err := CreateTempDirInTempDir() 465 Expect(err).To(BeNil()) 466 467 containerFile := filepath.Join(targetPath, "Containerfile") 468 content := `FROM scratch 469 RUN cat /etc/hosts 470 RUN grep CapEff /proc/self/status` 471 472 Expect(ioutil.WriteFile(containerFile, []byte(content), 0755)).To(BeNil()) 473 474 defer func() { 475 Expect(os.RemoveAll(containerFile)).To(BeNil()) 476 }() 477 478 // When 479 session := podmanTest.Podman([]string{ 480 "build", "--pull-never", "--cap-drop=all", "--cap-add=net_bind_service", "--add-host", "testhost:1.2.3.4", "--from", ALPINE, targetPath, 481 }) 482 session.WaitWithDefaultTimeout() 483 484 // Then 485 Expect(session).Should(Exit(0)) 486 Expect(strings.Fields(session.OutputToString())). 487 To(ContainElement(ALPINE)) 488 Expect(strings.Fields(session.OutputToString())). 489 To(ContainElement("testhost")) 490 Expect(strings.Fields(session.OutputToString())). 491 To(ContainElement("0000000000000400")) 492 }) 493 494 It("podman build --isolation && --arch", func() { 495 targetPath, err := CreateTempDirInTempDir() 496 Expect(err).To(BeNil()) 497 498 containerFile := filepath.Join(targetPath, "Containerfile") 499 Expect(ioutil.WriteFile(containerFile, []byte(fmt.Sprintf("FROM %s", ALPINE)), 0755)).To(BeNil()) 500 501 defer func() { 502 Expect(os.RemoveAll(containerFile)).To(BeNil()) 503 }() 504 505 // When 506 session := podmanTest.Podman([]string{ 507 "build", "--isolation", "oci", "--arch", "arm64", targetPath, 508 }) 509 session.WaitWithDefaultTimeout() 510 // Then 511 Expect(session).Should(Exit(0)) 512 513 // When 514 session = podmanTest.Podman([]string{ 515 "build", "--isolation", "chroot", "--arch", "arm64", targetPath, 516 }) 517 session.WaitWithDefaultTimeout() 518 // Then 519 Expect(session).Should(Exit(0)) 520 521 // When 522 session = podmanTest.Podman([]string{ 523 "build", "--pull-never", "--isolation", "rootless", "--arch", "arm64", targetPath, 524 }) 525 session.WaitWithDefaultTimeout() 526 // Then 527 Expect(session).Should(Exit(0)) 528 529 // When 530 session = podmanTest.Podman([]string{ 531 "build", "--pull-never", "--isolation", "bogus", "--arch", "arm64", targetPath, 532 }) 533 session.WaitWithDefaultTimeout() 534 // Then 535 Expect(session).Should(Exit(125)) 536 }) 537 538 It("podman build --timestamp flag", func() { 539 containerfile := fmt.Sprintf(`FROM %s 540 RUN echo hello`, ALPINE) 541 542 containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") 543 err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755) 544 Expect(err).To(BeNil()) 545 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--timestamp", "0", "--file", containerfilePath, podmanTest.TempDir}) 546 session.WaitWithDefaultTimeout() 547 Expect(session).Should(Exit(0)) 548 549 inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Created }}", "test"}) 550 inspect.WaitWithDefaultTimeout() 551 Expect(inspect.OutputToString()).To(Equal("1970-01-01 00:00:00 +0000 UTC")) 552 }) 553 554 It("podman build --log-rusage", func() { 555 targetPath, err := CreateTempDirInTempDir() 556 Expect(err).To(BeNil()) 557 558 containerFile := filepath.Join(targetPath, "Containerfile") 559 content := `FROM scratch` 560 561 Expect(ioutil.WriteFile(containerFile, []byte(content), 0755)).To(BeNil()) 562 563 session := podmanTest.Podman([]string{"build", "--log-rusage", "--pull-never", targetPath}) 564 session.WaitWithDefaultTimeout() 565 Expect(session).Should(Exit(0)) 566 Expect(session.OutputToString()).To(ContainSubstring("(system)")) 567 Expect(session.OutputToString()).To(ContainSubstring("(user)")) 568 Expect(session.OutputToString()).To(ContainSubstring("(elapsed)")) 569 }) 570 571 It("podman build --arch --os flag", func() { 572 containerfile := `FROM scratch` 573 containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") 574 err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755) 575 Expect(err).To(BeNil()) 576 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--arch", "foo", "--os", "bar", "--file", containerfilePath, podmanTest.TempDir}) 577 session.WaitWithDefaultTimeout() 578 Expect(session).Should(Exit(0)) 579 580 inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Architecture }}", "test"}) 581 inspect.WaitWithDefaultTimeout() 582 Expect(inspect.OutputToString()).To(Equal("foo")) 583 584 inspect = podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Os }}", "test"}) 585 inspect.WaitWithDefaultTimeout() 586 Expect(inspect.OutputToString()).To(Equal("bar")) 587 588 }) 589 590 It("podman build --os windows flag", func() { 591 containerfile := `FROM scratch` 592 containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") 593 err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755) 594 Expect(err).To(BeNil()) 595 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--os", "windows", "--file", containerfilePath, podmanTest.TempDir}) 596 session.WaitWithDefaultTimeout() 597 Expect(session).Should(Exit(0)) 598 599 inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Architecture }}", "test"}) 600 inspect.WaitWithDefaultTimeout() 601 Expect(inspect.OutputToString()).To(Equal(runtime.GOARCH)) 602 603 inspect = podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Os }}", "test"}) 604 inspect.WaitWithDefaultTimeout() 605 Expect(inspect.OutputToString()).To(Equal("windows")) 606 607 }) 608 609 It("podman build device test", func() { 610 if _, err := os.Lstat("/dev/fuse"); err != nil { 611 Skip(fmt.Sprintf("test requires stat /dev/fuse to work: %v", err)) 612 } 613 containerfile := fmt.Sprintf(`FROM %s 614 RUN ls /dev/fuse`, ALPINE) 615 containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") 616 err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755) 617 Expect(err).To(BeNil()) 618 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir}) 619 session.WaitWithDefaultTimeout() 620 Expect(session).Should(Exit(125)) 621 622 session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/fuse", "-t", "test", "--file", containerfilePath, podmanTest.TempDir}) 623 session.WaitWithDefaultTimeout() 624 Expect(session).Should(Exit(0)) 625 }) 626 627 It("podman build device rename test", func() { 628 SkipIfRootless("rootless builds do not currently support renaming devices") 629 containerfile := fmt.Sprintf(`FROM %s 630 RUN ls /dev/test1`, ALPINE) 631 containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") 632 err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755) 633 Expect(err).To(BeNil()) 634 session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir}) 635 session.WaitWithDefaultTimeout() 636 Expect(session).Should(Exit(125)) 637 638 session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/zero:/dev/test1", "-t", "test", "--file", containerfilePath, podmanTest.TempDir}) 639 session.WaitWithDefaultTimeout() 640 Expect(session).Should(Exit(0)) 641 }) 642 })