#!/usr/bin/env bats -*- bats -*- # shellcheck disable=SC2096 # # Tests for podman build # load helpers @test "podman build - basic test" { rand_filename=$(random_string 20) rand_content=$(random_string 50) tmpdir=$PODMAN_TMPDIR/build-test mkdir -p $tmpdir dockerfile=$tmpdir/Dockerfile cat >$dockerfile < /$rand_filename EOF # The 'apk' command can take a long time to fetch files; bump timeout PODMAN_TIMEOUT=240 run_podman build -t build_test --format=docker $tmpdir is "$output" ".*STEP 4: COMMIT" "COMMIT seen in log" run_podman run --rm build_test cat /$rand_filename is "$output" "$rand_content" "reading generated file in image" run_podman rmi -f build_test } @test "podman build - global runtime flags test" { skip_if_remote "--runtime-flag flag not supported for remote" rand_content=$(random_string 50) tmpdir=$PODMAN_TMPDIR/build-test run mkdir -p $tmpdir containerfile=$tmpdir/Containerfile cat >$containerfile <$containerfile <$containersconf < $tmpdir/subtest/myfile1 run tar -C $tmpdir -cJf $tmpdir/myfile.tar.xz subtest cat >$tmpdir/Dockerfile <| $tmpdir/subtest/myfile2 run tar -C $tmpdir -cJf $tmpdir/myfile.tar.xz subtest run_podman build -t build_test -f $tmpdir/Dockerfile $tmpdir is "$output" ".*STEP 3: COMMIT" "COMMIT seen in log" # Since the tarfile is modified, podman SHOULD NOT use a cached layer. if [[ "$output" =~ "Using cache" ]]; then is "$output" "[no instance of 'Using cache']" "no cache used" fi # Pre-buildah-1906, this fails with ENOENT because the tarfile was cached run_podman run --rm build_test cat /subtest/myfile2 is "$output" "This is a NEW file" "file contents, second time" run_podman rmi -f build_test $iid } @test "podman build - URLs" { tmpdir=$PODMAN_TMPDIR/build-test mkdir -p $tmpdir cat >$tmpdir/Dockerfile <xyz', i.e. any string beginning with digit label_name=l$(random_string 8) label_value=$(random_string 12) # #8679: Create a secrets directory, and mount it in the container # (can only test locally; podman-remote has no --default-mounts-file opt) MOUNTS_CONF= secret_contents="ceci nest pas un secret" CAT_SECRET="echo $secret_contents" if ! is_remote; then mkdir $tmpdir/secrets echo $tmpdir/secrets:/run/secrets > $tmpdir/mounts.conf secret_filename=secretfile-$(random_string 20) secret_contents=shhh-$(random_string 30)-shhh echo $secret_contents >$tmpdir/secrets/$secret_filename MOUNTS_CONF=--default-mounts-file=$tmpdir/mounts.conf CAT_SECRET="cat /run/secrets/$secret_filename" fi # Command to run on container startup with no args cat >$tmpdir/mycmd <$PODMAN_TMPDIR/env-file1 <$PODMAN_TMPDIR/env-file2 <$tmpdir/Containerfile < expect=<$expect}>" is "$actual" "$expect" "jq .Config.$field" done # Bad symlink in volume. Prior to #7094, well, we wouldn't actually # get here because any 'podman run' on a volume that had symlinks, # be they dangling or valid, would barf with # Error: chown /_data/symlink: ENOENT run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/badsymlink is "$output" "1:2:'/a/b/c/badsymlink' -> '/no/such/nonesuch'" \ "bad symlink to nonexistent file is chowned and preserved" run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/goodsymlink is "$output" "1:2:'/a/b/c/goodsymlink' -> '/bin/mydefaultcmd'" \ "good symlink to existing file is chowned and preserved" run_podman run --rm build_test stat -c'%u:%g' /bin/mydefaultcmd is "$output" "2:3" "target of symlink is not chowned" run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/myfile is "$output" "4:5:/a/b/c/myfile" "file in volume is chowned" # Hey, as long as we have an image with lots of layers, let's # confirm that 'image tree' works as expected run_podman image tree build_test is "${lines[0]}" "Image ID: ${iid:0:12}" \ "image tree: first line" is "${lines[1]}" "Tags: \[localhost/build_test:latest]" \ "image tree: second line" is "${lines[2]}" "Size: [0-9.]\+[kM]B" \ "image tree: third line" is "${lines[3]}" "Image Layers" \ "image tree: fourth line" is "${lines[4]}" "... ID: [0-9a-f]\{12\} Size: .* Top Layer of: \[$IMAGE]" \ "image tree: first layer line" is "${lines[-1]}" "... ID: [0-9a-f]\{12\} Size: .* Top Layer of: \[localhost/build_test:latest]" \ "image tree: last layer line" # FIXME: 'image tree --whatrequires' does not work via remote if ! is_remote; then run_podman image tree --whatrequires $IMAGE is "${lines[-1]}" \ ".*ID: .* Top Layer of: \\[localhost/build_test:latest\\]" \ "'image tree --whatrequires' shows our built image" fi # Clean up run_podman rmi -f build_test } @test "podman build - stdin test" { # Random workdir, and random string to verify build output workdir=/$(random_string 10) random_echo=$(random_string 15) PODMAN_TIMEOUT=240 run_podman build -t build_test - << EOF FROM $IMAGE RUN mkdir $workdir WORKDIR $workdir RUN /bin/echo $random_echo EOF is "$output" ".*STEP 5: COMMIT" "COMMIT seen in log" is "$output" ".*STEP .: RUN /bin/echo $random_echo" run_podman run --rm build_test pwd is "$output" "$workdir" "pwd command in container" 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 <$containerfile <$containerfile1 <$containerfile2 <$dockerfile <