|
Packit |
63bb0d |
#!/bin/bash
|
|
Packit |
63bb0d |
set -euxo pipefail
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
# The project whose -tests package is installed.
|
|
Packit Service |
509fd4 |
#
|
|
Packit Service |
509fd4 |
# If it is osbuild-composer (the default), it is pulled from the same
|
|
Packit Service |
509fd4 |
# repository as the osbuild-composer under test. For all other projects, the
|
|
Packit Service |
509fd4 |
# "dependants" key in Schutzfile is consulted to determine the repository to
|
|
Packit Service |
509fd4 |
# pull the -test package from.
|
|
Packit Service |
509fd4 |
PROJECT=${1:-osbuild-composer}
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
# Colorful output.
|
|
Packit Service |
509fd4 |
function greenprint {
|
|
Packit Service |
509fd4 |
echo -e "\033[1;32m${1}\033[0m"
|
|
Packit Service |
509fd4 |
}
|
|
Packit Service |
509fd4 |
|
|
Packit |
63bb0d |
function retry {
|
|
Packit |
63bb0d |
local count=0
|
|
Packit |
63bb0d |
local retries=5
|
|
Packit |
63bb0d |
until "$@"; do
|
|
Packit |
63bb0d |
exit=$?
|
|
Packit Service |
509fd4 |
count=$((count + 1))
|
|
Packit |
63bb0d |
if [[ $count -lt $retries ]]; then
|
|
Packit |
63bb0d |
echo "Retrying command..."
|
|
Packit |
63bb0d |
sleep 1
|
|
Packit |
63bb0d |
else
|
|
Packit |
63bb0d |
echo "Command failed after ${retries} retries. Giving up."
|
|
Packit |
63bb0d |
return $exit
|
|
Packit |
63bb0d |
fi
|
|
Packit |
63bb0d |
done
|
|
Packit |
63bb0d |
return 0
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
function setup_repo {
|
|
Packit Service |
509fd4 |
local project=$1
|
|
Packit Service |
509fd4 |
local commit=$2
|
|
Packit Service |
509fd4 |
local priority=${3:-10}
|
|
Packit Service |
509fd4 |
greenprint "Setting up dnf repository for ${project} ${commit}"
|
|
Packit Service |
509fd4 |
sudo tee "/etc/yum.repos.d/${project}.repo" << EOF
|
|
Packit Service |
509fd4 |
[${project}]
|
|
Packit Service |
509fd4 |
name=${project} ${commit}
|
|
Packit Service |
509fd4 |
baseurl=http://osbuild-composer-repos.s3-website.us-east-2.amazonaws.com/${project}/${ID}-${VERSION_ID}/${ARCH}/${commit}
|
|
Packit Service |
509fd4 |
enabled=1
|
|
Packit Service |
509fd4 |
gpgcheck=0
|
|
Packit Service |
509fd4 |
priority=${priority}
|
|
Packit Service |
509fd4 |
EOF
|
|
Packit Service |
509fd4 |
}
|
|
Packit Service |
509fd4 |
|
|
Packit |
63bb0d |
# Get OS details.
|
|
Packit |
63bb0d |
source /etc/os-release
|
|
Packit Service |
509fd4 |
ARCH=$(uname -m)
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
if [[ -n "${RHN_REGISTRATION_SCRIPT:-}" ]] && ! sudo subscription-manager status; then
|
|
Packit Service |
509fd4 |
greenprint "Registering RHEL"
|
|
Packit Service |
509fd4 |
sudo chmod +x "$RHN_REGISTRATION_SCRIPT"
|
|
Packit Service |
509fd4 |
sudo "$RHN_REGISTRATION_SCRIPT"
|
|
Packit |
63bb0d |
fi
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
greenprint "Enabling fastestmirror to speed up dnf ðï¸"
|
|
Packit Service |
509fd4 |
echo -e "fastestmirror=1" | sudo tee -a /etc/dnf/dnf.conf
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
greenprint "Adding osbuild team ssh keys"
|
|
Packit Service |
509fd4 |
cat schutzbot/team_ssh_keys.txt | tee -a ~/.ssh/authorized_keys > /dev/null
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
# TODO: include this in the jenkins runner (and split test/target machines out)
|
|
Packit Service |
509fd4 |
sudo dnf -y install jq
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
setup_repo osbuild-composer "${GIT_COMMIT}" 5
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
OSBUILD_GIT_COMMIT=$(cat Schutzfile | jq -r '.["'"${ID}-${VERSION_ID}"'"].dependencies.osbuild.commit')
|
|
Packit Service |
509fd4 |
if [[ "${OSBUILD_GIT_COMMIT}" != "null" ]]; then
|
|
Packit Service |
509fd4 |
setup_repo osbuild "${OSBUILD_GIT_COMMIT}" 10
|
|
Packit |
63bb0d |
fi
|
|
Packit |
63bb0d |
|
|
Packit Service |
509fd4 |
if [[ "$PROJECT" != "osbuild-composer" ]]; then
|
|
Packit Service |
509fd4 |
PROJECT_COMMIT=$(jq -r ".[\"${ID}-${VERSION_ID}\"].dependants[\"${PROJECT}\"].commit" Schutzfile)
|
|
Packit Service |
509fd4 |
setup_repo "${PROJECT}" "${PROJECT_COMMIT}" 10
|
|
Packit |
63bb0d |
|
|
Packit Service |
3a6627 |
# Get a list of packages needed to be preinstalled before "${PROJECT}-tests".
|
|
Packit Service |
3a6627 |
# Useful mainly for EPEL.
|
|
Packit Service |
3a6627 |
PRE_INSTALL_PACKAGES=$(jq -r ".[\"${ID}-${VERSION_ID}\"].dependants[\"${PROJECT}\"].pre_install_packages[]?" Schutzfile)
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
if [ "${PRE_INSTALL_PACKAGES}" ]; then
|
|
Packit Service |
3a6627 |
# shellcheck disable=SC2086 # We need to pass multiple arguments here.
|
|
Packit Service |
3a6627 |
sudo dnf -y install ${PRE_INSTALL_PACKAGES}
|
|
Packit Service |
3a6627 |
fi
|
|
Packit Service |
509fd4 |
fi
|
|
Packit |
63bb0d |
|
|
Packit Service |
bcdfb1 |
if [ -f "rhel8nightly.repo" ]; then
|
|
Packit Service |
bcdfb1 |
greenprint "Preparing repos for nightly build testing"
|
|
Packit Service |
bcdfb1 |
sudo mv rhel8nightly.repo /etc/yum.repos.d/
|
|
Packit Service |
bcdfb1 |
sudo rm -f /etc/yum.repos.d/osbuild*.repo
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
509fd4 |
greenprint "Installing test packages for ${PROJECT}"
|
|
Packit |
63bb0d |
# Note: installing only -tests to catch missing dependencies
|
|
Packit Service |
509fd4 |
retry sudo dnf -y install "${PROJECT}-tests"
|