Skip to content

Commit

Permalink
PoC
Browse files Browse the repository at this point in the history
Next: refactor
  • Loading branch information
dmnks committed Nov 18, 2024
1 parent 2001904 commit 3b1417b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/mktree.common
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ make_install()

mkdir -p $DESTDIR/usr/bin
cp @TESTPROG_NAMES@ $DESTDIR/usr/bin/
ln -s $script_dir/rpmtests.sh $DESTDIR/usr/bin/rpmtests
ln -sf $script_dir/rpmtests.sh $DESTDIR/usr/bin/rpmtests

mkdir -p $DESTDIR/$script_dir
cp rpmtests atlocal snapshot mktree.common $DESTDIR/$script_dir/
Expand Down
30 changes: 19 additions & 11 deletions tests/mktree.oci
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ fi

IMAGE=rpm
ARGS="-f Dockerfile $FROM $CONTEXT"
ROOTLESS=$([ $(id -u) == 0 ] && echo 0 || echo 1)
CMD=$1; shift

export ROOTLESS
source mktree.common

rpmtests()
{
local opts
local vol="$PWD:/srv:z"
local vol="$PWD:/srv"

# Pass select options to $PODMAN
case "$1" in
Expand All @@ -50,8 +48,18 @@ rpmtests()
vol=/srv
fi

$PODMAN run --privileged -it --rm --read-only --tmpfs /tmp -v $vol \
--workdir /srv -e ROOTLESS=$ROOTLESS $opts $IMAGE rpmtests "$@"
source ./snapshot
rm -rf $PWD/blah-img
mkdir -p $PWD/blah-img
chcon -Rt container_file_t $PWD
( cd $PWD/blah-img; podman create --name foo rpm; podman export foo | tar x; podman rm foo )
chmod -Rf u+rwX $PWD/blah-img
RPMTREE=$PWD/blah-rpm:$PWD/blah-img
RPMTEST=$PWD/blah-mnt
snapshot mount
$PODMAN run --privileged -it --read-only --tmpfs /tmp -v $vol \
--workdir /srv $opts --rootfs $RPMTEST rpmtests "$@"
snapshot umount
}

unshared()
Expand All @@ -67,28 +75,28 @@ case $CMD in
$PODMAN build --target base -t $IMAGE/base $ARGS

# Add RPM install on top
[ -n "$($PODMAN images -q $IMAGE)" ] && $PODMAN rmi $IMAGE
# [ -n "$($PODMAN images -q $IMAGE)" ] && $PODMAN rmi $IMAGE
if [ $NATIVE == yes ]; then
# Native build
id=$($PODMAN create $IMAGE/base)
trap "$PODMAN rm $id >/dev/null" EXIT
make_install $($PODMAN mount $id)
make_install $PWD/blah-rpm
$PODMAN commit -q $id $IMAGE
else
# Standalone build
$PODMAN build --target full -t $IMAGE $ARGS
fi
;;
check)
check) unshared "$@"
rpmtests "$@"
;;
atshell)
atshell) unshared "$@"
rpmtests --shell "$@"
;;
shell)
shell) unshared "$@"
rpmtests --shell snapshot shell
;;
reset)
reset) unshared
rpmtests --reset
;;
esac
3 changes: 2 additions & 1 deletion tests/snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ snapshot()
mkdir -p $1/diff $1/work
opts="-o upperdir=$1/diff,workdir=$1/work"
fi
[ ${ROOTLESS:-1} == 1 ] && opts+=" -o userxattr"
# [ ${ROOTLESS:-1} == 1 ] && opts+=" -o userxattr"
opts+=" -o userxattr"
mkdir -p ${RPMTEST}
mount -t overlay sandbox \
-o lowerdir="${RPMTREE}" \
Expand Down

0 comments on commit 3b1417b

Please sign in to comment.