|
Packit Service |
bcdfb1 |
#!/bin/bash
|
|
Packit Service |
bcdfb1 |
set -euo pipefail
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
# Provision the software under tet.
|
|
Packit Service |
15f37d |
/usr/libexec/osbuild-composer-test/provision.sh
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get OS data.
|
|
Packit Service |
bcdfb1 |
source /etc/os-release
|
|
Packit Service |
bcdfb1 |
ARCH=$(uname -m)
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
# Do not use httpd, but container
|
|
Packit Service |
15f37d |
sudo systemctl disable --now httpd
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Colorful output.
|
|
Packit Service |
bcdfb1 |
function greenprint {
|
|
Packit Service |
bcdfb1 |
echo -e "\033[1;32m${1}\033[0m"
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Start libvirtd and test it.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Starting libvirt daemon"
|
|
Packit Service |
bcdfb1 |
sudo systemctl start libvirtd
|
|
Packit Service |
bcdfb1 |
sudo virsh list --all > /dev/null
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Set a customized dnsmasq configuration for libvirt so we always get the
|
|
Packit Service |
bcdfb1 |
# same address on bootup.
|
|
Packit Service |
bcdfb1 |
sudo tee /tmp/integration.xml > /dev/null << EOF
|
|
Packit Service |
bcdfb1 |
<network>
|
|
Packit Service |
bcdfb1 |
<name>integration</name>
|
|
Packit Service |
bcdfb1 |
<uuid>1c8fe98c-b53a-4ca4-bbdb-deb0f26b3579</uuid>
|
|
Packit Service |
bcdfb1 |
<forward mode='nat'>
|
|
Packit Service |
bcdfb1 |
<nat>
|
|
Packit Service |
bcdfb1 |
<port start='1024' end='65535'/>
|
|
Packit Service |
bcdfb1 |
</nat>
|
|
Packit Service |
bcdfb1 |
</forward>
|
|
Packit Service |
bcdfb1 |
<bridge name='integration' stp='on' delay='0'/>
|
|
Packit Service |
bcdfb1 |
<mac address='52:54:00:36:46:ef'/>
|
|
Packit Service |
bcdfb1 |
<ip address='192.168.100.1' netmask='255.255.255.0'>
|
|
Packit Service |
bcdfb1 |
<dhcp>
|
|
Packit Service |
bcdfb1 |
<range start='192.168.100.2' end='192.168.100.254'/>
|
|
Packit Service |
bcdfb1 |
<host mac='34:49:22:B0:83:30' name='vm' ip='192.168.100.50'/>
|
|
Packit Service |
bcdfb1 |
</dhcp>
|
|
Packit Service |
bcdfb1 |
</ip>
|
|
Packit Service |
bcdfb1 |
</network>
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
if ! sudo virsh net-info integration > /dev/null 2>&1; then
|
|
Packit Service |
bcdfb1 |
sudo virsh net-define /tmp/integration.xml
|
|
Packit Service |
bcdfb1 |
sudo virsh net-start integration
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Allow anyone in the wheel group to talk to libvirt.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ช Allowing users in wheel group to talk to libvirt"
|
|
Packit Service |
bcdfb1 |
sudo tee /etc/polkit-1/rules.d/50-libvirt.rules > /dev/null << EOF
|
|
Packit Service |
bcdfb1 |
polkit.addRule(function(action, subject) {
|
|
Packit Service |
bcdfb1 |
if (action.id == "org.libvirt.unix.manage" &&
|
|
Packit Service |
15f37d |
subject.isInGroup("adm")) {
|
|
Packit Service |
bcdfb1 |
return polkit.Result.YES;
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
});
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Set up variables.
|
|
Packit Service |
15f37d |
OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/
|
|
Packit Service |
464a89 |
OSTREE_REF="test/rhel/8/${ARCH}/edge"
|
|
Packit Service |
15f37d |
OS_VARIANT="rhel8-unknown"
|
|
Packit Service |
bcdfb1 |
TEST_UUID=$(uuidgen)
|
|
Packit Service |
bcdfb1 |
IMAGE_KEY="osbuild-composer-ostree-test-${TEST_UUID}"
|
|
Packit Service |
bcdfb1 |
GUEST_ADDRESS=192.168.100.50
|
|
Packit Service |
15f37d |
URL=http://192.168.100.1/repo/
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Set up temporary files.
|
|
Packit Service |
bcdfb1 |
TEMPDIR=$(mktemp -d)
|
|
Packit Service |
bcdfb1 |
BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml
|
|
Packit Service |
bcdfb1 |
KS_FILE=${TEMPDIR}/ks.cfg
|
|
Packit Service |
bcdfb1 |
COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json
|
|
Packit Service |
bcdfb1 |
COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# SSH setup.
|
|
Packit Service |
bcdfb1 |
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
|
|
Packit Service |
bcdfb1 |
SSH_KEY=${OSBUILD_COMPOSER_TEST_DATA}keyring/id_rsa
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get the compose log.
|
|
Packit Service |
bcdfb1 |
get_compose_log () {
|
|
Packit Service |
bcdfb1 |
COMPOSE_ID=$1
|
|
Packit Service |
bcdfb1 |
LOG_FILE=${WORKSPACE}/osbuild-${ID}-${VERSION_ID}-${COMPOSE_ID}.log
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Download the logs.
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose log "$COMPOSE_ID" | tee "$LOG_FILE" > /dev/null
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get the compose metadata.
|
|
Packit Service |
bcdfb1 |
get_compose_metadata () {
|
|
Packit Service |
bcdfb1 |
COMPOSE_ID=$1
|
|
Packit Service |
bcdfb1 |
METADATA_FILE=${WORKSPACE}/osbuild-${ID}-${VERSION_ID}-${COMPOSE_ID}.json
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Download the metadata.
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose metadata "$COMPOSE_ID" > /dev/null
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Find the tarball and extract it.
|
|
Packit Service |
bcdfb1 |
TARBALL=$(basename "$(find . -maxdepth 1 -type f -name "*-metadata.tar")")
|
|
Packit Service |
bcdfb1 |
tar -xf "$TARBALL" -C "${TEMPDIR}"
|
|
Packit Service |
bcdfb1 |
rm -f "$TARBALL"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Move the JSON file into place.
|
|
Packit Service |
bcdfb1 |
cat "${TEMPDIR}"/"${COMPOSE_ID}".json | jq -M '.' | tee "$METADATA_FILE" > /dev/null
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Build ostree image.
|
|
Packit Service |
bcdfb1 |
build_image() {
|
|
Packit Service |
15f37d |
blueprint_name=$1
|
|
Packit Service |
15f37d |
image_type=$2
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get worker unit file so we can watch the journal.
|
|
Packit Service |
bcdfb1 |
WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service")
|
|
Packit Service |
bcdfb1 |
sudo journalctl -af -n 1 -u "${WORKER_UNIT}" &
|
|
Packit Service |
bcdfb1 |
WORKER_JOURNAL_PID=$!
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Start the compose.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Starting compose"
|
|
Packit Service |
15f37d |
if [ $# -eq 3 ]; then
|
|
Packit Service |
15f37d |
repo_url=$3
|
|
Packit Service |
bcdfb1 |
sudo curl --silent --header "Content-Type: application/json" --unix-socket /run/weldr/api.socket http://localhost/api/v1/compose --data "{
|
|
Packit Service |
bcdfb1 |
\"blueprint_name\": \"$blueprint_name\",
|
|
Packit Service |
15f37d |
\"compose_type\": \"$image_type\",
|
|
Packit Service |
bcdfb1 |
\"ostree\": {
|
|
Packit Service |
15f37d |
\"url\": \"$repo_url\",
|
|
Packit Service |
bcdfb1 |
\"ref\": \"$OSTREE_REF\"
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
}" | tee "$COMPOSE_START"
|
|
Packit Service |
bcdfb1 |
else
|
|
Packit Service |
bcdfb1 |
sudo curl --silent --header "Content-Type: application/json" --unix-socket /run/weldr/api.socket http://localhost/api/v1/compose --data "{
|
|
Packit Service |
bcdfb1 |
\"blueprint_name\": \"$blueprint_name\",
|
|
Packit Service |
464a89 |
\"compose_type\": \"$image_type\",
|
|
Packit Service |
464a89 |
\"ostree\": {
|
|
Packit Service |
464a89 |
\"ref\": \"$OSTREE_REF\"
|
|
Packit Service |
464a89 |
}
|
|
Packit Service |
bcdfb1 |
}" | tee "$COMPOSE_START"
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START")
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Wait for the compose to finish.
|
|
Packit Service |
bcdfb1 |
greenprint "โฑ Waiting for compose to finish: ${COMPOSE_ID}"
|
|
Packit Service |
bcdfb1 |
while true; do
|
|
Packit Service |
bcdfb1 |
sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null
|
|
Packit Service |
bcdfb1 |
COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO")
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Is the compose finished?
|
|
Packit Service |
bcdfb1 |
if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then
|
|
Packit Service |
bcdfb1 |
break
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Wait 30 seconds and try again.
|
|
Packit Service |
bcdfb1 |
sleep 5
|
|
Packit Service |
bcdfb1 |
done
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Capture the compose logs from osbuild.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ฌ Getting compose log and metadata"
|
|
Packit Service |
bcdfb1 |
get_compose_log "$COMPOSE_ID"
|
|
Packit Service |
bcdfb1 |
get_compose_metadata "$COMPOSE_ID"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Did the compose finish with success?
|
|
Packit Service |
bcdfb1 |
if [[ $COMPOSE_STATUS != FINISHED ]]; then
|
|
Packit Service |
bcdfb1 |
echo "Something went wrong with the compose. ๐ข"
|
|
Packit Service |
bcdfb1 |
exit 1
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Stop watching the worker journal.
|
|
Packit Service |
bcdfb1 |
sudo kill ${WORKER_JOURNAL_PID}
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Wait for the ssh server up to be.
|
|
Packit Service |
bcdfb1 |
wait_for_ssh_up () {
|
|
Packit Service |
bcdfb1 |
SSH_STATUS=$(sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@"${1}" '/bin/bash -c "echo -n READY"')
|
|
Packit Service |
bcdfb1 |
if [[ $SSH_STATUS == READY ]]; then
|
|
Packit Service |
bcdfb1 |
echo 1
|
|
Packit Service |
bcdfb1 |
else
|
|
Packit Service |
bcdfb1 |
echo 0
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Clean up our mess.
|
|
Packit Service |
bcdfb1 |
clean_up () {
|
|
Packit Service |
bcdfb1 |
greenprint "๐งผ Cleaning up"
|
|
Packit Service |
bcdfb1 |
sudo virsh destroy "${IMAGE_KEY}"
|
|
Packit Service |
bcdfb1 |
if [[ $ARCH == aarch64 ]]; then
|
|
Packit Service |
bcdfb1 |
sudo virsh undefine "${IMAGE_KEY}" --nvram
|
|
Packit Service |
bcdfb1 |
else
|
|
Packit Service |
bcdfb1 |
sudo virsh undefine "${IMAGE_KEY}"
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
# Remove qcow2 file.
|
|
Packit Service |
bcdfb1 |
sudo rm -f "$LIBVIRT_IMAGE_PATH"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Remove any status containers if exist
|
|
Packit Service |
15f37d |
sudo podman ps -a -q --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rm -f
|
|
Packit Service |
15f37d |
# Remove all images
|
|
Packit Service |
15f37d |
sudo podman rmi -f -a
|
|
Packit Service |
15f37d |
|
|
Packit Service |
bcdfb1 |
# Remomve tmp dir.
|
|
Packit Service |
bcdfb1 |
sudo rm -rf "$TEMPDIR"
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Test result checking
|
|
Packit Service |
bcdfb1 |
check_result () {
|
|
Packit Service |
15f37d |
greenprint "๐ Checking for test result"
|
|
Packit Service |
bcdfb1 |
if [[ $RESULTS == 1 ]]; then
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Success"
|
|
Packit Service |
bcdfb1 |
else
|
|
Packit Service |
bcdfb1 |
greenprint "โ Failed"
|
|
Packit Service |
bcdfb1 |
clean_up
|
|
Packit Service |
bcdfb1 |
exit 1
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
##########################################################
|
|
Packit Service |
bcdfb1 |
##
|
|
Packit Service |
15f37d |
## rhel-edge container image for building installer image
|
|
Packit Service |
bcdfb1 |
##
|
|
Packit Service |
15f37d |
##########################################################
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Write a blueprint for ostree image.
|
|
Packit Service |
bcdfb1 |
tee "$BLUEPRINT_FILE" > /dev/null << EOF
|
|
Packit Service |
15f37d |
name = "container"
|
|
Packit Service |
15f37d |
description = "A base rhel-edge container image"
|
|
Packit Service |
bcdfb1 |
version = "0.0.1"
|
|
Packit Service |
bcdfb1 |
modules = []
|
|
Packit Service |
bcdfb1 |
groups = []
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[[packages]]
|
|
Packit Service |
bcdfb1 |
name = "python36"
|
|
Packit Service |
bcdfb1 |
version = "*"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
[customizations.kernel]
|
|
Packit Service |
15f37d |
name = "kernel-rt"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
[[customizations.user]]
|
|
Packit Service |
15f37d |
name = "admin"
|
|
Packit Service |
15f37d |
description = "Administrator account"
|
|
Packit Service |
15f37d |
password = "\$6\$GRmb7S0p8vsYmXzH\$o0E020S.9JQGaHkszoog4ha4AQVs3sk8q0DvLjSMxoxHBKnB2FBXGQ/OkwZQfW/76ktHd0NX5nls2LPxPuUdl."
|
|
Packit Service |
15f37d |
key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod root@localhost"
|
|
Packit Service |
15f37d |
home = "/home/admin/"
|
|
Packit Service |
15f37d |
groups = ["wheel"]
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
greenprint "๐ container blueprint"
|
|
Packit Service |
15f37d |
cat "$BLUEPRINT_FILE"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Prepare the blueprint for the compose.
|
|
Packit Service |
15f37d |
greenprint "๐ Preparing container blueprint"
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints push "$BLUEPRINT_FILE"
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints depsolve container
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
# Build container image.
|
|
Packit Service |
15f37d |
build_image container rhel-edge-container
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
# Download the image
|
|
Packit Service |
15f37d |
greenprint "๐ฅ Downloading the container image"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Clear container running env
|
|
Packit Service |
15f37d |
greenprint "๐งน Clearing container running env"
|
|
Packit Service |
15f37d |
# Remove any status containers if exist
|
|
Packit Service |
15f37d |
sudo podman ps -a -q --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rm -f
|
|
Packit Service |
15f37d |
# Remove all images
|
|
Packit Service |
15f37d |
sudo podman rmi -f -a
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Deal with rhel-edge container
|
|
Packit Service |
15f37d |
greenprint "๐ Extracting and running the image"
|
|
Packit Service |
15f37d |
IMAGE_FILENAME="${COMPOSE_ID}-rhel84-container.tar"
|
|
Packit Service |
15f37d |
sudo podman pull "oci-archive:${IMAGE_FILENAME}"
|
|
Packit Service |
15f37d |
# Workaound for issue https://bugzilla.redhat.com/show_bug.cgi?id=1933774
|
|
Packit Service |
15f37d |
sudo restorecon -R /var/lib/containers/storage/overlay/
|
|
Packit Service |
15f37d |
sudo podman images
|
|
Packit Service |
15f37d |
# Clear image file
|
|
Packit Service |
bcdfb1 |
sudo rm -f "$IMAGE_FILENAME"
|
|
Packit Service |
15f37d |
# Get image id to run image
|
|
Packit Service |
15f37d |
EDGE_IMAGE_ID=$(sudo podman images --filter "dangling=true" --format "{{.ID}}")
|
|
Packit Service |
15f37d |
sudo podman run -d --name rhel-edge --network host "${EDGE_IMAGE_ID}"
|
|
Packit Service |
15f37d |
# Wait for container to be running
|
|
Packit Service |
15f37d |
until [ "$(sudo podman inspect -f '{{.State.Running}}' rhel-edge)" == "true" ]; do
|
|
Packit Service |
15f37d |
sleep 1;
|
|
Packit Service |
15f37d |
done;
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Clean compose and blueprints.
|
|
Packit Service |
15f37d |
greenprint "๐งฝ Clean up container blueprint and compose"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints delete container > /dev/null
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
########################################################
|
|
Packit Service |
15f37d |
##
|
|
Packit Service |
15f37d |
## rhel-edge installer image building from container image
|
|
Packit Service |
15f37d |
##
|
|
Packit Service |
15f37d |
########################################################
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Write a blueprint for installer image.
|
|
Packit Service |
15f37d |
tee "$BLUEPRINT_FILE" > /dev/null << EOF
|
|
Packit Service |
15f37d |
name = "installer"
|
|
Packit Service |
15f37d |
description = "A rhel-edge installer image"
|
|
Packit Service |
15f37d |
version = "0.0.1"
|
|
Packit Service |
15f37d |
modules = []
|
|
Packit Service |
15f37d |
groups = []
|
|
Packit Service |
15f37d |
EOF
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
greenprint "๐ installer blueprint"
|
|
Packit Service |
15f37d |
cat "$BLUEPRINT_FILE"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Prepare the blueprint for the compose.
|
|
Packit Service |
15f37d |
greenprint "๐ Preparing installer blueprint"
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints push "$BLUEPRINT_FILE"
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints depsolve installer
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Build installer image.
|
|
Packit Service |
15f37d |
build_image installer rhel-edge-installer "$URL"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Download the image
|
|
Packit Service |
15f37d |
greenprint "๐ฅ Downloading the installer image"
|
|
Packit Service |
15f37d |
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
|
|
Packit Service |
15f37d |
ISO_FILENAME="${COMPOSE_ID}-rhel84-boot.iso"
|
|
Packit Service |
15f37d |
sudo mv "${ISO_FILENAME}" /var/lib/libvirt/images
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Clean compose and blueprints.
|
|
Packit Service |
15f37d |
greenprint "๐งน Clean up installer blueprint and compose"
|
|
Packit Service |
15f37d |
sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints delete installer > /dev/null
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
########################################################
|
|
Packit Service |
15f37d |
##
|
|
Packit Service |
15f37d |
## install rhel-edge image with installer(ISO)
|
|
Packit Service |
15f37d |
##
|
|
Packit Service |
15f37d |
########################################################
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Ensure SELinux is happy with our new images.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ฟ Running restorecon on image directory"
|
|
Packit Service |
bcdfb1 |
sudo restorecon -Rv /var/lib/libvirt/images/
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Create qcow2 file for virt install.
|
|
Packit Service |
15f37d |
greenprint "๐ฅ Create qcow2 file for virt install"
|
|
Packit Service |
bcdfb1 |
LIBVIRT_IMAGE_PATH=/var/lib/libvirt/images/${IMAGE_KEY}.qcow2
|
|
Packit Service |
bcdfb1 |
sudo qemu-img create -f qcow2 "${LIBVIRT_IMAGE_PATH}" 20G
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Write kickstart file for ostree image installation.
|
|
Packit Service |
15f37d |
greenprint "๐ Generate kickstart file"
|
|
Packit Service |
bcdfb1 |
tee "$KS_FILE" > /dev/null << STOPHERE
|
|
Packit Service |
bcdfb1 |
text
|
|
Packit Service |
bcdfb1 |
lang en_US.UTF-8
|
|
Packit Service |
bcdfb1 |
keyboard us
|
|
Packit Service |
bcdfb1 |
timezone --utc Etc/UTC
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
selinux --enforcing
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
bootloader --timeout=1 --append="net.ifnames=0 modprobe.blacklist=vc4"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
network --bootproto=dhcp --device=link --activate --onboot=on
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
zerombr
|
|
Packit Service |
bcdfb1 |
clearpart --all --initlabel --disklabel=msdos
|
|
Packit Service |
bcdfb1 |
autopart --nohome --noswap --type=plain
|
|
Packit Service |
15f37d |
ostreesetup --nogpg --osname=rhel-edge --remote=rhel-edge --url=file:///ostree/repo --ref=${OSTREE_REF}
|
|
Packit Service |
bcdfb1 |
poweroff
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
%post --log=/var/log/anaconda/post-install.log --erroronfail
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# no sudo password for user admin
|
|
Packit Service |
bcdfb1 |
echo -e 'admin\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Remove any persistent NIC rules generated by udev
|
|
Packit Service |
bcdfb1 |
rm -vf /etc/udev/rules.d/*persistent-net*.rules
|
|
Packit Service |
bcdfb1 |
# And ensure that we will do DHCP on eth0 on startup
|
|
Packit Service |
bcdfb1 |
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
|
|
Packit Service |
bcdfb1 |
DEVICE="eth0"
|
|
Packit Service |
bcdfb1 |
BOOTPROTO="dhcp"
|
|
Packit Service |
bcdfb1 |
ONBOOT="yes"
|
|
Packit Service |
bcdfb1 |
TYPE="Ethernet"
|
|
Packit Service |
bcdfb1 |
PERSISTENT_DHCLIENT="yes"
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
echo "Zeroing out empty space."
|
|
Packit Service |
bcdfb1 |
# This forces the filesystem to reclaim space from deleted files
|
|
Packit Service |
bcdfb1 |
dd bs=1M if=/dev/zero of=/var/tmp/zeros || :
|
|
Packit Service |
bcdfb1 |
rm -f /var/tmp/zeros
|
|
Packit Service |
bcdfb1 |
echo "(Don't worry -- that out-of-space error was expected.)"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
%end
|
|
Packit Service |
bcdfb1 |
STOPHERE
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Install ostree image via anaconda.
|
|
Packit Service |
15f37d |
greenprint "๐ฟ Install ostree image via installer(ISO)"
|
|
Packit Service |
bcdfb1 |
sudo virt-install --initrd-inject="${KS_FILE}" \
|
|
Packit Service |
15f37d |
--extra-args="inst.ks=file:/ks.cfg console=ttyS0,115200" \
|
|
Packit Service |
bcdfb1 |
--name="${IMAGE_KEY}"\
|
|
Packit Service |
bcdfb1 |
--disk path="${LIBVIRT_IMAGE_PATH}",format=qcow2 \
|
|
Packit Service |
bcdfb1 |
--ram 3072 \
|
|
Packit Service |
bcdfb1 |
--vcpus 2 \
|
|
Packit Service |
bcdfb1 |
--network network=integration,mac=34:49:22:B0:83:30 \
|
|
Packit Service |
bcdfb1 |
--os-type linux \
|
|
Packit Service |
bcdfb1 |
--os-variant ${OS_VARIANT} \
|
|
Packit Service |
15f37d |
--location "/var/lib/libvirt/images/${ISO_FILENAME}" \
|
|
Packit Service |
bcdfb1 |
--nographics \
|
|
Packit Service |
bcdfb1 |
--noautoconsole \
|
|
Packit Service |
bcdfb1 |
--wait=-1 \
|
|
Packit Service |
bcdfb1 |
--noreboot
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Start VM.
|
|
Packit Service |
15f37d |
greenprint "๐ Start VM"
|
|
Packit Service |
bcdfb1 |
sudo virsh start "${IMAGE_KEY}"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Check for ssh ready to go.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Checking for SSH is ready to go"
|
|
Packit Service |
bcdfb1 |
for LOOP_COUNTER in $(seq 0 30); do
|
|
Packit Service |
bcdfb1 |
RESULTS="$(wait_for_ssh_up $GUEST_ADDRESS)"
|
|
Packit Service |
bcdfb1 |
if [[ $RESULTS == 1 ]]; then
|
|
Packit Service |
bcdfb1 |
echo "SSH is ready now! ๐ฅณ"
|
|
Packit Service |
bcdfb1 |
break
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
sleep 10
|
|
Packit Service |
bcdfb1 |
done
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Check image installation result
|
|
Packit Service |
bcdfb1 |
check_result
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
##################################################
|
|
Packit Service |
bcdfb1 |
##
|
|
Packit Service |
15f37d |
## upgrade rhel-edge with new upgrade container
|
|
Packit Service |
bcdfb1 |
##
|
|
Packit Service |
bcdfb1 |
##################################################
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Write a blueprint for ostree image.
|
|
Packit Service |
bcdfb1 |
tee "$BLUEPRINT_FILE" > /dev/null << EOF
|
|
Packit Service |
bcdfb1 |
name = "upgrade"
|
|
Packit Service |
15f37d |
description = "An upgrade rhel-edge container image"
|
|
Packit Service |
bcdfb1 |
version = "0.0.2"
|
|
Packit Service |
bcdfb1 |
modules = []
|
|
Packit Service |
bcdfb1 |
groups = []
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[[packages]]
|
|
Packit Service |
bcdfb1 |
name = "python36"
|
|
Packit Service |
bcdfb1 |
version = "*"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[[packages]]
|
|
Packit Service |
bcdfb1 |
name = "wget"
|
|
Packit Service |
bcdfb1 |
version = "*"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
[customizations.kernel]
|
|
Packit Service |
15f37d |
name = "kernel-rt"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
[[customizations.user]]
|
|
Packit Service |
15f37d |
name = "admin"
|
|
Packit Service |
15f37d |
description = "Administrator account"
|
|
Packit Service |
15f37d |
password = "\$6\$GRmb7S0p8vsYmXzH\$o0E020S.9JQGaHkszoog4ha4AQVs3sk8q0DvLjSMxoxHBKnB2FBXGQ/OkwZQfW/76ktHd0NX5nls2LPxPuUdl."
|
|
Packit Service |
15f37d |
key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod root@localhost"
|
|
Packit Service |
15f37d |
home = "/home/admin/"
|
|
Packit Service |
15f37d |
groups = ["wheel"]
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
greenprint "๐ upgrade blueprint"
|
|
Packit Service |
15f37d |
cat "$BLUEPRINT_FILE"
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Prepare the blueprint for the compose.
|
|
Packit Service |
15f37d |
greenprint "๐ Preparing upgrade blueprint"
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints push "$BLUEPRINT_FILE"
|
|
Packit Service |
15f37d |
sudo composer-cli blueprints depsolve upgrade
|
|
Packit Service |
15f37d |
|
|
Packit Service |
bcdfb1 |
# Build upgrade image.
|
|
Packit Service |
15f37d |
build_image upgrade rhel-edge-container "$URL"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
# Download the image
|
|
Packit Service |
15f37d |
greenprint "๐ฅ Downloading the upgrade image"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Clear container running env
|
|
Packit Service |
15f37d |
greenprint "๐งน Clearing container running env"
|
|
Packit Service |
15f37d |
# Remove any status containers if exist
|
|
Packit Service |
15f37d |
sudo podman ps -a -q --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rm -f
|
|
Packit Service |
15f37d |
# Remove all images
|
|
Packit Service |
15f37d |
sudo podman rmi -f -a
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Deal with rhel-edge container
|
|
Packit Service |
15f37d |
greenprint "๐ Extracting and running the image"
|
|
Packit Service |
15f37d |
IMAGE_FILENAME="${COMPOSE_ID}-rhel84-container.tar"
|
|
Packit Service |
15f37d |
sudo podman pull "oci-archive:${IMAGE_FILENAME}"
|
|
Packit Service |
15f37d |
# Workaound for issue https://bugzilla.redhat.com/show_bug.cgi?id=1933774
|
|
Packit Service |
15f37d |
sudo restorecon -R /var/lib/containers/storage/overlay/
|
|
Packit Service |
15f37d |
sudo podman images
|
|
Packit Service |
15f37d |
# Clear image file
|
|
Packit Service |
bcdfb1 |
sudo rm -f "$IMAGE_FILENAME"
|
|
Packit Service |
15f37d |
# Get image id to run image
|
|
Packit Service |
15f37d |
EDGE_IMAGE_ID=$(sudo podman images --filter "dangling=true" --format "{{.ID}}")
|
|
Packit Service |
15f37d |
sudo podman run -d --name rhel-edge --network host "${EDGE_IMAGE_ID}"
|
|
Packit Service |
15f37d |
# Wait for container to be running
|
|
Packit Service |
15f37d |
until [ "$(sudo podman inspect -f '{{.State.Running}}' rhel-edge)" == "true" ]; do
|
|
Packit Service |
15f37d |
sleep 1;
|
|
Packit Service |
15f37d |
done;
|
|
Packit Service |
15f37d |
|
|
Packit Service |
15f37d |
# Get ostree commit value.
|
|
Packit Service |
15f37d |
greenprint "๐น Get ostree upgrade commit value"
|
|
Packit Service |
464a89 |
UPGRADE_HASH=$(curl ${URL}refs/heads/"${OSTREE_REF}")
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Clean compose and blueprints.
|
|
Packit Service |
15f37d |
greenprint "๐งฝ Clean up upgrade blueprint and compose"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
|
|
Packit Service |
bcdfb1 |
sudo composer-cli blueprints delete upgrade > /dev/null
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
15f37d |
# Config remote repository for upgrade
|
|
Packit Service |
15f37d |
greenprint "๐ Config remote repository for upgrade"
|
|
Packit Service |
15f37d |
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${GUEST_ADDRESS} 'sudo ostree remote delete rhel-edge'
|
|
Packit Service |
15f37d |
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${GUEST_ADDRESS} "sudo ostree remote add --no-gpg-verify --no-sign-verify rhel-edge ${URL}"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Upgrade image/commit.
|
|
Packit Service |
15f37d |
greenprint "๐ณ Upgrade ostree image/commit"
|
|
Packit Service |
bcdfb1 |
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${GUEST_ADDRESS} 'sudo rpm-ostree upgrade'
|
|
Packit Service |
bcdfb1 |
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${GUEST_ADDRESS} 'nohup sudo systemctl reboot &>/dev/null & exit'
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Sleep 10 seconds here to make sure vm restarted already
|
|
Packit Service |
bcdfb1 |
sleep 10
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Check for ssh ready to go.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Checking for SSH is ready to go"
|
|
Packit Service |
bcdfb1 |
# shellcheck disable=SC2034 # Unused variables left for readability
|
|
Packit Service |
bcdfb1 |
for LOOP_COUNTER in $(seq 0 30); do
|
|
Packit Service |
bcdfb1 |
RESULTS="$(wait_for_ssh_up $GUEST_ADDRESS)"
|
|
Packit Service |
bcdfb1 |
if [[ $RESULTS == 1 ]]; then
|
|
Packit Service |
bcdfb1 |
echo "SSH is ready now! ๐ฅณ"
|
|
Packit Service |
bcdfb1 |
break
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
sleep 10
|
|
Packit Service |
bcdfb1 |
done
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Check ostree upgrade result
|
|
Packit Service |
bcdfb1 |
check_result
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Add instance IP address into /etc/ansible/hosts
|
|
Packit Service |
bcdfb1 |
sudo tee "${TEMPDIR}"/inventory > /dev/null << EOF
|
|
Packit Service |
bcdfb1 |
[ostree_guest]
|
|
Packit Service |
bcdfb1 |
${GUEST_ADDRESS}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[ostree_guest:vars]
|
|
Packit Service |
bcdfb1 |
ansible_python_interpreter=/usr/bin/python3
|
|
Packit Service |
bcdfb1 |
ansible_user=admin
|
|
Packit Service |
bcdfb1 |
ansible_private_key_file=${SSH_KEY}
|
|
Packit Service |
bcdfb1 |
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Test IoT/Edge OS
|
|
Packit Service |
15f37d |
sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type=rhel-edge -e ostree_commit="${UPGRADE_HASH}" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
|
|
Packit Service |
bcdfb1 |
check_result
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Final success clean up
|
|
Packit Service |
bcdfb1 |
clean_up
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
exit 0
|