diff --git a/03_build_installer.sh b/03_build_installer.sh index 63f9b5e7d..070358242 100755 --- a/03_build_installer.sh +++ b/03_build_installer.sh @@ -15,6 +15,7 @@ mkdir -p $OCP_DIR if [ -z "$KNI_INSTALL_FROM_GIT" ]; then # Extract openshift-install from the release image extract_installer "${OPENSHIFT_RELEASE_IMAGE}" $OCP_DIR + extract_rhcos_json "${OPENSHIFT_RELEASE_IMAGE}" $OCP_DIR else # Clone and build the installer from source clone_installer diff --git a/ocp_install_env.sh b/ocp_install_env.sh index 97540b615..a3c0f413e 100644 --- a/ocp_install_env.sh +++ b/ocp_install_env.sh @@ -39,6 +39,27 @@ function extract_installer() { extract_command openshift-baremetal-install "$1" "$2" } +function extract_rhcos_json() { + local release_image + local outdir + + release_image="$1" + outdir="$2" + pullsecret_file=$(mktemp "pullsecret--XXXXXXXXXX") + + echo "${PULL_SECRET}" > "${pullsecret_file}" + + baremetal_image=$(oc adm release info --image-for=baremetal-installer --registry-config "$pullsecret_file" "$release_image") + baremetal_container=$(podman create --authfile "$pullsecret_file" "$baremetal_image") + + # This is OK to fail as rhcos.json isn't available in every release, + # we'll download it from github if it's not available + podman cp "$baremetal_container":/var/cache/rhcos.json "$outdir" || true + + podman rm -f "$baremetal_container" + rm -rf "${pullsecret_file}" +} + function clone_installer() { # Clone repo, if not already present if [[ ! -d $OPENSHIFT_INSTALL_PATH ]]; then @@ -52,6 +73,7 @@ function build_installer() { cd $OPENSHIFT_INSTALL_PATH TAGS="libvirt baremetal" hack/build.sh popd + cp "$OPENSHIFT_INSTALL_PATH/data/data/rhcos.json" "$OCP_DIR" } # FIXME(stbenjam): This is not available in 4.3 (yet) diff --git a/rhcos.sh b/rhcos.sh index 92c83ea7a..5fed13bb6 100644 --- a/rhcos.sh +++ b/rhcos.sh @@ -1,11 +1,24 @@ -# Get the git commit that the openshift installer was built from -OPENSHIFT_INSTALL_COMMIT=$($OPENSHIFT_INSTALLER version | grep commit | cut -d' ' -f4) +if [[ -f "$OCP_DIR/rhcos.json" ]]; then + MACHINE_OS_IMAGE_JSON=$(cat "$OCP_DIR/rhcos.json") +else -# Get the rhcos.json for that commit -OPENSHIFT_INSTALLER_MACHINE_OS=${OPENSHIFT_INSTALLER_MACHINE_OS:-https://raw.githubusercontent.com/openshift/installer/$OPENSHIFT_INSTALL_COMMIT/data/data/rhcos.json} + if [[ -v JOB_NAME ]] && [[ "$JOB_NAME" =~ "openshift-installer" ]]; then + # Get the SHA from the PR if we're in CI + OPENSHIFT_INSTALL_COMMIT=${PULL_PULL_SHA:-$(echo "$JOB_SPEC" | jq -r '.refs.pulls[0].sha')} + else + # Get the git commit that the openshift installer was built from + OPENSHIFT_INSTALL_COMMIT=$($OPENSHIFT_INSTALLER version | grep commit | cut -d' ' -f4) + fi -# Get the rhcos.json for that commit, and find the baseURI and openstack image path -MACHINE_OS_IMAGE_JSON=$(curl "${OPENSHIFT_INSTALLER_MACHINE_OS}") + # Get the git commit that the openshift installer was built from + OPENSHIFT_INSTALL_COMMIT=$($OPENSHIFT_INSTALLER version | grep commit | cut -d' ' -f4) + + # Get the rhcos.json for that commit + OPENSHIFT_INSTALLER_MACHINE_OS=${OPENSHIFT_INSTALLER_MACHINE_OS:-https://raw.githubusercontent.com/openshift/installer/$OPENSHIFT_INSTALL_COMMIT/data/data/rhcos.json} + + # Get the rhcos.json for that commit, and find the baseURI and openstack image path + MACHINE_OS_IMAGE_JSON=$(curl "${OPENSHIFT_INSTALLER_MACHINE_OS}") +fi export MACHINE_OS_INSTALLER_IMAGE_URL=$(echo "${MACHINE_OS_IMAGE_JSON}" | jq -r '.baseURI + .images.openstack.path') export MACHINE_OS_INSTALLER_IMAGE_SHA256=$(echo "${MACHINE_OS_IMAGE_JSON}" | jq -r '.images.openstack.sha256')