|
| 1 | +#!/bin/bash -xe |
| 2 | + |
| 3 | +# podman run -v /lib/modules/$(uname -r):/host/modules --privileged quay.io/ovirt/buildcontainer:el8stream |
| 4 | +echo custom modules: ${SUPERMIN_MODULES} |
| 5 | +echo custom kernel: ${SUPERMIN_KERNEL} |
| 6 | +echo extract install logs: ${EXTRACT_INSTALL_LOGS} |
| 7 | +echo final build: ${FINALBUILD} |
| 8 | + |
| 9 | +export EXPORTED_ARTIFACTS=${EXPORTED_ARTIFACTS:-$PWD/exported-artifacts} |
| 10 | + |
| 11 | +export LIBGUESTFS_BACKEND=direct |
| 12 | +export LIBGUESTFS_TMPDIR=/var/tmp |
| 13 | +export LIBGUESTFS_CACHEDIR=$LIBGUESTFS_TMPDIR |
| 14 | + |
| 15 | +on_exit() { |
| 16 | + ln -fv data/ovirt-node*.ks *.log "$EXPORTED_ARTIFACTS/" |
| 17 | + cleanup |
| 18 | +} |
| 19 | + |
| 20 | +trap on_exit EXIT |
| 21 | + |
| 22 | +prepare() { |
| 23 | + mkdir -p "$EXPORTED_ARTIFACTS" |
| 24 | + |
| 25 | + mknod /dev/kvm c 10 232 || : |
| 26 | + mknod /dev/vhost-net c 10 238 || : |
| 27 | + mkdir /dev/net || : |
| 28 | + mknod /dev/net/tun c 10 200 || : |
| 29 | + seq 0 9 | xargs -I {} mknod /dev/loop{} b 7 {} || : |
| 30 | + |
| 31 | + virsh list --name | xargs -rn1 virsh destroy || : |
| 32 | + virsh list --all --name | xargs -rn1 virsh undefine --remove-all-storage || : |
| 33 | + losetup -O BACK-FILE | grep -v BACK-FILE | grep iso$ | xargs -r umount -dvf ||: |
| 34 | + |
| 35 | + virt-host-validate ||: |
| 36 | + |
| 37 | + [ -f ${SUPERMIN_MODULES}/kernel/fs/squashfs/squashfs* ] || { echo missing squashfs module in ${SUPERMIN_MODULES}; exit 1; } |
| 38 | +} |
| 39 | + |
| 40 | +prepare_osinfo_db() { |
| 41 | + local osinfo_dir="/usr/share/osinfo/os/ovirt.org" |
| 42 | + mkdir -p ${osinfo_dir} |
| 43 | + cp data/ovirt-osinfo.xml ${osinfo_dir}/ovirt-4.xml |
| 44 | +} |
| 45 | + |
| 46 | +build() { |
| 47 | + dist="$(rpm --eval %{dist})" |
| 48 | + dist=${dist##.} |
| 49 | + |
| 50 | + case ${dist} in |
| 51 | + el8) |
| 52 | + prepare_osinfo_db |
| 53 | + export SSG_TARGET_XML=/usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml |
| 54 | + export SHIP_OVIRT_CONF=1 |
| 55 | + ./autogen.sh |
| 56 | + ;; |
| 57 | + el9) |
| 58 | + prepare_osinfo_db |
| 59 | + export SSG_TARGET_XML=/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml |
| 60 | + export SHIP_OVIRT_CONF=1 |
| 61 | + ./autogen.sh \ |
| 62 | + --with-distro=c9s \ |
| 63 | + --with-bootisourl=http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso |
| 64 | + ;; |
| 65 | + esac |
| 66 | + |
| 67 | + make squashfs & |
| 68 | + tail -f virt-install.log --pid=$! --retry ||: |
| 69 | + |
| 70 | + # move out anaconda build logs and export them for debugging |
| 71 | + [[ -n "$EXTRACT_INSTALL_LOGS" ]] && { |
| 72 | + tmpdir=$(mktemp -d) |
| 73 | + mkdir $EXPORTED_ARTIFACTS/image-logs |
| 74 | + mv ovirt-node-ng-image.squashfs.img{,.orig} |
| 75 | + unsquashfs ovirt-node-ng-image.squashfs.img.orig |
| 76 | + mount squashfs-root/LiveOS/rootfs.img $tmpdir |
| 77 | + mv $tmpdir/var/log/anaconda $EXPORTED_ARTIFACTS/image-logs/var_log_anaconda || : |
| 78 | + mv $tmpdir/root/*ks* $EXPORTED_ARTIFACTS/image-logs || : |
| 79 | + umount $tmpdir |
| 80 | + rmdir $tmpdir |
| 81 | + mksquashfs squashfs-root ovirt-node-ng-image.squashfs.img -noappend -comp xz |
| 82 | + } |
| 83 | + |
| 84 | +# don't push squashfs to exported-artifacts, |
| 85 | +# ovirt-node*.squashfs.img \ |
| 86 | + ln -fv \ |
| 87 | + *manifest* \ |
| 88 | + *unsigned* \ |
| 89 | + "$EXPORTED_ARTIFACTS/" |
| 90 | + |
| 91 | + |
| 92 | + make product.img rpm |
| 93 | + |
| 94 | +# don't push rpms to exported-artifacts, uploaded separately |
| 95 | +# tmp.repos/SRPMS/*.rpm \ |
| 96 | +# tmp.repos/RPMS/noarch/*.rpm \ |
| 97 | + ln -fv \ |
| 98 | + product.img \ |
| 99 | + "$EXPORTED_ARTIFACTS/" |
| 100 | + |
| 101 | +# skip old iso target relying on jenkins and skip the squashfs |
| 102 | +# make offline-installation-iso |
| 103 | +# mv -fv ovirt-node-ng-image.squashfs.img \ |
| 104 | +# ovirt-node-ng-image-$(date +%Y%m%d).squashfs.img |
| 105 | + |
| 106 | + make iso |
| 107 | +# do not push iso to exported-artifacts, uploaded separately |
| 108 | +# ln -fv \ |
| 109 | +# ovirt-node*.iso \ |
| 110 | +# "$EXPORTED_ARTIFACTS/" |
| 111 | + |
| 112 | +} |
| 113 | + |
| 114 | +cleanup() { |
| 115 | + # Kill qemu-kvm in case it has been left around. |
| 116 | + killall qemu-kvm ||: |
| 117 | + # Remove device-mapper files that were created by kpartx in LMC |
| 118 | + dmsetup ls | \ |
| 119 | + grep ^loop | \ |
| 120 | + awk '{print $1}' | \ |
| 121 | + xargs -r -I {} dmsetup remove -f --retry /dev/mapper/{} ||: |
| 122 | + |
| 123 | + # umount and detach |
| 124 | + losetup -O BACK-FILE | grep -v BACK-FILE | xargs -r umount -vdf ||: |
| 125 | + losetup -v -D ||: |
| 126 | +} |
| 127 | + |
| 128 | +fetch_remote() { |
| 129 | + local sshkey=$1 |
| 130 | + local addr=$2 |
| 131 | + local path=$3 |
| 132 | + local dest=$4 |
| 133 | + local compress=$5 |
| 134 | + |
| 135 | + scp -o "UserKnownHostsFile /dev/null" \ |
| 136 | + -o "StrictHostKeyChecking no" \ |
| 137 | + -i $sshkey -r root@$addr:$path $dest ||: |
| 138 | + |
| 139 | + [[ -n $compress ]] && { |
| 140 | + tar czf $dest.tgz $dest && mv $dest.tgz $EXPORTED_ARTIFACTS |
| 141 | + }||: |
| 142 | +} |
| 143 | + |
| 144 | +check_iso() { |
| 145 | + LOGDIR="${EXPORTED_ARTIFACTS}" ISO_INSTALL_TIMEOUT=40 ./scripts/node-setup/setup-node-appliance.sh \ |
| 146 | + -i ovirt-node*.iso \ |
| 147 | + -p ovirt > setup-iso.log 2>&1 || setup_rc=$? |
| 148 | + |
| 149 | + local name=$(grep available setup-iso.log | cut -d: -f1) |
| 150 | + local addr=$(grep -Po "(?<=at ).*" setup-iso.log) |
| 151 | + local wrkdir=$(grep -Po "(?<=WORKDIR: ).*" setup-iso.log) |
| 152 | + local sshkey="$wrkdir/sshkey-${name}" |
| 153 | + |
| 154 | + fetch_remote "$sshkey" "$addr" "/tmp" "init_tmp" "1" |
| 155 | + fetch_remote "$sshkey" "$addr" "/var/log" "init_var_log" "1" |
| 156 | + |
| 157 | + [[ $setup_rc -ne 0 ]] && { |
| 158 | + mv ovirt-node*.iso *.tgz $EXPORTED_ARTIFACTS |
| 159 | + echo "ISO install failed, exiting" |
| 160 | + exit 1 |
| 161 | + } |
| 162 | + |
| 163 | + cat *nodectl-check*.log |
| 164 | + |
| 165 | + status1=$(grep -Po "(?<=Status: ).*" *nodectl-check*.log) |
| 166 | + status2=$(grep Status network-check.log |cut -d' ' -f2) |
| 167 | + status3=$(test $(grep ansible_distribution_major_version *node-ansible-check.log |cut -d\" -f4) -eq "8" && echo "OK") |
| 168 | + |
| 169 | + [[ "$status1" == *OK* && "$status2" == *OK* && "$status3" == *OK* ]] || { |
| 170 | + echo "Invalid node status" |
| 171 | + exit 1 |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +prepare |
| 176 | +build |
| 177 | +# check_iso not working |
| 178 | + |
| 179 | +echo "Done." |
0 commit comments