#!/usr/bin/env bats -*- bats -*- # # Tests for podman build # load helpers @test "podman build - basic test" { if is_remote && is_rootless; then skip "unreliable with podman-remote and rootless; #2972" fi rand_filename=$(random_string 20) rand_content=$(random_string 50) tmpdir=$PODMAN_TMPDIR/build-test run mkdir -p $tmpdir || die "Could not mkdir $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 } # Regression from v1.5.0. This test passes fine in v1.5.0, fails in 1.6 @test "podman build - cache (#3920)" { if is_remote && is_rootless; then skip "unreliable with podman-remote and rootless; #2972" fi # Make an empty test directory, with a subdirectory used for tar tmpdir=$PODMAN_TMPDIR/build-test mkdir -p $tmpdir/subtest || die "Could not mkdir $tmpdir/subtest" echo "This is the ORIGINAL file" > $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) # Command to run on container startup with no args cat >$tmpdir/mycmd <$PODMAN_TMPDIR/env-file <$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" # Clean up run_podman rmi -f build_test } @test "podman build - stdin test" { if is_remote && is_rootless; then skip "unreliable with podman-remote and rootless; #2972" fi # Random workdir, and multiple random strings to verify command & env workdir=/$(random_string 10) PODMAN_TIMEOUT=240 run_podman build -t build_test - << EOF FROM $IMAGE RUN mkdir $workdir WORKDIR $workdir RUN /bin/echo 'Test' EOF is "$output" ".*STEP 5: COMMIT" "COMMIT seen in log" run_podman run --rm build_test pwd is "$output" "$workdir" "pwd command in container" 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 # test failures. Try a last-ditch force-rm in cleanup, ignoring errors. run_podman '?' rm -a -f run_podman '?' rmi -f build_test basic_teardown } # vim: filetype=sh