mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-16 08:26:16 +00:00
rootfs: fix golang version detection
When the rootfs creation is used for PRs there is not a match with a kata runtime version, in this case lets clone the runtime repository and checkout to the kata branch target. If is already cloned this mean this was set by depens-on script or the user. Fixes: #326 Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
parent
0c48630395
commit
4ade7e5853
@ -4,7 +4,9 @@
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -e
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
set -o errtrace
|
||||
|
||||
[ -n "$DEBUG" ] && set -x
|
||||
|
||||
@ -12,17 +14,31 @@ script_name="${0##*/}"
|
||||
script_dir="$(dirname $(readlink -f $0))"
|
||||
AGENT_VERSION=${AGENT_VERSION:-}
|
||||
GO_AGENT_PKG=${GO_AGENT_PKG:-github.com/kata-containers/agent}
|
||||
GO_RUNTIME_PKG=${GO_RUNTIME_PKG:-github.com/kata-containers/runtime}
|
||||
AGENT_BIN=${AGENT_BIN:-kata-agent}
|
||||
AGENT_INIT=${AGENT_INIT:-no}
|
||||
KERNEL_MODULES_DIR=${KERNEL_MODULES_DIR:-""}
|
||||
OSBUILDER_VERSION="unknown"
|
||||
DOCKER_RUNTIME=${DOCKER_RUNTIME:-runc}
|
||||
GO_VERSION=
|
||||
GO_VERSION="null"
|
||||
#https://github.com/kata-containers/tests/blob/master/.ci/jenkins_job_build.sh
|
||||
# Give preference to variable set by CI
|
||||
KATA_BRANCH=${branch:-}
|
||||
KATA_BRANCH=${KATA_BRANCH:-master}
|
||||
export GOPATH=${GOPATH:-${HOME}/go}
|
||||
|
||||
lib_file="${script_dir}/../scripts/lib.sh"
|
||||
source "$lib_file"
|
||||
|
||||
handle_error() {
|
||||
local exit_code="${?}"
|
||||
local line_number="${1:-}"
|
||||
echo "Failed at $line_number: ${BASH_COMMAND}"
|
||||
exit "${exit_code}"
|
||||
|
||||
}
|
||||
trap 'handle_error $LINENO' ERR
|
||||
|
||||
# Default architecture
|
||||
ARCH=$(uname -m)
|
||||
|
||||
@ -247,22 +263,44 @@ error_handler()
|
||||
|
||||
detect_go_version()
|
||||
{
|
||||
info "Detecting agent go version"
|
||||
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)"
|
||||
|
||||
local runtimeRevision=
|
||||
local runtimeRevision=""
|
||||
|
||||
if [ "${AGENT_VERSION:-master}" == "master" ]; then
|
||||
# This matches both AGENT_VERSION == "" and AGENT_VERSION == "master"
|
||||
runtimeRevision="master"
|
||||
else
|
||||
# Detect runtime revision by fetching the agent's VERSION file
|
||||
runtimeRevision="$(curl -fsSL https://raw.githubusercontent.com/kata-containers/agent/${AGENT_VERSION:-master}/VERSION)"
|
||||
[ -z "$runtimeRevision" ] && die "Could not detect the agent version for the given AGENT_VERSION='${AGENT_VERSION:-master}'"
|
||||
# Detect runtime revision by fetching the agent's VERSION file
|
||||
local runtime_version_url="https://raw.githubusercontent.com/kata-containers/agent/${AGENT_VERSION:-master}/VERSION"
|
||||
info "Detecting runtime version using ${runtime_version_url}"
|
||||
|
||||
if runtimeRevision="$(curl -fsSL ${runtime_version_url})"; then
|
||||
[ -n "${runtimeRevision}" ] || die "failed to get agent version"
|
||||
typeset -r runtimeVersionsURL="https://raw.githubusercontent.com/kata-containers/runtime/${runtimeRevision}/versions.yaml"
|
||||
info "Getting golang version from ${runtimeVersionsURL}"
|
||||
# This may fail if we are a kata bump.
|
||||
if GO_VERSION="$(curl -fsSL "$runtimeVersionsURL" | $yq r - "languages.golang.version")"; then
|
||||
[ "$GO_VERSION" != "null" ]
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
typeset -r runtimeVersionsURL="https://raw.githubusercontent.com/kata-containers/runtime/${runtimeRevision}/versions.yaml"
|
||||
GO_VERSION="$(curl -fsSL "$runtimeVersionsURL" | $yq r - "languages.golang.version")"
|
||||
info "Agent version has not match with a runtime version, assumming it is a PR"
|
||||
local kata_runtime_pkg_dir="${GOPATH}/src/${GO_RUNTIME_PKG}"
|
||||
if [ ! -d "${kata_runtime_pkg_dir}" ];then
|
||||
info "There is not runtime repository in filesystem (${kata_runtime_pkg_dir})"
|
||||
local runtime_versions_url="https://raw.githubusercontent.com/kata-containers/runtime/${KATA_BRANCH}/versions.yaml"
|
||||
info "Get versions file from ${runtime_versions_url}"
|
||||
GO_VERSION="$(curl -fsSL "${runtime_versions_url}" | $yq r - "languages.golang.version")"
|
||||
if [ "$?" == "0" ] && [ "$GO_VERSION" != "null" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
local kata_versions_file="${kata_runtime_pkg_dir}/versions.yaml"
|
||||
info "Get Go version from ${kata_versions_file}"
|
||||
GO_VERSION="$(cat "${kata_versions_file}" | $yq r - "languages.golang.version")"
|
||||
|
||||
[ "$?" == "0" ] && [ "$GO_VERSION" != "null" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user