From 761597056c8dc2bb1efd67e937a196ddff1fa7a6 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 29 Mar 2017 15:50:32 -0400 Subject: [PATCH] Add a few tests for building images It's nowhere near exhaustive, but it's a start. Signed-off-by: Nalin Dahyabhai Closes: #59 Approved by: rhatdan --- tests/bud.bats | 170 ++++++++++++++++++ .../from-multiple-files/Dockerfile1.alpine | 2 + .../from-multiple-files/Dockerfile1.scratch | 2 + .../from-multiple-files/Dockerfile2.nofrom | 1 + .../from-multiple-files/Dockerfile2.withfrom | 2 + tests/bud/from-scratch/Dockerfile | 1 + tests/bud/http-context-subdir/context.tar | Bin 0 -> 10240 bytes tests/bud/http-context/context.tar | Bin 0 -> 10240 bytes tests/bud/preserve-volumes/Dockerfile | 16 ++ tests/helpers.bash | 2 +- 10 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 tests/bud.bats create mode 100644 tests/bud/from-multiple-files/Dockerfile1.alpine create mode 100644 tests/bud/from-multiple-files/Dockerfile1.scratch create mode 100644 tests/bud/from-multiple-files/Dockerfile2.nofrom create mode 100644 tests/bud/from-multiple-files/Dockerfile2.withfrom create mode 100644 tests/bud/from-scratch/Dockerfile create mode 100644 tests/bud/http-context-subdir/context.tar create mode 100644 tests/bud/http-context/context.tar create mode 100644 tests/bud/preserve-volumes/Dockerfile 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 0000000000000000000000000000000000000000..533ae524e2bb64df78c9fb864b32bda8628361b0 GIT binary patch literal 10240 zcmeIwO$x#=5QgEbJwE%(zO85%ZNW_oitlXFOh_1>uRdH- zeNRg@V@Xram8xBv>aWk9$;FAYVl$(}n5-z2E@zynd-`@wRn%I=5K`A1`S^4`a^)9V z{+0hK_){JC$8$aX)NR1l7X94cdl6HrE`QVfA12RoQCg-SW%%Ns=fB=8=!VgCGehEeOWmzh)=NBC9L{|7=D^9Uk93hR=}3 z_ji!PN=td)$kI!#yQ+0!Z`x|>)ivdvwa#6|=wXSf#lJcC$rwp7=4!k-?%i)boMZ6l zUQaWJ)aNi=&JmfE2q1s}0tg_000IagfB*srAb /dev/null + pushd ${2:-${TESTDIR}} > /dev/null cp ${TESTSDIR}/serve.go . go build serve.go HTTP_SERVER_PORT=$((RANDOM+32768))