rootfs: Install yq if not found instead of error

When building rootfs, yq is needed to parse
the version from versions.yaml file. If yq
is not found, it fails. In this PR, we install
yq if not found.

Fixes: #363

Signed-off-by: Nitesh Konkar <niteshkonkar@in.ibm.com>
This commit is contained in:
Nitesh Konkar 2019-09-24 23:31:45 +05:30
parent c33068de10
commit 05428a6424
2 changed files with 76 additions and 1 deletions

72
scripts/install-yq.sh Normal file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env bash
#
# Copyright (c) 2019 IBM
#
# SPDX-License-Identifier: Apache-2.0
#
# If we fail for any reason a message will be displayed
die() {
msg="$*"
echo "ERROR: $msg" >&2
exit 1
}
# Install the yq yaml query package from the mikefarah github repo
# Install via binary download, as we may not have golang installed at this point
function install_yq() {
GOPATH=${GOPATH:-${HOME}/go}
local yq_path="${GOPATH}/bin/yq"
local yq_pkg="github.com/mikefarah/yq"
[ -x "${GOPATH}/bin/yq" ] && return
read -r -a sysInfo <<< "$(uname -sm)"
case "${sysInfo[0]}" in
"Linux" | "Darwin")
goos="${sysInfo[0],}"
;;
"*")
die "OS ${sysInfo[0]} not supported"
;;
esac
case "${sysInfo[1]}" in
"aarch64")
goarch=arm64
;;
"ppc64le")
goarch=ppc64le
;;
"x86_64")
goarch=amd64
;;
"s390x")
goarch=s390x
;;
"*")
die "Arch ${sysInfo[1]} not supported"
;;
esac
mkdir -p "${GOPATH}/bin"
# Check curl
if ! command -v "curl" >/dev/null; then
die "Please install curl"
fi
local yq_version=2.3.0
local yq_url="https://${yq_pkg}/releases/download/${yq_version}/yq_${goos}_${goarch}"
curl -o "${yq_path}" -LSsf ${yq_url}
[ $? -ne 0 ] && die "Download ${yq_url} failed"
chmod +x ${yq_path}
if ! command -v "${yq_path}" >/dev/null; then
die "Cannot not get ${yq_path} executable"
fi
}
install_yq

View File

@ -12,6 +12,7 @@ GO_RUNTIME_PKG=${GO_RUNTIME_PKG:-github.com/kata-containers/runtime}
# Give preference to variable set by CI # Give preference to variable set by CI
KATA_BRANCH=${branch:-} KATA_BRANCH=${branch:-}
KATA_BRANCH=${KATA_BRANCH:-master} KATA_BRANCH=${KATA_BRANCH:-master}
yq_file="${script_dir}/../scripts/install-yq.sh"
error() error()
{ {
@ -273,7 +274,9 @@ detect_go_version()
{ {
info "Detecting agent go version" info "Detecting agent go version"
typeset -r yq=$(command -v yq || command -v ${GOPATH}/bin/yq) typeset -r yq=$(command -v yq || command -v ${GOPATH}/bin/yq)
[ -z "$yq" ] && die "'yq' application not found (needed to parsing minimum Go version required)" if [ -z "$yq" ]; then
source "$yq_file"
fi
local runtimeRevision="" local runtimeRevision=""