Skip to content

Commit 22ee1d8

Browse files
committed
ci: Unify more of hack/ and tests/
A key thing for me is that the `Justfile` should be a one-stop shop for development of the project. It can't have everything but it should answer the basic questions of "how do I build and test this project". This aligns the recently added tmt-on-GHA flow a *bit* more closely with some of that. Biggest is to use the `just build-integration-test-image` as the canonical way to build a container image with our testing stuff in it; which uses our main Dockerfile Other cleanups: - Change the scripts to accept data via argv[1] and not environment - Drop the hardcoded testing directory and use `target/` as a generic build artifact dir Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 029ed34 commit 22ee1d8

File tree

10 files changed

+113
-124
lines changed

10 files changed

+113
-124
lines changed

.github/workflows/integration.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ jobs:
2323
- uses: actions/checkout@v4
2424

2525
- name: Build bootc and bootc image
26-
env:
27-
TEST_OS: ${{ matrix.test_os }}
28-
run: sudo -E TEST_OS=$TEST_OS tests/build.sh
26+
run: sudo tests/build.sh ${{ matrix.test_os }}
2927

3028
- name: Grant sudo user permission to archive files
3129
run: |
@@ -88,9 +86,7 @@ jobs:
8886
ls -l /dev/kvm
8987
9088
- name: Run test
91-
env:
92-
TMT_PLAN_NAME: ${{ matrix.tmt_plan }}
93-
run: chmod 600 /tmp/tmp-bootc-build/id_rsa && tests/test.sh
89+
run: tests/test.sh ${{ matrix.tmt_plan }}
9490

9591
- name: Archive TMT logs
9692
if: always()

hack/Containerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# This injects some extra testing stuff into our image
1+
# Build a container image that has extra testing stuff in it, such
2+
# as nushell, some preset logically bound images, etc. This expects
3+
# to create an image derived FROM localhost/bootc which was created
4+
# by the Dockerfile at top.
25

