diff options
-rw-r--r-- | docs/source/Commands.rst | 2 | ||||
-rw-r--r-- | docs/source/markdown/podman.1.md | 4 | ||||
-rw-r--r-- | pkg/api/handlers/compat/images_build.go | 12 | ||||
-rw-r--r-- | pkg/bindings/images/build.go | 2 | ||||
-rw-r--r-- | test/e2e/build_test.go | 13 | ||||
-rw-r--r-- | test/e2e/images_test.go | 4 | ||||
-rw-r--r-- | test/system/010-images.bats | 12 | ||||
-rw-r--r-- | test/system/070-build.bats | 63 | ||||
-rw-r--r-- | test/system/160-volumes.bats | 3 |
9 files changed, 99 insertions, 16 deletions
diff --git a/docs/source/Commands.rst b/docs/source/Commands.rst index 881dcb4b6..cd5d894da 100644 --- a/docs/source/Commands.rst +++ b/docs/source/Commands.rst @@ -3,7 +3,7 @@ Commands ======== -:doc:`Podman <markdown/podman.1>` (Pod Manager) Global Options +:doc:`Podman <markdown/podman.1>` (Pod Manager) Global Options, Environment Variables, Exit Codes, Configuration Files, and more :doc:`attach <markdown/podman-attach.1>` Attach to a running container diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 87867bf35..1954ca2aa 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -168,7 +168,7 @@ podman --remote flag, only the global options `--url`, `--identity`, `--log-leve Connection information can also be managed using the containers.conf file. -## Exit Status +## Exit Codes The exit code from `podman` gives information about why the container failed to run or why it exited. When `podman` commands exit with a non-zero code, @@ -257,7 +257,7 @@ the exit codes follow the `chroot` standard, see below: | [podman-volume(1)](podman-volume.1.md) | Simple management tool for volumes. | | [podman-wait(1)](podman-wait.1.md) | Wait on one or more containers to stop and print their exit codes. | -## FILES +## CONFIGURATION FILES **containers.conf** (`/usr/share/containers/containers.conf`, `/etc/containers/containers.conf`, `$HOME/.config/containers/containers.conf`) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index d5ccf56fe..a4bb72140 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -272,15 +272,13 @@ loop: flush() case <-runCtx.Done(): if !failed { - if utils.IsLibpodRequest(r) { - m.Stream = imageID - } else { + if !utils.IsLibpodRequest(r) { m.Stream = fmt.Sprintf("Successfully built %12.12s\n", imageID) + if err := enc.Encode(m); err != nil { + logrus.Warnf("Failed to json encode error %q", err.Error()) + } + flush() } - if err := enc.Encode(m); err != nil { - logrus.Warnf("Failed to json encode error %q", err.Error()) - } - flush() } break loop } diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 60ffea548..815ab4e86 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -187,7 +187,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO case s.Stream != "": stdout.Write([]byte(s.Stream)) if re.Match([]byte(s.Stream)) { - id = s.Stream + id = strings.TrimSuffix(s.Stream, "\n") } case s.Error != "": return nil, errors.New(s.Error) diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index ea15e2b8d..87db5a126 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -7,6 +7,7 @@ import ( "runtime" "strings" + "github.com/containers/buildah" . "github.com/containers/podman/v2/test/utils" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -239,4 +240,16 @@ RUN printenv http_proxy` Expect(ok).To(BeTrue()) os.Unsetenv("http_proxy") }) + + It("podman build and check identity", func() { + session := podmanTest.Podman([]string{"build", "-f", "Containerfile.path", "--no-cache", "-t", "test", "build/basicalpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + // Verify that OS and Arch are being set + inspect := podmanTest.PodmanNoCache([]string{"image", "inspect", "--format", "{{ index .Config.Labels }}", "test"}) + inspect.WaitWithDefaultTimeout() + data := inspect.OutputToString() + Expect(data).To(ContainSubstring(buildah.Version)) + }) }) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index b42061c20..96eccdc28 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -198,7 +198,7 @@ WORKDIR /test Expect(result.OutputToString()).To(Equal("/test")) }) - It("podman images filter after image", func() { + It("podman images filter since image", func() { podmanTest.RestoreAllArtifacts() rmi := podmanTest.PodmanNoCache([]string{"rmi", "busybox"}) rmi.WaitWithDefaultTimeout() @@ -207,7 +207,7 @@ WORKDIR /test dockerfile := `FROM quay.io/libpod/alpine:latest ` podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false") - result := podmanTest.PodmanNoCache([]string{"images", "-q", "-f", "after=quay.io/libpod/alpine:latest"}) + result := podmanTest.PodmanNoCache([]string{"images", "-q", "-f", "since=quay.io/libpod/alpine:latest"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) Expect(len(result.OutputToStringArray())).To(Equal(0)) diff --git a/test/system/010-images.bats b/test/system/010-images.bats index 900a24368..98bb0cc57 100644 --- a/test/system/010-images.bats +++ b/test/system/010-images.bats @@ -3,10 +3,18 @@ load helpers @test "podman images - basic output" { - run_podman images -a + headings="REPOSITORY *TAG *IMAGE ID *CREATED *SIZE" - is "${lines[0]}" "REPOSITORY *TAG *IMAGE ID *CREATED *SIZE" "header line" + run_podman images -a + is "${lines[0]}" "$headings" "header line" is "${lines[1]}" "$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME *$PODMAN_TEST_IMAGE_TAG *[0-9a-f]\+" "podman images output" + + # 'podman images' should emit headings even if there are no images + # (but --root only works locally) + if ! is_remote; then + run_podman --root ${PODMAN_TMPDIR}/nothing-here-move-along images + is "$output" "$headings" "'podman images' emits headings even w/o images" + fi } @test "podman images - custom formats" { diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 0741357ed..83bcd13eb 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -221,6 +221,11 @@ EOF run_podman run --rm build_test pwd is "$output" "$workdir" "pwd command in container" + # Determine buildah version, so we can confirm it gets into Labels + run_podman info --format '{{ .Host.BuildahVersion }}' + is "$output" "[1-9][0-9.-]\+" ".Host.BuildahVersion is reasonable" + buildah_version=$output + # Confirm that 'podman inspect' shows the expected values # FIXME: can we rely on .Env[0] being PATH, and the rest being in order?? run_podman image inspect build_test @@ -239,6 +244,7 @@ Cmd[0] | /bin/mydefaultcmd Cmd[1] | $s_echo WorkingDir | $workdir Labels.$label_name | $label_value +Labels.\"io.buildah.version\" | $buildah_version " parse_table "$tests" | while read field expect; do @@ -312,6 +318,63 @@ EOF run_podman rmi -f build_test } +# #8092 - podman build should not gobble stdin (Fixes: #8066) +@test "podman build - does not gobble stdin that does not belong to it" { + random1=random1-$(random_string 12) + random2=random2-$(random_string 15) + random3=random3-$(random_string 12) + + tmpdir=$PODMAN_TMPDIR/build-test + mkdir -p $tmpdir + cat >$tmpdir/Containerfile <<EOF +FROM $IMAGE +RUN echo x${random2}y +EOF + + # This is a little rococo, bear with me please. #8092 fixed a bug + # in which 'podman build' would slurp up any input in the pipeline. + # Not a problem in a contrived example such as the one below, but + # definitely a problem when running commands in a pipeline to bash: + # all commands after 'podman build' would silently be ignored. + # In the test below, prior to #8092, the 'sed' would not get + # any input, and we would never see $random3 in the output. + # And, we use 'sed' to massage $random3 juuuuust on the remote + # chance that podman itself could pass stdin through. + results=$(echo $random3 | ( + echo $random1 + run_podman build -t build_test $tmpdir + sed -e 's/^/a/' -e 's/$/z/' + )) + + # First simple test: confirm that we see the piped-in string, as + # massaged by sed. This fails in 287edd4e2, the commit before #8092. + # We do this before the thorough test (below) because, should it + # fail, the diagnostic is much clearer and easier to understand. + is "$results" ".*a${random3}z" "stdin remains after podman-build" + + # More thorough test: verify all the required strings in order. + # This is unlikely to fail, but it costs us nothing and could + # catch a regression somewhere else. + # FIXME: podman-remote output differs from local: #8342 (spurious ^M) + # FIXME: podman-remote output differs from local: #8343 (extra SHA output) + remote_extra="" + if is_remote; then remote_extra=".*";fi + expect="${random1} +.* +STEP 1: FROM $IMAGE +STEP 2: RUN echo x${random2}y +x${random2}y${remote_extra} +STEP 3: COMMIT build_test${remote_extra} +--> [0-9a-f]\{11\} +[0-9a-f]\{64\} +a${random3}z" + + is "$results" "$expect" "Full output from 'podman build' pipeline" + + run_podman rmi -f build_test +} + + function teardown() { # A timeout or other error in 'build' can leave behind stale images # that podman can't even see and which will cascade into subsequent diff --git a/test/system/160-volumes.bats b/test/system/160-volumes.bats index c19e61669..0b7aab2fb 100644 --- a/test/system/160-volumes.bats +++ b/test/system/160-volumes.bats @@ -162,7 +162,8 @@ EOF myvol=myvol$(random_string) rand=$(random_string) - run_podman run --rm -v $myvol:/myvol:z $IMAGE \ + # Duplicate "-v" confirms #8307, fix for double-lock on same volume + run_podman run --rm -v $myvol:/myvol:z -v $myvol:/myvol2:z $IMAGE \ sh -c "echo $rand >/myvol/myfile" run_podman volume ls -q is "$output" "$myvol" "autocreated named container persists" |