diff --git a/tests/bud.bats b/tests/bud.bats new file mode 100644 index 00000000..f3ed7f2a --- /dev/null +++ b/tests/bud.bats @@ -0,0 +1,170 @@ +#!/usr/bin/env bats + +load helpers + +@test "bud-from-scratch" { + target=scratch-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-from-multiple-files-one-from" { + target=scratch-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom + cid=$(buildah from ${target}) + root=$(buildah mount ${cid}) + cmp $root/Dockerfile1 ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch + cmp $root/Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom + run test -s $root/etc/passwd + [ "$status" -ne 0 ] + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] + + target=alpine-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.alpine -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom + cid=$(buildah from ${target}) + root=$(buildah mount ${cid}) + cmp $root/Dockerfile1 ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.alpine + cmp $root/Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom + run test -s $root/etc/passwd + [ "$status" -eq 0 ] + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-from-multiple-files-two-froms" { + target=scratch-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.withfrom + cid=$(buildah from ${target}) + root=$(buildah mount ${cid}) + cmp $root/Dockerfile1 ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch + cmp $root/Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.withfrom + run test -s $root/etc/passwd + [ "$status" -ne 0 ] + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] + + target=alpine-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.alpine -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.withfrom + cid=$(buildah from ${target}) + root=$(buildah mount ${cid}) + cmp $root/Dockerfile1 ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.alpine + cmp $root/Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.withfrom + run test -s $root/etc/passwd + [ "$status" -eq 0 ] + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-preserve-subvolumes" { + # This Dockerfile needs us to be able to handle a working RUN instruction. + if ! which runc ; then + skip + fi + target=volume-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/preserve-volumes + cid=$(buildah from ${target}) + root=$(buildah mount ${cid}) + test -s $root/vol/subvol/subsubvol/subsubvolfile + run test -s $root/vol/subvol/subvolfile + [ "$status" -ne 0 ] + test -s $root/vol/volfile + run test -s $root/vol/anothervolfile + [ "$status" -ne 0 ] + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-http-Dockerfile" { + starthttpd ${TESTSDIR}/bud/from-scratch + target=scratch-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f http://0.0.0.0:${HTTP_SERVER_PORT}/Dockerfile . + stophttpd + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-http-context-with-Dockerfile" { + starthttpd ${TESTSDIR}/bud/http-context + target=scratch-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} http://0.0.0.0:${HTTP_SERVER_PORT}/context.tar + stophttpd + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-http-context-dir-with-Dockerfile-pre" { + starthttpd ${TESTSDIR}/bud/http-context-subdir + target=scratch-image + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f context/Dockerfile http://0.0.0.0:${HTTP_SERVER_PORT}/context.tar + stophttpd + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-http-context-dir-with-Dockerfile-post" { + starthttpd ${TESTSDIR}/bud/http-context-subdir + target=scratch-image + buildah bud http://0.0.0.0:${HTTP_SERVER_PORT}/context.tar --signature-policy ${TESTSDIR}/policy.json -t ${target} -f context/Dockerfile + stophttpd + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-git-context" { + # We need git and ssh to be around to handle cloning a repository. + if ! which git ; then + skip + fi + if ! which ssh ; then + skip + fi + target=giturl-image + # Any repo should do, but this one is small and is FROM: scratch. + gitrepo=git://github.com/projectatomic/nulecule-library + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} "${gitrepo}" + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} + +@test "bud-github-context" { + target=github-image + # Any repo should do, but this one is small and is FROM: scratch. + gitrepo=github.com/projectatomic/nulecule-library + buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} "${gitrepo}" + cid=$(buildah from ${target}) + buildah rm ${cid} + buildah --debug=false images -q + buildah rmi $(buildah --debug=false images -q) + run buildah --debug=false images -q + [ "$output" = "" ] +} diff --git a/tests/bud/from-multiple-files/Dockerfile1.alpine b/tests/bud/from-multiple-files/Dockerfile1.alpine new file mode 100644 index 00000000..c6e3fc40 --- /dev/null +++ b/tests/bud/from-multiple-files/Dockerfile1.alpine @@ -0,0 +1,2 @@ +FROM alpine +COPY Dockerfile1.alpine /Dockerfile1 diff --git a/tests/bud/from-multiple-files/Dockerfile1.scratch b/tests/bud/from-multiple-files/Dockerfile1.scratch new file mode 100644 index 00000000..4f9ab8a6 --- /dev/null +++ b/tests/bud/from-multiple-files/Dockerfile1.scratch @@ -0,0 +1,2 @@ +FROM scratch +COPY Dockerfile1.scratch /Dockerfile1 diff --git a/tests/bud/from-multiple-files/Dockerfile2.nofrom b/tests/bud/from-multiple-files/Dockerfile2.nofrom new file mode 100644 index 00000000..0473c91d --- /dev/null +++ b/tests/bud/from-multiple-files/Dockerfile2.nofrom @@ -0,0 +1 @@ +COPY Dockerfile2.nofrom / diff --git a/tests/bud/from-multiple-files/Dockerfile2.withfrom b/tests/bud/from-multiple-files/Dockerfile2.withfrom new file mode 100644 index 00000000..fa3b9690 --- /dev/null +++ b/tests/bud/from-multiple-files/Dockerfile2.withfrom @@ -0,0 +1,2 @@ +FROM alpine +COPY Dockerfile2.withfrom / diff --git a/tests/bud/from-scratch/Dockerfile b/tests/bud/from-scratch/Dockerfile new file mode 100644 index 00000000..c35f1b5f --- /dev/null +++ b/tests/bud/from-scratch/Dockerfile @@ -0,0 +1 @@ +FROM scratch diff --git a/tests/bud/http-context-subdir/context.tar b/tests/bud/http-context-subdir/context.tar new file mode 100644 index 00000000..533ae524 Binary files /dev/null and b/tests/bud/http-context-subdir/context.tar differ diff --git a/tests/bud/http-context/context.tar b/tests/bud/http-context/context.tar new file mode 100644 index 00000000..2e5f3a51 Binary files /dev/null and b/tests/bud/http-context/context.tar differ diff --git a/tests/bud/preserve-volumes/Dockerfile b/tests/bud/preserve-volumes/Dockerfile new file mode 100644 index 00000000..38c8844a --- /dev/null +++ b/tests/bud/preserve-volumes/Dockerfile @@ -0,0 +1,16 @@ +FROM alpine +RUN mkdir -p /vol/subvol/subsubvol +RUN dd if=/dev/zero bs=512 count=1 of=/vol/subvol/subsubvol/subsubvolfile +VOLUME /vol/subvol +# At this point, the contents below /vol/subvol should be frozen. +RUN dd if=/dev/zero bs=512 count=1 of=/vol/subvol/subvolfile +# In particular, /vol/subvol/subvolfile should be wiped out. +RUN dd if=/dev/zero bs=512 count=1 of=/vol/volfile +# However, /vol/volfile should exist. +VOLUME /vol +# And this should be redundant. +VOLUME /vol/subvol +# And now we've frozen /vol. +RUN dd if=/dev/zero bs=512 count=1 of=/vol/anothervolfile +# Which means that in the image we're about to commit, /vol/anothervolfile +# shouldn't exist, either. diff --git a/tests/helpers.bash b/tests/helpers.bash index 038adb1d..92af896c 100644 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -12,7 +12,7 @@ function setup() { } function starthttpd() { - pushd ${2:-${BATS_TMPDIR}} > /dev/null + pushd ${2:-${TESTDIR}} > /dev/null cp ${TESTSDIR}/serve.go . go build serve.go HTTP_SERVER_PORT=$((RANDOM+32768))