-
Notifications
You must be signed in to change notification settings - Fork 373
/
mktree.oci
executable file
·94 lines (82 loc) · 1.95 KB
/
mktree.oci
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
#!/bin/bash
#
# OCI-based mktree backend
set -e
PROGRAM=$(basename $0)
if [ "$PROGRAM" == "mktree" ]; then
# Running from build directory
CMAKE=yes
NATIVE=@MKTREE_NATIVE@
PODMAN=@PODMAN@
CONTEXT=@CMAKE_SOURCE_DIR@
else
# Running from source directory
CMAKE=no
NATIVE=no
PODMAN=${MKTREE_ENGINE:-podman}
CONTEXT=..
fi
if [ $NATIVE == yes ]; then
FROM="--from @OS_NAME@:@OS_VERSION@"
else
FROM=
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"
# Pass select options to $PODMAN
case "$1" in
# Useful for CI environments without a tty
--interactive=*) opts=$1; shift ;;
esac
# Don't keep the test artifacts around in non-cmake mode
if [ $CMAKE == no ]; then
set -- --log "$@"
vol=/srv
fi
$PODMAN run --privileged -it --rm --read-only --tmpfs /tmp -v $vol \
--workdir /srv -e ROOTLESS=$ROOTLESS $opts $IMAGE rpmtests "$@"
}
unshared()
{
[ $(id -u) != 0 ] && [ $NATIVE == yes ] || return 0
$PODMAN unshare $0 $CMD "$@"
exit
}
case $CMD in
build) unshared
# Build base image
$PODMAN build --target base -t $IMAGE/base $ARGS
# Add RPM install on top
[ -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)
$PODMAN commit -q $id $IMAGE
else
# Standalone build
$PODMAN build --target full -t $IMAGE $ARGS
fi
;;
check)
rpmtests "$@"
;;
atshell)
rpmtests --shell "$@"
;;
shell)
rpmtests --shell snapshot shell
;;
reset)
rpmtests --reset
;;
esac