36
FROM scratch as context
47
# We only need this stuff in the initial context
@@ -11,7 +14,15 @@ ARG variant=
1114
# And this layer has additional stuff for testing, such as nushell etc.
1215
RUN --mount=type=bind,from=context,target=/run/context <<EORUN
1316
set -xeuo pipefail
14-
/run/context/hack/provision-derived.sh "$variant"
17+
cd /run/context/hack
18+
./provision-derived.sh "$variant"
19+
20+
# For test-22-logically-bound-install
21+
cp -a lbi/usr/. /usr
22+
for x in curl.container curl-base.image podman.image; do
23+
ln -s /usr/share/containers/systemd/$x /usr/lib/bootc/bound-images.d/$x
24+
done
25+
1526
# Add some testing kargs into our dev builds
1627
install -D -t /usr/lib/bootc/kargs.d /run/context/hack/test-kargs/*
1728
# Also copy in some default install configs we use for testing
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Image]
2+
Image=quay.io/curl/curl-base:latest
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Container]
2+
Image=quay.io/curl/curl:latest
3+
GlobalArgs=--storage-opt=additionalimagestore=/usr/lib/bootc/storage
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This is not symlinked to bound-images.d so it should not be pulled.
2+
# It's here to represent an app image that exists
3+
# in a bootc image but is not logically bound.
4+
[Image]
5+
Image=registry.redhat.io/jboss-webserver-5/jws5-rhel8-operator:latest
6+
AuthFile=/root/auth.json
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Image]
2+
Image=registry.access.redhat.com/ubi9/podman:latest

hack/packages.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Needed by tmt
2+
rsync
3+
/usr/bin/flock
4+
/usr/bin/awk

hack/provision-derived.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ case "${ID}-${VERSION_ID}" in
1515
"centos-9")
1616
dnf config-manager --set-enabled crb
1717
dnf -y install epel-release epel-next-release
18-
dnf -y install nu
19-
dnf clean all
2018
;;
2119
"rhel-9."*)
2220
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
2321
dnf -y install nu
24-
dnf clean all
2522
;;
2623
"centos-10"|"rhel-10."*)
2724
# nu is not available in CS10
@@ -32,10 +29,13 @@ case "${ID}-${VERSION_ID}" in
3229
;;
3330
"fedora-"*)
3431
dnf -y install nu
35-
dnf clean all
3632
;;
3733
esac
3834

35+
# Extra packages we install
36+
grep -Ev -e '^#' packages.txt | xargs dnf -y install
37+
dnf clean all
38+
3939
# Stock extra cleaning of logs and caches in general (mostly dnf)
4040
rm /var/log/* /var/cache /var/lib/{dnf,rpm-state,rhsm} -rf
4141
# And clean root's homedir

tests/build.sh

Lines changed: 37 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,115 +4,65 @@ set -exuo pipefail
44
# This script basically builds bootc from source using the provided base image,
55
# then runs the target tests.
66

7-
mkdir -p /tmp/tmp-bootc-build
8-
BOOTC_TEMPDIR="/tmp/tmp-bootc-build"
9-
10-
# Get OS info from TEST_OS env
11-
OS_ID=$(echo "$TEST_OS" | cut -d '-' -f 1)
12-
OS_VERSION_ID=$(echo "$TEST_OS" | cut -d '-' -f 2)
13-
14-
# Base image
15-
case "$OS_ID" in
16-
"centos")
17-
TIER1_IMAGE_URL="quay.io/centos-bootc/centos-bootc:stream${OS_VERSION_ID}"
7+
# If provided should be of the form fedora-42 or centos-10
8+
target=${1:-}
9+
10+
build_args=()
11+
if test -n "${target:-}"; then
12+
shift
13+
# Get OS info from TEST_OS env
14+
OS_ID=$(echo "$target" | cut -d '-' -f 1)
15+
OS_VERSION_ID=$(echo "$target" | cut -d '-' -f 2)
16+
17+
# Base image
18+
case "$OS_ID" in
19+
"centos")
20+
BASE="quay.io/centos-bootc/centos-bootc:stream${OS_VERSION_ID}"
1821
;;
19-
"fedora")
20-
TIER1_IMAGE_URL="quay.io/fedora/fedora-bootc:${OS_VERSION_ID}"
22+
"fedora")
23+
BASE="quay.io/fedora/fedora-bootc:${OS_VERSION_ID}"
2124
;;
22-
esac
23-
24-
CONTAINERFILE="${BOOTC_TEMPDIR}/Containerfile"
25-
tee "$CONTAINERFILE" > /dev/null << CONTAINERFILEOF
26-
FROM $TIER1_IMAGE_URL as build
27-
28-
WORKDIR /code
29-
30-
RUN <<EORUN
31-
set -xeuo pipefail
32-
. /usr/lib/os-release
33-
case \$ID in
34-
centos|rhel) dnf config-manager --set-enabled crb;;
35-
fedora) dnf -y install dnf-utils 'dnf5-command(builddep)';;
36-
esac
37-
dnf -y builddep contrib/packaging/bootc.spec
38-
dnf -y install git-core
39-
EORUN
40-
41-
RUN mkdir -p /build/target/dev-rootfs
42-
# git config --global --add safe.directory /code to fix "fatal: detected dubious ownership in repository at '/code'" error
43-
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome git config --global --add safe.directory /code && make test-bin-archive && mkdir -p /out && cp target/bootc.tar.zst /out
44-
45-
FROM $TIER1_IMAGE_URL
46-
47-
# Inject our built code
48-
COPY --from=build /out/bootc.tar.zst /tmp
49-
RUN tar -C / --zstd -xvf /tmp/bootc.tar.zst && rm -vrf /tmp/*
50-
51-
RUN <<EORUN
52-
set -xeuo pipefail
53-
54-
# Provision test requirement
55-
/code/hack/provision-derived.sh
56-
# Also copy in some default install configs we use for testing
57-
cp -a /code/hack/install-test-configs/* /usr/lib/bootc/install/
58-
# And some test kargs
59-
cp -a /code/hack/test-kargs/* /usr/lib/bootc/kargs.d/
60-
61-
# For testing farm
62-
mkdir -p -m 0700 /var/roothome
63-
64-
# Enable ttyS0 console
65-
mkdir -p /usr/lib/bootc/kargs.d/
66-
cat <<KARGEOF >> /usr/lib/bootc/kargs.d/20-console.toml
67-
kargs = ["console=ttyS0,115200n8"]
68-
KARGEOF
69-
70-
# For test-22-logically-bound-install
71-
cp -a /code/tmt/tests/lbi/usr/. /usr
72-
ln -s /usr/share/containers/systemd/curl.container /usr/lib/bootc/bound-images.d/curl.container
73-
ln -s /usr/share/containers/systemd/curl-base.image /usr/lib/bootc/bound-images.d/curl-base.image
74-
ln -s /usr/share/containers/systemd/podman.image /usr/lib/bootc/bound-images.d/podman.image
75-
76-
# Install rsync which is required by tmt
77-
dnf -y install cloud-init rsync
78-
dnf -y clean all
25+
*) echo "Unknown OS: ${OS_ID}" 1>&2; exit 1
26+
;;
27+
esac
28+
build_args+=("--build-arg=base=$BASE")
29+
fi
7930

80-
rm -rf /var/cache /var/lib/dnf
81-
EORUN
82-
CONTAINERFILEOF
31+
just build ${build_args[@]}
32+
just build-integration-test-image
8333

84-
LOCAL_IMAGE="localhost/bootc:test"
85-
podman build \
86-
--retry 5 \
87-
--retry-delay 5s \
88-
-v "$(pwd)":/code:z \
89-
-t "$LOCAL_IMAGE" \
90-
-f "$CONTAINERFILE" \
91-
"$BOOTC_TEMPDIR"
34+
# Host builds will have this already, but we use it as a general dumping space
35+
# for output artifacts
36+
mkdir -p target
9237

93-
SSH_KEY=${BOOTC_TEMPDIR}/id_rsa
38+
SSH_KEY=$(pwd)/target/id_rsa
39+
rm -vf "${SSH_KEY}"*
9440
ssh-keygen -f "${SSH_KEY}" -N "" -q -t rsa-sha2-256 -b 2048
41+
chmod 600 "${SSH_KEY}"
9542

96-
truncate -s 10G "${BOOTC_TEMPDIR}/disk.raw"
43+
rm -vf target/disk.raw
44+
truncate -s 10G "target/disk.raw"
9745

9846
# For test-22-logically-bound-install
9947
podman pull --retry 5 --retry-delay 5s quay.io/curl/curl:latest
10048
podman pull --retry 5 --retry-delay 5s quay.io/curl/curl-base:latest
10149
podman pull --retry 5 --retry-delay 5s registry.access.redhat.com/ubi9/podman:latest
10250

51+
mkdir -p target/disks
52+
10353
podman run \
10454
--rm \
10555
--privileged \
10656
--pid=host \
10757
--security-opt label=type:unconfined_t \
10858
-v /var/lib/containers:/var/lib/containers \
10959
-v /dev:/dev \
110-
-v "$BOOTC_TEMPDIR":/output \
111-
"$LOCAL_IMAGE" \
60+
-v $(pwd)/target:/target \
61+
localhost/bootc-integration \
11262
bootc install to-disk \
11363
--filesystem "xfs" \
114-
--root-ssh-authorized-keys "/output/id_rsa.pub" \
64+
--root-ssh-authorized-keys "/target/id_rsa.pub" \
11565
--karg=console=ttyS0,115200n8 \
11666
--generic-image \
11767
--via-loopback \
118-
/output/disk.raw
68+
/target/disk.raw

tests/test.sh

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
11
#!/bin/bash
22
set -exuo pipefail
33

4-
# This script runs disk image with qemu-system and run tmt against this vm.
4+
# You must have invoked test/build.sh before running this.
5+
6+
# Put ourself in a user+mount+pid namespace to close leaks
7+
if test -z "${test_unshared:-}"; then
8+
exec unshare -m -- env test_unshared=1 "$0" "$@"
9+
fi
10+
11+
TMT_PLAN_NAME=$1
12+
shift
513

6-
BOOTC_TEMPDIR="/tmp/tmp-bootc-build"
714
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
8-
SSH_KEY=${BOOTC_TEMPDIR}/id_rsa
15+
SSH_KEY=$(pwd)/target/id_rsa
16+
test -f $SSH_KEY
917

18+
# TODO replace with tmt's virt provisioner
1019
ARCH=$(uname -m)
20+
qemu_args=()
1121
case "$ARCH" in
1222
"aarch64")
13-
qemu-system-aarch64 \
14-
-name bootc-vm \
15-
-enable-kvm \
16-
-machine virt \
17-
-cpu host \
18-
-m 2G \
19-
-bios /usr/share/AAVMF/AAVMF_CODE.fd \
20-
-drive file="${BOOTC_TEMPDIR}/disk.raw",if=virtio,format=raw \
21-
-net nic,model=virtio \
22-
-net user,hostfwd=tcp::2222-:22 \
23-
-display none \
24-
-daemonize
23+
qemu_args+=(qemu-system-aarch64
24+
-machine virt
25+
-bios /usr/share/AAVMF/AAVMF_CODE.fd)
2526
;;
2627
"x86_64")
27-
qemu-system-x86_64 \
28-
-name bootc-vm \
29-
-enable-kvm \
30-
-cpu host \
31-
-m 2G \
32-
-drive file="${BOOTC_TEMPDIR}/disk.raw",if=virtio,format=raw \
33-
-net nic,model=virtio \
34-
-net user,hostfwd=tcp::2222-:22 \
35-
-display none \
36-
-daemonize
28+
qemu_args+=(qemu-system-x86_64)
3729
;;
3830
*)
3931
echo "Only support x86_64 and aarch64" >&2
4032
exit 1
4133
;;
4234
esac
35+
qemu_args+=(
36+
-name bootc-vm \
37+
-enable-kvm \
38+
-cpu host \
39+
-m 2G \
40+
-drive file="target/disk.raw",if=virtio,format=raw
41+
-net nic,model=virtio
42+
-net user,hostfwd=tcp::2222-:22
43+
-display none
44+
)
45+
46+
# Kill qemu when the test exits by default
47+
setpriv --pdeathsig SIGTERM -- ${qemu_args[@]} &>/dev/null &
4348

4449
wait_for_ssh_up() {
4550
SSH_STATUS=$(ssh "${SSH_OPTIONS[@]}" -i "$SSH_KEY" -p 2222 root@"${1}" '/bin/bash -c "echo -n READY"')
@@ -66,5 +71,15 @@ ssh "${SSH_OPTIONS[@]}" \
6671
root@localhost \
6772
"bootc status"
6873

74+
# First a tremendous hackaround for tmt blindly rsync'ing all of .
75+
# including the target/ directory
76+
rm target/stub -rf
77+
mkdir -p target/stub
78+
ls -al $SSH_KEY
79+
touch -m 0600 target/stub/$(basename $SSH_KEY)
80+
mount --bind $SSH_KEY target/stub/$(basename $SSH_KEY)
81+
mount --rbind target/stub target
82+
ls -al "$SSH_KEY"
83+
6984
# TMT will rsync tmt-* scripts to TMT_SCRIPTS_DIR=/var/lib/tmt/scripts
7085
tmt run --all --verbose -e TMT_SCRIPTS_DIR=/var/lib/tmt/scripts provision --how connect --guest localhost --port 2222 --user root --key "$SSH_KEY" plan --name "/tmt/plans/bootc-integration/${TMT_PLAN_NAME}"

0 commit comments

Comments
 (0)