|
| 1 | +#!/bin/bash |
| 2 | +set -exuo pipefail |
| 3 | + |
| 4 | +# This script basically builds bootc from source using the provided base image, |
| 5 | +# then runs the target tests. |
| 6 | + |
| 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}" |
| 18 | + ;; |
| 19 | + "fedora") |
| 20 | + TIER1_IMAGE_URL="quay.io/fedora/fedora-bootc:${OS_VERSION_ID}" |
| 21 | + ;; |
| 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 |
| 79 | +
|
| 80 | +rm -rf /var/cache /var/lib/dnf |
| 81 | +EORUN |
| 82 | +CONTAINERFILEOF |
| 83 | + |
| 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" |
| 92 | + |
| 93 | +SSH_KEY=${BOOTC_TEMPDIR}/id_rsa |
| 94 | +ssh-keygen -f "${SSH_KEY}" -N "" -q -t rsa-sha2-256 -b 2048 |
| 95 | + |
| 96 | +truncate -s 10G "${BOOTC_TEMPDIR}/disk.raw" |
| 97 | + |
| 98 | +# For test-22-logically-bound-install |
| 99 | +podman pull --retry 5 --retry-delay 5s quay.io/curl/curl:latest |
| 100 | +podman pull --retry 5 --retry-delay 5s quay.io/curl/curl-base:latest |
| 101 | +podman pull --retry 5 --retry-delay 5s registry.access.redhat.com/ubi9/podman:latest |
| 102 | + |
| 103 | +podman run \ |
| 104 | + --rm \ |
| 105 | + --privileged \ |
| 106 | + --pid=host \ |
| 107 | + --security-opt label=type:unconfined_t \ |
| 108 | + -v /var/lib/containers:/var/lib/containers \ |
| 109 | + -v /dev:/dev \ |
| 110 | + -v "$BOOTC_TEMPDIR":/output \ |
| 111 | + "$LOCAL_IMAGE" \ |
| 112 | + bootc install to-disk \ |
| 113 | + --filesystem "xfs" \ |
| 114 | + --root-ssh-authorized-keys "/output/id_rsa.pub" \ |
| 115 | + --karg=console=ttyS0,115200n8 \ |
| 116 | + --generic-image \ |
| 117 | + --via-loopback \ |
| 118 | + /output/disk.raw |
0 commit comments