forked from kata-containers/packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.sh
119 lines (101 loc) · 3.25 KB
/
lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
export GOPATH=${GOPATH:-${HOME}/go}
kata_arch_sh="${GOPATH}/src/github.com/kata-containers/tests/.ci/kata-arch.sh"
hub_bin="hub-bin"
get_kata_arch() {
go get -u github.com/kata-containers/tests || true
[ -f "${kata_arch_sh}" ] || die "Not found $kata_arch_sh"
}
install_yq() {
GOPATH=${GOPATH:-${HOME}/go}
local yq_path="${GOPATH}/bin/yq"
local yq_pkg="github.com/mikefarah/yq"
[ -x "${GOPATH}/bin/yq" ] && return
get_kata_arch
goarch=$("${kata_arch_sh}" -g)
mkdir -p "${GOPATH}/bin"
# Workaround to get latest release from github (to not use github token).
# Get the redirection to latest release on github.
yq_latest_url=$(curl -Ls -o /dev/null -w %{url_effective} "https://${yq_pkg}/releases/latest")
# The redirected url should include the latest release version
# https://github.com/mikefarah/yq/releases/tag/<VERSION-HERE>
yq_version=$(basename "${yq_latest_url}")
local yq_url="https://${yq_pkg}/releases/download/${yq_version}/yq_linux_${goarch}"
curl -o "${yq_path}" -L "${yq_url}"
chmod +x "${yq_path}"
}
get_from_kata_deps() {
local dependency="$1"
BRANCH=${BRANCH:-master}
local branch="${2:-${BRANCH}}"
local runtime_repo="github.com/kata-containers/runtime"
GOPATH=${GOPATH:-${HOME}/go}
local runtime_repo_dir="${GOPATH}/src/${runtime_repo}"
# For our CI, we will query the local versions.yaml file both for kernel and
# all other subsystems. eg: a new version of NEMU would be good to test
# through CI. For the kernel, .ci/install_kata_kernel.sh file in tests
# repository will pass the kernel version as an override to this function to
# allow testing of kernels before they land in tree.
if [ "${CI:-}" = "true" ] && [ -d "${runtime_repo_dir}" ]; then
versions_file="${runtime_repo_dir}/versions.yaml"
else
versions_file="versions-${branch}.yaml"
fi
#make sure yq is installed
install_yq >&2
if [ ! -e "${versions_file}" ]; then
yaml_url="https://raw.githubusercontent.com/kata-containers/runtime/${branch}/versions.yaml"
echo "versions file (${versions_file}) does not exist" >&2
echo "Download from ${yaml_url}" >&2
curl --silent -o "${versions_file}" "$yaml_url"
fi
result=$("${GOPATH}/bin/yq" read "$versions_file" "$dependency")
[ "$result" = "null" ] && result=""
echo "$result"
}
die() {
echo >&2 "ERROR: $*"
exit 1
}
info() {
echo >&2 "INFO: $*"
}
get_repo_hash() {
local repo_dir=${1:-}
[ -d "${repo_dir}" ] || die "${repo_dir} is not a directory"
pushd "${repo_dir}" >>/dev/null
git rev-parse --verify HEAD
popd >>/dev/null
}
build_hub() {
info "Get hub"
if cmd=$(command -v hub); then
hub_bin="${cmd}"
return
else
hub_bin="${tmp_dir:-/tmp}/hub-bin"
fi
local hub_repo="github.com/github/hub"
local hub_repo_dir="${GOPATH}/src/${hub_repo}"
[ -d "${hub_repo_dir}" ] || git clone --quiet --depth 1 "https://${hub_repo}.git" "${hub_repo_dir}"
pushd "${hub_repo_dir}" >>/dev/null
git checkout master
git pull
./script/build -o "${hub_bin}"
popd >>/dev/null
}
arch_to_golang()
{
local -r arch="$1"
case "$arch" in
aarch64) echo "arm64";;
ppc64le) echo "$arch";;
x86_64) echo "amd64";;
s390x) echo "s390x";;
*) die "unsupported architecture: $arch";;
esac
}
get_kata_hash() {
repo=$1
ref=$2
git ls-remote --heads --tags "https://github.com/${project}/${repo}.git" | grep "${ref}" | awk '{print $1}'
}