2017-03-18 06:45:19 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
@test "run" {
|
|
|
|
if ! which runc ; then
|
|
|
|
skip
|
|
|
|
fi
|
2017-07-21 01:41:51 +08:00
|
|
|
runc --version
|
2017-03-18 06:45:19 +08:00
|
|
|
createrandom ${TESTDIR}/randomfile
|
2017-03-28 02:46:35 +08:00
|
|
|
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
|
2017-03-25 00:49:22 +08:00
|
|
|
root=$(buildah mount $cid)
|
|
|
|
buildah config $cid --workingdir /tmp
|
|
|
|
run buildah --debug=false run $cid pwd
|
2017-07-21 01:41:51 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2017-03-18 06:45:19 +08:00
|
|
|
[ "$output" = /tmp ]
|
2017-03-25 00:49:22 +08:00
|
|
|
buildah config $cid --workingdir /root
|
2017-03-18 06:45:19 +08:00
|
|
|
run buildah --debug=false run $cid pwd
|
2017-07-21 01:41:51 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2017-03-18 06:45:19 +08:00
|
|
|
[ "$output" = /root ]
|
|
|
|
cp ${TESTDIR}/randomfile $root/tmp/
|
|
|
|
buildah run $cid cp /tmp/randomfile /tmp/other-randomfile
|
|
|
|
test -s $root/tmp/other-randomfile
|
|
|
|
cmp ${TESTDIR}/randomfile $root/tmp/other-randomfile
|
2017-07-21 01:41:51 +08:00
|
|
|
|
|
|
|
buildah unmount $cid
|
|
|
|
buildah rm $cid
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "run--args" {
|
|
|
|
if ! which runc ; then
|
|
|
|
skip
|
|
|
|
fi
|
|
|
|
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
|
|
|
|
|
|
|
|
# This should fail, because buildah run doesn't have a -n flag.
|
|
|
|
run buildah --debug=false run $cid echo -n test
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
|
|
|
|
# This should succeed, because buildah run stops caring at the --, which is preserved as part of the command.
|
|
|
|
run buildah --debug=false run $cid echo -- -n test
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo :"$output":
|
|
|
|
[ "$output" = "-- -n test" ]
|
|
|
|
|
|
|
|
# This should succeed, because buildah run stops caring at the --, which is not part of the command.
|
|
|
|
run buildah --debug=false run $cid -- echo -n -- test
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo :"$output":
|
2017-07-18 05:09:30 +08:00
|
|
|
[ "$output" = "-- test" ]
|
2017-07-21 01:41:51 +08:00
|
|
|
|
|
|
|
# This should succeed, because buildah run stops caring at the --.
|
|
|
|
run buildah --debug=false run $cid -- echo -- -n test --
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo :"$output":
|
|
|
|
[ "$output" = "-- -n test --" ]
|
|
|
|
|
|
|
|
# This should succeed, because buildah run stops caring at the --.
|
|
|
|
run buildah --debug=false run $cid -- echo -n "test"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo :"$output":
|
2017-07-18 05:09:30 +08:00
|
|
|
[ "$output" = "test" ]
|
|
|
|
|
2017-03-24 04:45:35 +08:00
|
|
|
buildah rm $cid
|
2017-03-18 06:45:19 +08:00
|
|
|
}
|
2017-04-05 05:31:02 +08:00
|
|
|
|
2017-06-23 23:53:51 +08:00
|
|
|
@test "run-cmd" {
|
|
|
|
if ! which runc ; then
|
|
|
|
skip
|
|
|
|
fi
|
|
|
|
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
|
|
|
|
buildah config $cid --workingdir /tmp
|
|
|
|
|
|
|
|
buildah config $cid --entrypoint ""
|
|
|
|
buildah config $cid --cmd pwd
|
|
|
|
run buildah --debug=false run $cid
|
|
|
|
[ "$output" = /tmp ]
|
|
|
|
|
|
|
|
buildah config $cid --entrypoint echo
|
|
|
|
run buildah --debug=false run $cid
|
|
|
|
[ "$output" = pwd ]
|
|
|
|
|
|
|
|
buildah config $cid --cmd ""
|
|
|
|
run buildah --debug=false run $cid
|
|
|
|
[ "$output" = "" ]
|
|
|
|
|
|
|
|
buildah config $cid --entrypoint ""
|
|
|
|
run buildah --debug=false run $cid echo that-other-thing
|
|
|
|
[ "$output" = that-other-thing ]
|
|
|
|
|
|
|
|
buildah config $cid --cmd echo
|
|
|
|
run buildah --debug=false run $cid echo that-other-thing
|
|
|
|
[ "$output" = that-other-thing ]
|
|
|
|
|
|
|
|
buildah config $cid --entrypoint echo
|
|
|
|
run buildah --debug=false run $cid echo that-other-thing
|
|
|
|
[ "$output" = that-other-thing ]
|
|
|
|
|
|
|
|
buildah rm $cid
|
|
|
|
}
|
|
|
|
|
2017-04-05 05:31:02 +08:00
|
|
|
@test "run-user" {
|
|
|
|
if ! which runc ; then
|
|
|
|
skip
|
|
|
|
fi
|
|
|
|
eval $(go env)
|
|
|
|
echo CGO_ENABLED=${CGO_ENABLED}
|
|
|
|
if test "$CGO_ENABLED" -ne 1; then
|
|
|
|
skip
|
|
|
|
fi
|
|
|
|
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
|
|
|
|
root=$(buildah mount $cid)
|
|
|
|
|
|
|
|
testuser=jimbo
|
|
|
|
testgroup=jimbogroup
|
|
|
|
testuid=$RANDOM
|
|
|
|
testgid=$RANDOM
|
|
|
|
testgroupid=$RANDOM
|
|
|
|
echo "$testuser:x:$testuid:$testgid:Jimbo Jenkins:/home/$testuser:/bin/sh" >> $root/etc/passwd
|
|
|
|
echo "$testgroup:x:$testgroupid:" >> $root/etc/group
|
|
|
|
|
|
|
|
buildah config $cid -u ""
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = 0 ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = 0 ]
|
|
|
|
|
|
|
|
buildah config $cid -u ${testuser}
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = $testuid ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = $testgid ]
|
|
|
|
|
|
|
|
buildah config $cid -u ${testuid}
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = $testuid ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = $testgid ]
|
|
|
|
|
|
|
|
buildah config $cid -u ${testuser}:${testgroup}
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = $testuid ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = $testgroupid ]
|
|
|
|
|
|
|
|
buildah config $cid -u ${testuid}:${testgroup}
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = $testuid ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = $testgroupid ]
|
|
|
|
|
|
|
|
buildah config $cid -u ${testuser}:${testgroupid}
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = $testuid ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = $testgroupid ]
|
|
|
|
|
|
|
|
buildah config $cid -u ${testuid}:${testgroupid}
|
|
|
|
buildah run -- $cid id
|
|
|
|
run buildah --debug=false run -- $cid id -u
|
|
|
|
[ "$output" = $testuid ]
|
|
|
|
run buildah --debug=false run -- $cid id -g
|
|
|
|
[ "$output" = $testgroupid ]
|
|
|
|
|
|
|
|
buildah unmount $cid
|
|
|
|
buildah rm $cid
|
|
|
|
}
|
2017-09-21 19:39:39 +08:00
|
|
|
|
|
|
|
@test "run --hostname" {
|
|
|
|
if ! which runc ; then
|
|
|
|
skip
|
|
|
|
fi
|
|
|
|
runc --version
|
|
|
|
createrandom ${TESTDIR}/randomfile
|
|
|
|
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json fedora)
|
|
|
|
root=$(buildah mount $cid)
|
|
|
|
run buildah --debug=false run -- $cid dnf -y install hostname
|
2017-11-10 01:02:22 +08:00
|
|
|
echo "$output"
|
2017-09-21 19:39:39 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
run buildah --debug=false run $cid hostname
|
2017-11-10 01:02:22 +08:00
|
|
|
echo "$output"
|
2017-09-21 19:39:39 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" != "foobar" ]
|
|
|
|
run buildah --debug=false run --hostname foobar $cid hostname
|
2017-11-10 01:02:22 +08:00
|
|
|
echo "$output"
|
2017-09-21 19:39:39 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "foobar" ]
|
|
|
|
buildah unmount $cid
|
|
|
|
buildah rm $cid
|
|
|
|
}
|