1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#!/usr/bin/env bats
load helpers
@test "add-flags-order-verification" {
run_buildah 125 add container1 -q /tmp/container1
check_options_flag_err "-q"
run_buildah 125 add container1 --chown /tmp/container1 --quiet
check_options_flag_err "--chown"
run_buildah 125 add container1 /tmp/container1 --quiet
check_options_flag_err "--quiet"
}
@test "add-local-plain" {
createrandom ${TESTDIR}/randomfile
createrandom ${TESTDIR}/other-randomfile
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah mount $cid
root=$output
mkdir $root/subdir $root/other-subdir
# Copy a file to the working directory
run_buildah config --workingdir=/ $cid
run_buildah add $cid ${TESTDIR}/randomfile
# Copy a file to a specific subdirectory
run_buildah add $cid ${TESTDIR}/randomfile /subdir
# Copy two files to a specific subdirectory
run_buildah add $cid ${TESTDIR}/randomfile ${TESTDIR}/other-randomfile /other-subdir
# Copy two files to a specific location, which succeeds because we can create it as a directory.
run_buildah add $cid ${TESTDIR}/randomfile ${TESTDIR}/other-randomfile /notthereyet-subdir
# Copy two files to a specific location, which fails because it's not a directory.
run_buildah 125 add $cid ${TESTDIR}/randomfile ${TESTDIR}/other-randomfile /randomfile
# Copy a file to a different working directory
run_buildah config --workingdir=/cwd $cid
run_buildah add $cid ${TESTDIR}/randomfile
run_buildah unmount $cid
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image
run_buildah rm $cid
run_buildah from --signature-policy ${TESTSDIR}/policy.json new-image
newcid=$output
run_buildah mount $newcid
newroot=$output
test -s $newroot/randomfile
cmp ${TESTDIR}/randomfile $newroot/randomfile
test -s $newroot/subdir/randomfile
cmp ${TESTDIR}/randomfile $newroot/subdir/randomfile
test -s $newroot/other-subdir/randomfile
cmp ${TESTDIR}/randomfile $newroot/other-subdir/randomfile
test -s $newroot/other-subdir/other-randomfile
cmp ${TESTDIR}/other-randomfile $newroot/other-subdir/other-randomfile
test -d $newroot/cwd
test -s $newroot/cwd/randomfile
cmp ${TESTDIR}/randomfile $newroot/cwd/randomfile
run_buildah rm $newcid
}
@test "add-local-archive" {
createrandom ${TESTDIR}/randomfile
createrandom ${TESTDIR}/other-randomfile
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/random2
tar -c -C ${TESTDIR} -f ${TESTDIR}/tarball1.tar random1 random2
mkdir ${TESTDIR}/tarball2
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball2/tarball2.random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball2/tarball2.random2
tar -c -C ${TESTDIR} -z -f ${TESTDIR}/tarball2.tar.gz tarball2
mkdir ${TESTDIR}/tarball3
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball3/tarball3.random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball3/tarball3.random2
tar -c -C ${TESTDIR} -j -f ${TESTDIR}/tarball3.tar.bz2 tarball3
mkdir ${TESTDIR}/tarball4
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball4/tarball4.random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball4/tarball4.random2
tar -c -C ${TESTDIR} -j -f ${TESTDIR}/tarball4.tar.bz2 tarball4
# Add the files to the working directory, which should extract them all.
run_buildah config --workingdir=/ $cid
run_buildah add $cid ${TESTDIR}/tarball1.tar
run_buildah add $cid ${TESTDIR}/tarball2.tar.gz
run_buildah add $cid ${TESTDIR}/tarball3.tar.bz2
run_buildah add $cid ${TESTDIR}/tarball4.tar.bz2
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image
run_buildah rm $cid
run_buildah from --signature-policy ${TESTSDIR}/policy.json new-image
newcid=$output
run_buildah mount $newcid
newroot=$output
test -s $newroot/random1
cmp ${TESTDIR}/random1 $newroot/random1
test -s $newroot/random2
cmp ${TESTDIR}/random2 $newroot/random2
test -s $newroot/tarball2/tarball2.random1
cmp ${TESTDIR}/tarball2/tarball2.random1 $newroot/tarball2/tarball2.random1
test -s $newroot/tarball2/tarball2.random2
cmp ${TESTDIR}/tarball2/tarball2.random2 $newroot/tarball2/tarball2.random2
test -s $newroot/tarball3/tarball3.random1
cmp ${TESTDIR}/tarball3/tarball3.random1 $newroot/tarball3/tarball3.random1
test -s $newroot/tarball3/tarball3.random2
cmp ${TESTDIR}/tarball3/tarball3.random2 $newroot/tarball3/tarball3.random2
test -s $newroot/tarball4/tarball4.random1
cmp ${TESTDIR}/tarball4/tarball4.random1 $newroot/tarball4/tarball4.random1
test -s $newroot/tarball4/tarball4.random2
cmp ${TESTDIR}/tarball4/tarball4.random2 $newroot/tarball4/tarball4.random2
}
@test "add single file creates absolute path with correct permissions" {
_prefetch ubuntu
imgName=ubuntu-image
createrandom ${TESTDIR}/distutils.cfg
permission=$(stat -c "%a" ${TESTDIR}/distutils.cfg)
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json ubuntu
cid=$output
run_buildah add $cid ${TESTDIR}/distutils.cfg /usr/lib/python3.7/distutils
run_buildah run $cid stat -c "%a" /usr/lib/python3.7/distutils
expect_output $permission
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:${imgName}
run_buildah rm $cid
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json ${imgName}
newcid=$output
run_buildah run $newcid stat -c "%a" /usr/lib/python3.7/distutils
expect_output $permission
}
@test "add single file creates relative path with correct permissions" {
_prefetch ubuntu
imgName=ubuntu-image
createrandom ${TESTDIR}/distutils.cfg
permission=$(stat -c "%a" ${TESTDIR}/distutils.cfg)
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json ubuntu
cid=$output
run_buildah add $cid ${TESTDIR}/distutils.cfg lib/custom
run_buildah run $cid stat -c "%a" lib/custom
expect_output $permission
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:${imgName}
run_buildah rm $cid
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json ${imgName}
newcid=$output
run_buildah run $newcid stat -c "%a" lib/custom
expect_output $permission
}
@test "add with chown" {
_prefetch busybox
createrandom ${TESTDIR}/randomfile
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json busybox
cid=$output
run_buildah add --chown bin:bin $cid ${TESTDIR}/randomfile /tmp/random
run_buildah run $cid ls -l /tmp/random
expect_output --substring bin.*bin
}
@test "add url" {
_prefetch busybox
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json busybox
cid=$output
run_buildah add $cid https://github.com/containers/buildah/raw/master/README.md
run_buildah run $cid ls /README.md
run_buildah add $cid https://github.com/containers/buildah/raw/master/README.md /home
run_buildah run $cid ls /home/README.md
}
@test "add relative" {
# make sure we don't get thrown by relative source locations
_prefetch busybox
run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json busybox
cid=$output
run_buildah add $cid deny.json /
run_buildah run $cid ls /deny.json
run_buildah add $cid ./docker.json /
run_buildah run $cid ls /docker.json
run_buildah add $cid tools/Makefile /
run_buildah run $cid ls /Makefile
}
@test "add --ignore" {
mytest=${TESTDIR}/mytest
mkdir -p ${mytest}
touch ${mytest}/mystuff
touch ${mytest}/source.go
mkdir -p ${mytest}/notmystuff
touch ${mytest}/notmystuff/notmystuff
cat > ${mytest}/.ignore << _EOF
*.go
.ignore
notmystuff
_EOF
expect="
stuff
stuff/mystuff"
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah 125 copy --ignorefile ${mytest}/.ignore $cid ${mytest} /stuff
expect_output -- "--ignore options requires that you specify a context dir using --contextdir" "container file list"
run_buildah add --contextdir=${mytest} --ignorefile ${mytest}/.ignore $cid ${mytest} /stuff
run_buildah mount $cid
mnt=$output
run find $mnt -printf "%P\n"
filelist=$(LC_ALL=C sort <<<"$output")
run_buildah umount $cid
expect_output --from="$filelist" "$expect" "container file list"
}
|