|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# OVE (OpenShift Virtualization Edition) ISO building utilities |
| 5 | +# Functions for creating agent ISOs without embedded registry |
| 6 | + |
| 7 | +# Check if using a custom registry (not upstream quay.io or CI registry) |
| 8 | +function is_custom_registry() { |
| 9 | + [[ ! "${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE}" =~ quay\.io ]] && \ |
| 10 | + [[ ! "${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE}" =~ registry\.ci\.openshift\.org ]] |
| 11 | +} |
| 12 | + |
| 13 | +# Determine release image URL based on mirror configuration |
| 14 | +function get_release_image_url() { |
| 15 | + if [[ "${MIRROR_IMAGES}" == "true" ]]; then |
| 16 | + echo "${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE}" |
| 17 | + else |
| 18 | + echo "${OPENSHIFT_RELEASE_IMAGE}" |
| 19 | + fi |
| 20 | +} |
| 21 | + |
| 22 | +# Build OVE ISO using script method |
| 23 | +function build_ove_iso_script() { |
| 24 | + local asset_dir=$1 |
| 25 | + local release_image_url=$2 |
| 26 | + local mirror_path_arg=$3 |
| 27 | + local registry_cert_arg=$4 |
| 28 | + |
| 29 | + ./hack/build-ove-image.sh \ |
| 30 | + --pull-secret-file "${PULL_SECRET_FILE}" \ |
| 31 | + --release-image-url "${release_image_url}" \ |
| 32 | + --ssh-key-file "${SSH_KEY_FILE}" \ |
| 33 | + --dir "${asset_dir}" \ |
| 34 | + ${mirror_path_arg} \ |
| 35 | + ${registry_cert_arg} |
| 36 | +} |
| 37 | + |
| 38 | +# Build OVE ISO using container method |
| 39 | +function build_ove_iso_container() { |
| 40 | + local asset_dir=$1 |
| 41 | + local release_image_url=$2 |
| 42 | + |
| 43 | + # Build ISO in container |
| 44 | + make build-ove-iso-container \ |
| 45 | + PULL_SECRET_FILE="${PULL_SECRET_FILE}" \ |
| 46 | + RELEASE_IMAGE_URL="${release_image_url}" \ |
| 47 | + ARCH=${ARCH} |
| 48 | + |
| 49 | + # Extract ISO from container |
| 50 | + ./hack/iso-from-container.sh |
| 51 | + |
| 52 | + # Move to asset directory |
| 53 | + local iso_name="agent-ove.${ARCH}.iso" |
| 54 | + echo "Moving ${iso_name} to ${asset_dir}" |
| 55 | + mv ./output-iso/${iso_name} "${asset_dir}" |
| 56 | +} |
| 57 | + |
| 58 | +# Create agent ISO without registry (OVE ISO) |
| 59 | +function create_agent_iso_no_registry() { |
| 60 | + local asset_dir=${1} |
| 61 | + |
| 62 | + # Update release_info.json as its needed by CI tests |
| 63 | + save_release_info ${OPENSHIFT_RELEASE_IMAGE} ${OCP_DIR} |
| 64 | + |
| 65 | + AGENT_ISO_BUILDER_IMAGE=$(getAgentISOBuilderImage) |
| 66 | + |
| 67 | + # Extract agent-iso-builder source from container |
| 68 | + id=$(podman create --pull always --authfile "${PULL_SECRET_FILE}" "${AGENT_ISO_BUILDER_IMAGE}") && \ |
| 69 | + podman cp "${id}":/src "${asset_dir}" && \ |
| 70 | + podman rm "${id}" |
| 71 | + |
| 72 | + pushd . |
| 73 | + cd "${asset_dir}"/src |
| 74 | + |
| 75 | + # Determine release image URL |
| 76 | + local release_image_url=$(get_release_image_url) |
| 77 | + if [[ "${MIRROR_IMAGES}" == "true" ]]; then |
| 78 | + echo "Using mirrored release image: ${release_image_url}" |
| 79 | + else |
| 80 | + echo "Using upstream release image: ${release_image_url}" |
| 81 | + fi |
| 82 | + |
| 83 | + # Prepare mirror and certificate arguments for script build method |
| 84 | + local mirror_path_arg="" |
| 85 | + local registry_cert_arg="" |
| 86 | + |
| 87 | + if [[ "${MIRROR_IMAGES}" == "true" ]]; then |
| 88 | + echo "Using pre-mirrored images from ${REGISTRY_DIR}" |
| 89 | + mirror_path_arg="--mirror-path ${REGISTRY_DIR}" |
| 90 | + |
| 91 | + # Add registry certificate if using custom registry |
| 92 | + if is_custom_registry && [[ -f "${REGISTRY_DIR}/certs/${REGISTRY_CRT}" ]]; then |
| 93 | + registry_cert_arg="--registry-cert ${REGISTRY_DIR}/certs/${REGISTRY_CRT}" |
| 94 | + fi |
| 95 | + fi |
| 96 | + |
| 97 | + # Build OVE ISO using selected method |
| 98 | + if [[ "${AGENT_ISO_NO_REGISTRY_BUILD_METHOD}" == "script" ]]; then |
| 99 | + build_ove_iso_script "${asset_dir}" "${release_image_url}" "${mirror_path_arg}" "${registry_cert_arg}" |
| 100 | + else |
| 101 | + build_ove_iso_container "${asset_dir}" "${release_image_url}" |
| 102 | + fi |
| 103 | + |
| 104 | + rm -rf "${asset_dir}"/src |
| 105 | + popd |
| 106 | +} |
0 commit comments