Skip to content

Commit

Permalink
scripts/install-release-image: Extract the RHCOS AMI from the release…
Browse files Browse the repository at this point in the history
… image

A temporary workaround while [1] is in flight.

[1]: openshift#1286
  • Loading branch information
wking committed Feb 27, 2019
1 parent fe01197 commit 4f8bac2
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions scripts/install-release-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -42,7 +47,7 @@
# [4]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

die () {
echo "${*}" >&2
printf "${@}" >&2
exit 1
}

Expand Down Expand Up @@ -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"
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" \
"${@}"

0 comments on commit 4f8bac2

Please sign in to comment.