This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
/
jenkins_job_build.sh
executable file
·370 lines (327 loc) · 10.3 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
export GOPATH=${WORKSPACE}/go
# For all our jobs, golang will be installed using static binaries
export PATH=${GOPATH}/bin:/usr/local/go/bin:/usr/sbin:${PATH}
export GOROOT="/usr/local/go"
# List of all setup flags used by scripts
init_ci_flags() {
# Make jobs work like in CI
# CI disables non-working tests
export CI="true"
export KATA_DEV_MODE="false"
# Install crio
export CRIO="no"
# Install cri-containerd
export CRI_CONTAINERD="no"
# Default cri runtime - used to setup k8s
export CRI_RUNTIME=""
# Ask runtime to only use cgroup at pod level
# Useful for pod overhead
export DEFSANDBOXCGROUPONLY="false"
# Hypervisor to use
export KATA_HYPERVISOR=""
# Install k8s
export KUBERNETES="no"
# Run a subset of k8s e2e test
# Will run quick to ensure e2e setup is OK
# - Use false for PRs
# - Use true for nightly testing
export MINIMAL_K8S_E2E="false"
# Test cgroup v2
export TEST_CGROUPSV2="false"
# Run crio functional test
export TEST_CRIO="false"
# Run docker functional test
export TEST_DOCKER="no"
# Use experimental kernel
# Values: true|false
export experimental_kernel="false"
# Use experimental qemu
export experimental_qemu="false"
# shared fs to use
# Values: 9pfs|virtiofs
export SHARED_FS="9pfs"
# Run the kata-check checks
export RUN_KATA_CHECK="true"
# METRICS_CI flags
# Request to run METRICS_CI
# Values: ""|some value : If empty metrics CI is not enabled
export METRICS_CI=""
# Metrics check values depend in the env it run
# Define a profile to check on PRs
# Values: empty|string : String will be used to find a profile with defined values to check
export METRICS_CI_PROFILE=""
# Check values for a profile defined as CLOUD
# Deprecated use METRICS_CI_PROFILE will be replaced by METRICS_CI_PROFILE=cloud-metrics
export METRICS_CI_CLOUD=""
# Generate a report using a jenkins job data
# Name of the job to get data from
export METRICS_JOB_BASELINE=""
}
source "/etc/os-release" || source "/usr/lib/os-release"
# Run noninteractive on debian and ubuntu
if [ "$ID" == "debian" ] || [ "$ID" == "ubuntu" ]; then
export DEBIAN_FRONTEND=noninteractive
fi
# Unit test issue for RHEL
unit_issue="https://github.com/kata-containers/runtime/issues/1517"
# 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"
[ -z "$kata_repo" ] && echo >&2 "kata repo no provided" && exit 1
tests_repo="${tests_repo:-github.com/kata-containers/tests}"
runtime_repo="${runtime_repo:-github.com/kata-containers/runtime}"
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}
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 "No baremetal cleanup script for arch ${arch}"
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
[ "${ghprbPullId}" ] && [ "${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"
# Run the static analysis tools
if [ -z "${METRICS_CI}" ]; then
# We also run static checks on travis for x86 and ppc64le,
# so run them on jenkins only on architectures that travis
# do not support.
if [ "$arch" = "s390x" ] || [ "$arch" = "aarch64" ]; then
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" "$kata_repo" "$specific_branch"
fi
fi
# Check if we can fastpath return/skip the CI
# Specifically do this **after** we have potentially done the static
# checks, as we always want to run those.
# 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
# Setup Kata Containers Environment
#
# - If the repo is "tests", this will call the script living in that repo
# directly.
# - If the repo is not "tests", call the repo-specific script (which is
# expected to call the script of the same name in the "tests" repo).
case "${CI_JOB}" in
"CLOUD-HYPERVISOR-PODMAN")
export KATA_HYPERVISOR="cloud-hypervisor"
export TEST_CGROUPSV2="true"
;;
"CRI_CONTAINERD_K8S")
# This job only tests containerd + k8s
export CRI_CONTAINERD="yes"
export KUBERNETES="yes"
export CRIO="no"
export OPENSHIFT="no"
;;
"PODMAN")
export TEST_CGROUPSV2="true"
;;
"VIRTIOFS-METRICS-BAREMETAL")
export METRICS_CI="true"
export SHARED_FS="virtiofs"
export METRICS_CI_PROFILE="virtiofs-baremetal"
export experimental_kernel="true"
export experimental_qemu="true"
;;
"SANDBOX_CGROUP_ONLY")
# Used by runtime makefile to enable option on intall
export DEFSANDBOXCGROUPONLY=true
;;
"CLOUD-HYPERVISOR")
export CRIO="no"
export CRI_CONTAINERD="yes"
export CRI_RUNTIME="containerd"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
export OPENSHIFT="no"
export TEST_CRIO="false"
export TEST_DOCKER="true"
;;
"CLOUD-HYPERVISOR-DOCKER")
export CRIO="no"
export CRI_CONTAINERD="no"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="no"
export OPENSHIFT="no"
export TEST_CRIO="false"
export TEST_DOCKER="true"
;;
"CLOUD-HYPERVISOR-K8S-CONTAINERD")
init_ci_flags
export CRI_CONTAINERD="yes"
export CRI_RUNTIME="containerd"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
;;
"CLOUD-HYPERVISOR-K8S-E2E-CRIO-MINIMAL")
init_ci_flags
export CRIO="yes"
export CRI_RUNTIME="crio"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
export MINIMAL_K8S_E2E="true"
;;
"CLOUD-HYPERVISOR-K8S-E2E-CONTAINERD-MINIMAL")
init_ci_flags
export CRI_CONTAINERD="yes"
export CRI_RUNTIME="containerd"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
export MINIMAL_K8S_E2E="true"
;;
"CLOUD-HYPERVISOR-K8S-E2E-CONTAINERD-SHIMV2-MINIMAL")
init_ci_flags
export CRI_CONTAINERD="yes"
export CRI_RUNTIME="containerd"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
export MINIMAL_K8S_E2E="true"
;;
"CLOUD-HYPERVISOR-K8S-E2E-CRIO-FULL")
init_ci_flags
export CRIO="yes"
export CRI_RUNTIME="crio"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
export MINIMAL_K8S_E2E="false"
;;
"CLOUD-HYPERVISOR-K8S-E2E-CONTAINERD-FULL")
init_ci_flags
export CRI_CONTAINERD="yes"
export CRI_RUNTIME="containerd"
export KATA_HYPERVISOR="cloud-hypervisor"
export KUBERNETES="yes"
export MINIMAL_K8S_E2E="false"
;;
"CLOUD-HYPERVISOR-METRICS-BAREMETAL")
init_ci_flags
export KATA_HYPERVISOR="cloud-hypervisor"
export METRICS_CI="true"
export METRICS_CI_PROFILE="clh-baremetal"
export METRICS_JOB_BASELINE="metrics/job/clh-master"
;;
"VIRTIOFS")
init_ci_flags
export SHARED_FS="virtiofs"
export TEST_DOCKER=true
export TEST_CONFORMANCE=true
;;
esac
"${ci_dir_name}/setup.sh"
# Now we have all the components installed, log that info before we
# run the tests.
if command -v kata-runtime; then
echo "Logging kata-env information:"
kata-runtime kata-env
else
echo "WARN: Kata runtime is not installed"
fi
if [ -n "${METRICS_CI}" ]; then
echo "Running the metrics tests:"
"${tests_repo_dir}/.ci/run_metrics_PR_ci.sh"
elif [ -n "${VFIO_CI}" ]; then
pushd "${GOPATH}/src/${tests_repo}"
echo "Installing initrd image:"
export AGENT_INIT=yes TEST_INITRD=yes OSBUILDER_DISTRO=alpine
sudo -E PATH=$PATH "${ci_dir_name}/install_kata_image.sh"
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
else
if [ "${kata_repo}" != "${tests_repo}" ]; then
if [ "${ID}" == "rhel" ] && [ "${kata_repo}" == "${runtime_repo}" ]; then
echo "INFO: issue ${unit_issue}"
else
echo "INFO: Running unit tests for repo $kata_repo"
make test
fi
fi
# Run integration tests
#
# Note: this will run all classes of tests for ${tests_repo}.
"${ci_dir_name}/run.sh"
# Code coverage
bash <(curl -s https://codecov.io/bash)
fi
popd