-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstaging.kernelci.org
executable file
·273 lines (238 loc) · 6.49 KB
/
staging.kernelci.org
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
#!/bin/dash
# Periodic job run on staging.kernelci.org to merge together all the pending
# PRs and update the staging.kernelci.org branches, then update Docker images
# and trigger a full build/test cycle with a kernel branch based on linux-next.
set -e
# Trap function for errors
ABSPATH=$(readlink -f "$0")
ABSDIR=$(dirname "$ABSPATH")
PIDFILE="/tmp/staging.kernelci.org.pid"
crash() {
local exit_code="$?"
# If exit code is 0, then it's not an error
[ "$exit_code" -eq 0 ] && exit 0
# Generate syslog message
logger -t kernelci-deploy "Error in script $0"
# remove pidfile
rm -f $PIDFILE
exit $exit_code
}
trap 'crash' EXIT
# verify if the script is already running
if [ -f $PIDFILE ]; then
pid=$(cat $PIDFILE)
if [ -d /proc/$pid ]; then
echo "Script already running with pid $pid"
exit 1
else
echo "Removing stale pidfile"
rm -f $PIDFILE
fi
fi
# create pidfile
echo $$ > $PIDFILE
cmd_pull() {
echo "Updating local repository"
git pull --ff-only
}
cmd_core() {
echo "Updating kernelci-core"
./pending.py kernelci-core --push
}
cmd_api() {
echo "Updating kernelci-api"
./pending.py kernelci-api --push
}
cmd_pipeline() {
echo "Updating kernelci-pipeline"
./pending.py kernelci-pipeline --push
}
cmd_bootrr() {
echo "Updating bootrr"
./pending.py bootrr --push
}
cmd_buildroot() {
echo "Updating buildroot"
./pending.py buildroot --push
}
cmd_test_definitions() {
echo "Updating test-definitions"
./pending.py test-definitions --push --main=master
./pending.py iec-security --push --main=master
}
cmd_kernel() {
tree="${1:-next}"
echo "Pushing kernel test branch for ${tree}"
case $tree in
next)
url=https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
branch=master
;;
mainline)
url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
branch=master
;;
stable)
url=https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
branch=linux-6.1.y
;;
cip)
url=https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git
branch=linux-5.10.y-cip
;;
android)
url=https://android.googlesource.com/kernel/common
branch=android13-5.15
;;
*)
echo "Unknown tree"
exit 1
;;
esac
./kernel.py \
--push \
--ssh-key=keys/id_rsa_staging.kernelci.org \
--from-url=$url \
--from-branch=$branch \
--branch=staging-"$tree" \
--tag-prefix=staging-"$tree"-
}
cmd_rotate_tree() {
if [ -e .tree ]; then
last=$(cat .tree)
else
last=
fi
case $last in
next)
tree=mainline
;;
mainline)
tree=stable
;;
stable)
tree=next
;;
*)
tree=next
;;
esac
echo $tree > .tree
echo $tree
}
docker_workaround() {
echo "Restarting containerd and docker"
sudo systemctl restart containerd docker
echo "Waiting 5 seconds for services to restart"
sleep 5
~/run-dozzle
}
cmd_api_pipeline() {
compose_files="\
-f docker-compose.yaml \
-f docker-compose-kcidb.yaml \
-f docker-compose-lava.yaml \
-f docker-compose-production.yaml \
"
api_services="api db redis"
echo "Stopping pipeline containers"
cd checkout/kernelci-pipeline
git prune
git fetch origin
git checkout origin/staging.kernelci.org
echo "Pulling pipeline containers"
docker-compose $compose_files pull
docker-compose $compose_files down --remove-orphans || true
# verify if it failed due orphaned network bug
if [ $? -ne 0 ]; then
echo "Failed to stop pipeline containers, restarting containerd and docker"
docker_workaround
echo "Attempting to restart pipeline containers again"
docker-compose $compose_files down --remove-orphans
fi
cd -
#./pending.py kernelci-api --push
echo "Pulling API containers"
cd checkout/kernelci-api
git prune
git fetch origin
git checkout origin/staging.kernelci.org
docker-compose pull $api_services
echo "Stopping API containers"
docker-compose down || true
# verify if it failed due orphaned network bug
if [ $? -ne 0 ]; then
echo "Failed to stop API containers, restarting containerd and docker"
docker_workaround
echo "Attempting to restart API containers again"
docker-compose down
fi
echo "Starting API containers"
docker-compose up -d $api_services
cd -
cd checkout/kernelci-pipeline
#REQUIREMENTS=requirements-dev.txt docker-compose $compose_files build --no-cache
echo "Starting pipeline containers"
SETTINGS=/home/kernelci/config/staging.kernelci.org.secrets.toml \
docker-compose $compose_files up -d
cd -
}
cmd_ghworkflow() {
# fail if .github_token is not set
GH_TOKEN=$(cat .github_token)
if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN is not set"
# The fine-grained token must have the following permission set:
# "Actions" repository permissions (write)
exit 1
fi
# trigger the workflow
echo "Triggering workflow"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/kernelci/kernelci-core/actions/workflows/staging.yml/dispatches \
-d '{"ref":"main","inputs":{}}'
# wait for the workflow to finish
while true; do
echo "Waiting for workflow to finish..."
sleep 10
status=$(curl -s -X GET "https://api.github.com/repos/kernelci/kernelci-core/actions/workflows/staging.yml/runs" | jq -r '.workflow_runs[0].status')
if [ "$status" = "completed" ]; then
break
fi
done
}
cmd_all() {
tree="$1"
[ -z $tree ] && tree=$(cmd_rotate_tree)
echo "Kernel tree: $tree"
cmd_ghworkflow
cmd_pull
#cmd_jenkins
#cmd_core
#cmd_api
#cmd_pipeline
#cmd_bootrr
#cmd_buildroot
#cmd_test_definitions
#cmd_kcidb
#cmd_backend
#cmd_frontend
cmd_kernel $tree
#cmd_docker
#cmd_monitor
cmd_api_pipeline
}
cmd="${1}"
if [ -n "$cmd" ]; then
shift 1
else
cmd="all"
fi
"cmd_"$cmd $@
# remove pidfile
rm -f $PIDFILE
exit 0