Skip to content

Commit acf17f4

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 <[email protected]>
1 parent 029ed34 commit acf17f4

File tree

10 files changed

+78
-104
lines changed

10 files changed

+78
-104
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Needed by tmt
2+
rsync

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: 35 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,115 +4,63 @@ 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 "$TEST_OS" | cut -d '-' -f 1)
15+
OS_VERSION_ID=$(echo "$TEST_OS" | 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
9439
ssh-keygen -f "${SSH_KEY}" -N "" -q -t rsa-sha2-256 -b 2048
40+
chmod 600 "${SSH_KEY}"
9541

96-
truncate -s 10G "${BOOTC_TEMPDIR}/disk.raw"
42+
truncate -s 10G "target/disk.raw"
9743

9844
# For test-22-logically-bound-install
9945
podman pull --retry 5 --retry-delay 5s quay.io/curl/curl:latest
10046
podman pull --retry 5 --retry-delay 5s quay.io/curl/curl-base:latest
10147
podman pull --retry 5 --retry-delay 5s registry.access.redhat.com/ubi9/podman:latest
10248

49+
mkdir -p target/disks
50+
10351
podman run \
10452
--rm \
10553
--privileged \
10654
--pid=host \
10755
--security-opt label=type:unconfined_t \
10856
-v /var/lib/containers:/var/lib/containers \
10957
-v /dev:/dev \
110-
-v "$BOOTC_TEMPDIR":/output \
111-
"$LOCAL_IMAGE" \
58+
-v $(pwd)/target:/target \
59+
localhost/bootc-integration \
11260
bootc install to-disk \
11361
--filesystem "xfs" \
114-
--root-ssh-authorized-keys "/output/id_rsa.pub" \
62+
--root-ssh-authorized-keys "/target/id_rsa.pub" \
11563
--karg=console=ttyS0,115200n8 \
11664
--generic-image \
11765
--via-loopback \
118-
/output/disk.raw
66+
/target/disk.raw

tests/test.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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+
TMT_PLAN_NAME=$1
7+
shift
58

6-
BOOTC_TEMPDIR="/tmp/tmp-bootc-build"
79
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
8-
SSH_KEY=${BOOTC_TEMPDIR}/id_rsa
10+
SSH_KEY=target/id_rsa
11+
test -f $SSH_KEY
912

13+
# TODO replace with tmt's virt provisioner
1014
ARCH=$(uname -m)
1115
case "$ARCH" in
1216
"aarch64")
@@ -17,7 +21,7 @@ case "$ARCH" in
1721
-cpu host \
1822
-m 2G \
1923
-bios /usr/share/AAVMF/AAVMF_CODE.fd \
20-
-drive file="${BOOTC_TEMPDIR}/disk.raw",if=virtio,format=raw \
24+
-drive file="target/disk.raw",if=virtio,format=raw \
2125
-net nic,model=virtio \
2226
-net user,hostfwd=tcp::2222-:22 \
2327
-display none \
@@ -29,7 +33,7 @@ case "$ARCH" in
2933
-enable-kvm \
3034
-cpu host \
3135
-m 2G \
32-
-drive file="${BOOTC_TEMPDIR}/disk.raw",if=virtio,format=raw \
36+
-drive file="target/disk.raw",if=virtio,format=raw \
3337
-net nic,model=virtio \
3438
-net user,hostfwd=tcp::2222-:22 \
3539
-display none \

0 commit comments

Comments
 (0)