|
| 1 | +#!/bin/bash |
| 2 | +set -exuo pipefail |
| 3 | + |
| 4 | +# Check environment |
| 5 | +printenv |
| 6 | + |
| 7 | +# This script only runs on Packit and gating environment |
| 8 | +# Do not run this script for image mode system |
| 9 | +if command -v bootc >/dev/null && bootc status --json | grep '"type":"bootcHost"'; then |
| 10 | + echo "This system is Image Mode." |
| 11 | + exit 0 |
| 12 | +fi |
| 13 | + |
| 14 | +# Install required packages |
| 15 | +dnf install -y podman skopeo jq bootc system-reinstall-bootc expect ansible-core |
| 16 | + |
| 17 | +# temp folder to save building files and folders |
| 18 | +BOOTC_TEMPDIR=$(mktemp -d) |
| 19 | +trap 'rm -rf -- "$BOOTC_TEMPDIR"' EXIT |
| 20 | + |
| 21 | +# Copy files and folders in hack to TEMPDIR |
| 22 | +cp -a . "$BOOTC_TEMPDIR" |
| 23 | + |
| 24 | +# Keep testing farm run folder |
| 25 | +cp -r /var/ARTIFACTS "$BOOTC_TEMPDIR" |
| 26 | + |
| 27 | +# Copy bootc repo |
| 28 | +cp -r /var/share/test-artifacts "$BOOTC_TEMPDIR" |
| 29 | + |
| 30 | +ARCH=$(uname -m) |
| 31 | +# Get OS info |
| 32 | +source /etc/os-release |
| 33 | + |
| 34 | +# Some rhts-*, rstrnt-* and tmt-* commands are in /usr/local/bin |
| 35 | +if [[ -d /var/lib/tmt/scripts ]]; then |
| 36 | + cp -r /var/lib/tmt/scripts "$BOOTC_TEMPDIR" |
| 37 | +else |
| 38 | + cp -r /usr/local/bin "$BOOTC_TEMPDIR" |
| 39 | +fi |
| 40 | + |
| 41 | +# Get base image URL |
| 42 | +TEST_OS="${ID}-${VERSION_ID}" |
| 43 | +BASE=$(cat os-image-map.json | jq --arg v "$TEST_OS" '.[$v]') |
| 44 | + |
| 45 | +if [[ "$ID" == "rhel" ]]; then |
| 46 | + # OSCI gating only |
| 47 | + CURRENT_COMPOSE_ID=$(skopeo inspect --no-tags --retry-times=5 --tls-verify=false "docker://${BASE}" | jq -r '.Labels."redhat.compose-id"') |
| 48 | + |
| 49 | + if [[ -n ${CURRENT_COMPOSE_ID} ]]; then |
| 50 | + if [[ ${CURRENT_COMPOSE_ID} == *-updates-* ]]; then |
| 51 | + BATCH_COMPOSE="updates/" |
| 52 | + else |
| 53 | + BATCH_COMPOSE="" |
| 54 | + fi |
| 55 | + else |
| 56 | + BATCH_COMPOSE="updates/" |
| 57 | + CURRENT_COMPOSE_ID=latest-RHEL-$VERSION_ID |
| 58 | + fi |
| 59 | + |
| 60 | + # use latest compose if specific compose is not accessible |
| 61 | + RC=$(curl -skIw '%{http_code}' -o /dev/null "http://${NIGHTLY_COMPOSE_SITE}/rhel-${VERSION_ID%%.*}/nightly/${BATCH_COMPOSE}RHEL-${VERSION_ID%%.*}/${CURRENT_COMPOSE_ID}/STATUS") |
| 62 | + if [[ $RC != "200" ]]; then |
| 63 | + CURRENT_COMPOSE_ID=latest-RHEL-${VERSION_ID%%} |
| 64 | + fi |
| 65 | + |
| 66 | + # generate rhel repo |
| 67 | + tee "${BOOTC_TEMPDIR}/rhel.repo" >/dev/null <<REPOEOF |
| 68 | +[rhel-baseos] |
| 69 | +name=baseos |
| 70 | +baseurl=http://${NIGHTLY_COMPOSE_SITE}/rhel-${VERSION_ID%%.*}/nightly/${BATCH_COMPOSE}RHEL-${VERSION_ID%%.*}/${CURRENT_COMPOSE_ID}/compose/BaseOS/${ARCH}/os/ |
| 71 | +enabled=1 |
| 72 | +gpgcheck=0 |
| 73 | +
|
| 74 | +[rhel-appstream] |
| 75 | +name=appstream |
| 76 | +baseurl=http://${NIGHTLY_COMPOSE_SITE}/rhel-${VERSION_ID%%.*}/nightly/${BATCH_COMPOSE}RHEL-${VERSION_ID%%.*}/${CURRENT_COMPOSE_ID}/compose/AppStream/${ARCH}/os/ |
| 77 | +enabled=1 |
| 78 | +gpgcheck=0 |
| 79 | +REPOEOF |
| 80 | + cp "${BOOTC_TEMPDIR}/rhel.repo" /etc/yum.repos.d |
| 81 | +fi |
| 82 | + |
| 83 | +# Fedora CI: https://github.com/fedora-ci/dist-git-pipeline/blob/master/Jenkinsfile#L145 |
| 84 | +# OSCI: https://gitlab.cee.redhat.com/osci-pipelines/dist-git-pipeline/-/blob/master/Jenkinsfile?ref_type=heads#L93 |
| 85 | +if [[ -v KOJI_TASK_ID ]] || [[ -v CI_KOJI_TASK_ID ]]; then |
| 86 | + # Just left those ls commands here to ring the bell for me when something changed |
| 87 | + echo "$TMT_SOURCE_DIR" |
| 88 | + ls -al "$TMT_SOURCE_DIR" |
| 89 | + ls -al "$TMT_SOURCE_DIR/SRPMS" |
| 90 | +fi |
| 91 | + |
| 92 | +ls -al /etc/yum.repos.d |
| 93 | +cat /etc/yum.repos.d/test-artifacts.repo |
| 94 | +ls -al /var/share/test-artifacts |
| 95 | + |
| 96 | +# copy bootc rpm repo into image building root |
| 97 | +cp /etc/yum.repos.d/test-artifacts.repo "$BOOTC_TEMPDIR" |
| 98 | + |
| 99 | +# Let's check things in hack folder |
| 100 | +ls -al "$BOOTC_TEMPDIR" "${BOOTC_TEMPDIR}/bin" |
| 101 | + |
| 102 | +# Do not use just because it's only available on Fedora, not on CS and RHEL |
| 103 | +podman build --jobs=4 --from "$BASE" -v "$BOOTC_TEMPDIR":/bootc-test:z -t localhost/bootc-integration -f "${BOOTC_TEMPDIR}/Containerfile.packit" "$BOOTC_TEMPDIR" |
| 104 | + |
| 105 | +# Keep these in sync with what's used in hack/lbi |
| 106 | +podman pull -q --retry 5 --retry-delay 5s quay.io/curl/curl:latest quay.io/curl/curl-base:latest registry.access.redhat.com/ubi9/podman:latest |
| 107 | + |
| 108 | +# Run system-reinstall-bootc |
| 109 | +# TODO make it more scriptable instead of expect + send |
| 110 | +./system-reinstall-bootc.exp |
0 commit comments