diff --git a/scripts/install-release-image.sh b/scripts/install-release-image.sh index 5b2ad49aceb..da98d37174d 100755 --- a/scripts/install-release-image.sh +++ b/scripts/install-release-image.sh @@ -5,14 +5,15 @@ # # Usage: # -# install-release-image.sh [ARG...] +# AWS_DEFAULT_REGION=us-east-1 install-release-image.sh [ARG...] # # Requires: # -# * oc, to extract the installer image +# * oc, to extract the installer and machine-os-content images # * podman, to run the installer image # * realpath, which is not in POSIX as a shell command [1], but is in # GNU coreutils [2]. The backing C function is in POSIX [3]. +# * jq, for processing the machine-os-content metadata # * A pull secret in ~/.docker/config.json for both oc and podman. # # Optional: @@ -32,6 +33,10 @@ # * AWS_CONFIG_FILE [4] # This defaults to ~/.aws/config, and, if set to an existing file, # it is mounted into the installer container at ~/.aws/config +# * AWS_DEFAULT_REGION +# Where you want to launch the cluster. We won't need this once +# #1286 lands, but until then we need it to look up the apropriate +# AMI. Sorry libvirt and OpenStack folks :p. # * AWS_SHARED_CREDENTIALS_FILE [4] # If set, this is mounted into the installer container at # ~/.aws/credentials @@ -84,8 +89,32 @@ then set -- --volume "${AWS_SHARED_CREDENTIALS_FILE}:/home/.aws/credentials:z" "${@}" || die 'failed to insert AWS_SHARED_CREDENTIALS_FILE into podman arguments' fi +# Begin workaround while we wait for https://github.com/openshift/installer/pull/1286 +OS_IMAGE="$(oc adm release info --image-for=machine-os-content "${RELEASE}")" || die 'failed to resolve machine-os-content image' +OS_ANNOTATIONS="$(oc image info --output=json "${OS_IMAGE}")" || die 'failed to extract machine-os-content metadata' +OS_BUILD="$(echo "${OS_ANNOTATIONS}" | jq -r .config.config.Labels.version)" || die 'failed to extract RHCOS build' +OS_BASE_URL="${OS_BASE_URL:-https://releases-rhcos.svc.ci.openshift.org/storage/releases}" +OS_CHANNEL="${OS_CHANNEL:=maipo}" + +# assume we're using AWS +REGION="${REGION:-${AWS_DEFAULT_REGION}}" + +if test -z "${REGION}" +then + die "REGION unset\n" +fi + +AMIS="$(curl -s "${OS_BASE_URL}/${OS_CHANNEL}/${OS_BUILD}/meta.json" | jq -r ".amis")" || die "failed to pull metadata for ${OS_BUILD}" +AMI="$(echo "${AMIS}" | jq -r ".[] | select(.name == \"${REGION}\").hvm")" || die 'failed to extract RHCOS AMI ID' +if test -z "${AMI}" +then + die "no AMI for %s. Available regions:\n%s\n" "${REGION}" "$(echo "${AMIS}" | jq -r '.[].name')" +fi +# End of #1286 workaround + exec podman run --rm -it \ --user "$(id -u):$(id -g)" \ --env OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE="${RELEASE}" \ + --env OPENSHIFT_INSTALL_OS_IMAGE_OVERRIDE="${AMI}" \ --volume "${ASSETS}:/output:z" \ "${@}"