forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins_job_build.sh
executable file
·237 lines (196 loc) · 7.01 KB
/
jenkins_job_build.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash
#
# Copyright (c) 2018-2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
cidir=$(dirname "$0")
source "/etc/os-release" || source "/usr/lib/os-release"
CI_JOB=${CI_JOB:-}
ghprbPullId=${ghprbPullId:-}
ghprbTargetBranch=${ghprbTargetBranch:-}
GIT_BRANCH=${GIT_BRANCH:-}
KATA_DEV_MODE=${KATA_DEV_MODE:-}
METRICS_CI=${METRICS_CI:-false}
WORKSPACE=${WORKSPACE:-}
BAREMETAL=${BAREMETAL:-false}
TMPDIR=${TMPDIR:-}
# Run noninteractive on ubuntu
if [ "$ID" == "ubuntu" ]; then
export DEBIAN_FRONTEND=noninteractive
fi
# Signify to all scripts that they are running in a CI environment
[ -z "${KATA_DEV_MODE}" ] && export CI=true
# Name of the repo that we are going to test
export kata_repo="$1"
echo "Setup env for kata repository: $kata_repo"
tests_repo="${tests_repo:-github.com/kata-containers/tests}"
katacontainers_repo="${katacontainers_repo:-github.com/kata-containers/kata-containers}"
if [ "${kata_repo}" == "${katacontainers_repo}" ]; then
ci_dir_name="ci"
else
ci_dir_name=".ci"
fi
# This script is intended to execute under Jenkins
# If we do not know where the Jenkins defined WORKSPACE area is
# then quit
if [ -z "${WORKSPACE}" ]; then
echo "Jenkins WORKSPACE env var not set - exiting" >&2
exit 1
fi
# Put our go area into the Jenkins job WORKSPACE tree
export GOPATH=${WORKSPACE}/go
mkdir -p "${GOPATH}"
# Export all environment variables needed.
export GOROOT="/usr/local/go"
export PATH=${GOPATH}/bin:/usr/local/go/bin:/usr/sbin:/sbin:${PATH}
# Support Golang 1.16.x.
# By default in Golang >= 1.16 GO111MODULE is set to "on",
# some subprojects in this repo may not support "go modules",
# set GO111MODULE to "auto" to enable module-aware mode only when
# a go.mod file is present in the current directory.
export GO111MODULE="auto"
kata_repo_dir="${GOPATH}/src/${kata_repo}"
tests_repo_dir="${GOPATH}/src/${tests_repo}"
# Get the tests repository
mkdir -p $(dirname "${tests_repo_dir}")
[ -d "${tests_repo_dir}" ] || git clone "https://${tests_repo}.git" "${tests_repo_dir}"
arch=$("${tests_repo_dir}/.ci/kata-arch.sh")
# Get the repository of the PR to be tested
mkdir -p $(dirname "${kata_repo_dir}")
[ -d "${kata_repo_dir}" ] || git clone "https://${kata_repo}.git" "${kata_repo_dir}"
# If CI running on bare-metal, a few clean-up work before walking into test repo
if [ "${BAREMETAL}" == true ]; then
echo "Looking for baremetal cleanup script for arch ${arch}"
clean_up_script=("${tests_repo_dir}/.ci/${arch}/clean_up_${arch}.sh") || true
if [ -f "${clean_up_script}" ]; then
echo "Running baremetal cleanup script for arch ${arch}"
tests_repo="${tests_repo}" "${clean_up_script}"
else
echo "Running common baremetal cleanup script"
tests_repo="${tests_repo}" "${tests_repo_dir}/.ci/clean_up.sh"
fi
fi
# $TMPDIR may be set special value on BAREMETAL CI.
# e.g. TMPDIR="/tmp/kata-containers" on ARM CI node.
if [ -n "${TMPDIR}" ]; then
mkdir -p "${TMPDIR}"
fi
pushd "${kata_repo_dir}"
pr_number=
branch=
# $ghprbPullId and $ghprbTargetBranch are variables from
# the Jenkins GithubPullRequestBuilder Plugin
[ -n "${ghprbPullId}" ] && [ -n "${ghprbTargetBranch}" ] && export pr_number="${ghprbPullId}"
# Install go after repository is cloned and checkout to PR
# This ensures:
# - We have latest changes in install_go.sh
# - We got get changes if versions.yaml changed.
"${GOPATH}/src/${tests_repo}/.ci/install_go.sh" -p -f
if [ -n "$pr_number" ]; then
export branch="${ghprbTargetBranch}"
export pr_branch="PR_${pr_number}"
else
export branch="${GIT_BRANCH/*\//}"
fi
# Resolve kata dependencies
"${GOPATH}/src/${tests_repo}/.ci/resolve-kata-dependencies.sh"
# Check if we can fastpath return/skip the CI
# Work around the 'set -e' dying if the check fails by using a bash
# '{ group command }' to encapsulate.
{
if [ "${pr_number:-}" != "" ]; then
echo "Testing a PR check if can fastpath return/skip"
"${tests_repo_dir}/.ci/ci-fast-return.sh"
ret=$?
else
echo "not a PR will run all the CI"
ret=1
fi
} || true
if [ "$ret" -eq 0 ]; then
echo "Short circuit fast path skipping the rest of the CI."
exit 0
fi
# Run the static analysis tools
if [ "${METRICS_CI}" = "false" ]; then
# We run static checks on GitHub Actions for x86_64,
# hence run them on Jenkins for non-x86_64 only.
if [ "$arch" != "x86_64" ]; then
if [ "${kata_repo}" == "${katacontainers_repo}" ]; then
make -C src/runtime pkg/katautils/config-settings.go
fi
specific_branch=""
# If not a PR, we are testing on stable or master branch.
[ -z "$pr_number" ] && specific_branch="true"
"${ci_dir_name}/static-checks.sh" --only-arch "$kata_repo" "$specific_branch"
fi
fi
# Source the variables needed for setup the system and run the tests
# according to the job type.
pushd "${GOPATH}/src/${tests_repo}"
source ".ci/ci_job_flags.sh"
source "${cidir}/lib.sh"
popd
"${ci_dir_name}/setup.sh"
# Use virtio-9p on s390x -- https://github.com/kata-containers/tests/issues/3998 for tracking
[ "$arch" = s390x ] && sudo -E "${GOPATH}/src/${tests_repo}/${cidir}/set_kata_config.sh" shared_fs virtio-9p
# Run unit tests on non x86_64
if [[ "$arch" == "s390x" || "$arch" == "aarch64" ]]; then
echo "Running unit tests"
sudo chown -R "$USER" "$HOME/.cargo" || true
"$ci_dir_name/install_rust.sh" && source "$HOME/.cargo/env"
pushd "${GOPATH}/src/${katacontainers_repo}"
echo "Installing libseccomp library from sources"
libseccomp_install_dir=$(mktemp -d -t libseccomp.XXXXXXXXXX)
gperf_install_dir=$(mktemp -d -t gperf.XXXXXXXXXX)
sudo -E ./ci/install_libseccomp.sh "${libseccomp_install_dir}" "${gperf_install_dir}"
echo "Set environment variables for the libseccomp crate to link the libseccomp library statically"
export LIBSECCOMP_LINK_TYPE=static
export LIBSECCOMP_LIB_PATH="${libseccomp_install_dir}/lib"
sudo -E PATH=$PATH make test
popd
else
echo "Skip running unit tests because it is assumed to run elsewhere"
fi
if [ "${CI_JOB}" == "VFIO" ]; then
pushd "${GOPATH}/src/${tests_repo}"
ci_dir_name=".ci"
echo "Installing initrd image"
sudo -E AGENT_INIT=yes TEST_INITRD=yes osbuilder_distro=alpine PATH=$PATH "${ci_dir_name}/install_kata_image.sh"
echo "Installing kernel"
sudo -E PATH=$PATH "${ci_dir_name}/install_kata_kernel.sh"
echo "Installing Cloud Hypervisor"
sudo -E PATH=$PATH "${ci_dir_name}/install_cloud_hypervisor.sh"
echo "Running VFIO tests"
"${ci_dir_name}/run.sh"
popd
elif [ "${METRICS_CI}" == "false" ]; then
# Run integration tests
#
# Note: this will run all classes of tests for ${tests_repo}.
"${ci_dir_name}/run.sh"
else
echo "Running the metrics tests:"
"${ci_dir_name}/run.sh"
fi
test_snap_build() {
if [[ "${ID}" == "ubuntu" && "$(uname -m)" != "x86_64" ]]; then
echo "Test snap build"
sudo apt install -y snapcraft
[ ! -d "${katacontainers_repo_dir}" ] && go get -d "${katacontainers_repo}" || true
pushd "${katacontainers_repo_dir}"
sudo snapcraft -d snap --destructive-mode
# PREFIX is changed in snap build, change it back
PREFIX=
popd
else
echo "Skipping snap test because it is assumed to run elsewhere"
fi
}
test_snap_build
popd