-
-
Notifications
You must be signed in to change notification settings - Fork 115
467 lines (432 loc) · 17.8 KB
/
test-online.yml
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
name: Test Online Environment
on:
push:
tags:
- v*
# See https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
workflow_dispatch:
jobs:
envs:
name: envs
steps:
##################################################################################################################
# Git checkout
- name: Checkout repository
uses: actions/checkout@v3
# The github.ref is, for example, refs/tags/v5.0.145 or refs/tags/v5.0-r8
# Generate variables like:
# SRS_TAG=v1.0.52
# SRS_MAJOR=1
# @see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Generate varaiables
run: |
SRS_TAG=$(bash scripts/version.sh)
echo "SRS_TAG=$SRS_TAG" >> $GITHUB_ENV
SRS_MAJOR=$(echo $SRS_TAG| awk -F '.' '{print $1}' |sed 's/v//g')
echo "SRS_MAJOR=$SRS_MAJOR" >> $GITHUB_ENV
SRS_DOMAIN=lego-$(date +%s)-$RANDOM
echo "SRS_DOMAIN=$SRS_DOMAIN" >> $GITHUB_ENV
echo "SRS_TAG:$SRS_TAG, SRS_MAJOR:$SRS_MAJOR, SRS_DOMAIN:$SRS_DOMAIN"
# Map a step output to a job output, see https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
SRS_TAG: ${{ env.SRS_TAG }}
SRS_MAJOR: ${{ env.SRS_MAJOR }}
SRS_DOMAIN: ${{ env.SRS_DOMAIN }}
runs-on: ubuntu-20.04
build-image:
name: Build Image
needs:
- envs
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Build image for platform
run: |
docker build -t platform:latest -f Dockerfile .
docker images
docker save -o platform.tar platform:latest
- uses: actions/upload-artifact@v3
with:
name: platform-cache
path: platform.tar
retention-days: 1
runs-on: ubuntu-20.04
create-vm-domain:
name: Create VM Domain
needs:
- envs
steps:
- name: Covert output to env
run: |
echo "SRS_TAG=${{ needs.envs.outputs.SRS_TAG }}" >> $GITHUB_ENV
echo "SRS_DOMAIN=${{ needs.envs.outputs.SRS_DOMAIN }}" >> $GITHUB_ENV
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
# Note that s-1vcpu-512mb-10gb is too small for test, because it leads to overload and failure due
# to the process kswapd. It is recommendded to use either s-1vcpu-1gb or s-2vcpu-2gb size instead.
- name: Create test machine
run: |
sshkey=$(doctl compute ssh-key list --no-header |grep srs |awk '{print $1}')
doctl compute droplet create $SRS_DOMAIN \
--image ubuntu-20-04-x64 --region sgp1 --size s-1vcpu-1gb \
--ssh-keys $sshkey --wait
- name: Query IP of Server
run: |
SRS_DROPLET_EIP=$(doctl compute droplet get $SRS_DOMAIN --format PublicIPv4 --no-header)
echo "SRS_DROPLET_EIP=$SRS_DROPLET_EIP" >> $GITHUB_ENV
echo "SRS_DROPLET_EIP:$SRS_DROPLET_EIP"
- name: Create domain name
run: |
doctl compute domain records create ossrs.io \
--record-type A --record-name $SRS_DOMAIN --record-data $SRS_DROPLET_EIP \
--record-ttl 3600
# Note that should never list all records.
doctl compute domain records ls ossrs.io |grep lego |wc -l
- name: Tips for Debugging
run: |
echo "Please use the following command to login the server:"
echo " ssh root@$SRS_DROPLET_EIP"
echo "Or check by web console:"
echo " http://$SRS_DOMAIN.ossrs.io"
echo "To terminate immediately:"
echo " ssh root@$SRS_DROPLET_EIP touch ctrl-abort"
echo "To reset the timer:"
echo " ssh root@$SRS_DROPLET_EIP touch ctrl-reset"
echo "To always wait for debugging:"
echo " ssh root@$SRS_DROPLET_EIP touch ctrl-debugging"
echo "Never dispose:"
echo " for((;;)); do ssh root@$SRS_DROPLET_EIP touch ctrl-debugging ctrl-reset; sleep 3; done"
- name: Checkout repository
uses: actions/checkout@v3
- name: Download test file
run: |
curl --location --output test/source.200kbps.768x320.flv \
https://github.com/ossrs/srs/raw/develop/trunk/doc/source.200kbps.768x320.flv
- name: Build package
run: |
# Build files for test, should run in ubuntu20.
bash scripts/setup-ubuntu/build.sh --language en --version $SRS_TAG --output $(pwd)/build
make -j -C test
# All files in provision will be uploaded to server.
mkdir -p provision provision/test
cp test/oryx.test test/source.200kbps.768x320.flv provision/test/
cp scripts/tools/failed-retry.sh provision/
cp build/linux-oryx-en.tar.gz platform/containers/conf/nginx.conf \
scripts/tools/secret.sh provision/
- name: Copy file via ssh key
uses: appleboy/[email protected]
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
port: 22
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
timeout: 600s
source: provision/*
target: /root
- name: Provision server
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
timeout: 600s
script: |
for ((i=0; i<10; i++)); do
apt-get update -y &&
apt-get install -y docker.io nginx unzip net-tools tree &&
echo "Install OK" && break
echo "Install failed, retry" &&
sleep 3
done
docker run --rm -v /usr/bin:/g ossrs/srs:tools \
cp /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /g/
ffmpeg -version
# Move files from provision.
mv -f provision/* .
/etc/init.d/nginx stop
cp nginx.conf /etc/nginx/nginx.conf
sed -i "s/user nginx;/user www-data;/g" /etc/nginx/nginx.conf
mkdir -p /data/config && touch /data/config/nginx.http.conf /data/config/nginx.server.conf
/etc/init.d/nginx start
- name: Wait for domain ready
run: |
for ((i=0; i<100; i++)); do
IP=$(dig +short $SRS_DOMAIN.ossrs.io 2>/dev/null)
if [[ ! -z $IP ]]; then
echo "Domain $SRS_DOMAIN.ossrs.io is ready, IP=$IP"
exit 0
fi
done
echo "Domain $SRS_DOMAIN.ossrs.io is not ready"
exit 1
# Map a step output to a job output, see https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
SRS_DROPLET_EIP: ${{ env.SRS_DROPLET_EIP }}
runs-on: ubuntu-20.04
run-test:
name: Run Test
needs:
- envs
- build-image
- create-vm-domain
steps:
- name: Remove unnecessary files
run: |
df -h
echo ""
echo "After removed some unused files."
echo ""
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/lib/jvm
df -h
- name: Covert output to env
run: |
echo "SRS_TAG=${{ needs.envs.outputs.SRS_TAG }}" >> $GITHUB_ENV
echo "SRS_DOMAIN=${{ needs.envs.outputs.SRS_DOMAIN }}" >> $GITHUB_ENV
echo "SRS_DROPLET_EIP=${{ needs.create-vm-domain.outputs.SRS_DROPLET_EIP }}" >> $GITHUB_ENV
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: platform-cache
- name: Setup the Go
uses: actions/setup-go@v3
with:
go-version: '>=1.16.0'
- name: Build package
run: |
# Build files for test, should run in ubuntu20.
rm -f platform.tar.gz && tar zcf platform.tar.gz platform.tar
# All files in provision will be uploaded to server.
mkdir -p provision
cp platform.tar.gz provision
- name: Copy file via ssh key
uses: appleboy/[email protected]
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
port: 22
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
timeout: 600s
source: provision/*
target: /root
- name: Provision server
env:
SRS_TAG: ${{ env.SRS_TAG }}
SRS_DOMAIN: ${{ env.SRS_DOMAIN }}
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
envs: SRS_TAG,SRS_DOMAIN
timeout: 600s
script: |
# Move files from provision.
mv -f provision/* .
# For manually debugging.
echo "" >> /etc/profile
echo "export SRS_TAG=${SRS_TAG}" >> /etc/profile
echo "export SRS_DOMAIN=${SRS_DOMAIN}" >> /etc/profile
if [[ $(docker images |grep platform |grep -q latest || echo no) == no ]]; then
tar xf platform.tar.gz
docker load -i platform.tar
fi
docker tag platform:latest ossrs/oryx:$SRS_TAG
docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/oryx:$SRS_TAG
docker image prune -f
docker images
tar xf linux-oryx-en.tar.gz
bash oryx/scripts/setup-ubuntu/install.sh
# Setup journald to write logs.
sed -i 's/#Storage=auto/Storage=volatile/g' /etc/systemd/journald.conf
systemctl restart systemd-journald
- name: Run All tests
env:
SRS_TAG: ${{ env.SRS_TAG }}
SRS_DOMAIN: ${{ env.SRS_DOMAIN }}
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
envs: SRS_TAG,SRS_DOMAIN
timeout: 7200s
command_timeout: 7200s
script: |
# We will handle the error by ourselves.
set +e
# Record all logs.
journalctl -u oryx -f >srs.log 2>&1 & pid_srs=$!
journalctl -u nginx -f >nginx.log 2>&1 & pid_nginx=$!
# Restart the service, might fail because journald restarted.
systemctl restart oryx nginx
systemctl status oryx nginx
echo "Wait for service ready." &&
bash secret.sh >./test/.env &&
./test/oryx.test -test.timeout=1h -test.v -endpoint http://$SRS_DOMAIN.ossrs.io \
-srs-log=true -wait-ready=true -init-password=true -check-api-secret=true -init-self-signed-cert=true \
-test.run TestSystem_Empty -no-bilibili-test=true &&
echo "Make upload writable." &&
sudo chmod 777 /data/upload &&
echo "Test HTTP API with self-signed cert." &&
bash secret.sh >./test/.env &&
./test/oryx.test -test.timeout=1h -test.v -wait-ready -endpoint http://$SRS_DOMAIN.ossrs.io \
-srs-log=true -wait-ready=true -init-password=false -check-api-secret=true -no-media-test \
-no-bilibili-test=true &&
echo "Test HTTPS API with self-signed cert." &&
bash secret.sh >./test/.env &&
./test/oryx.test -test.timeout=1h -test.v -wait-ready -endpoint https://$SRS_DOMAIN.ossrs.io \
-srs-log=true -wait-ready=true -init-password=false -check-api-secret=true -no-media-test \
-no-bilibili-test=true &&
echo "Request CERT from letsencrypt." &&
bash secret.sh >./test/.env &&
./test/oryx.test -test.timeout=1h -test.v -endpoint http://$SRS_DOMAIN.ossrs.io \
-srs-log=true -wait-ready=true -init-password=false -check-api-secret=true -domain-lets-encrypt=$SRS_DOMAIN.ossrs.io \
-test.run TestApi_LetsEncryptUpdateCert -no-media-test \
-no-bilibili-test=true &&
echo "Test HTTPS API with letsencrypt cert." &&
bash secret.sh >./test/.env &&
./test/oryx.test -test.timeout=1h -test.v -wait-ready -endpoint https://$SRS_DOMAIN.ossrs.io \
-srs-log=true -wait-ready=true -init-password=false -check-api-secret=true -https-insecure-verify \
-no-media-test -no-bilibili-test=true &&
echo "Run media test with retry" &&
bash secret.sh >./test/.env &&
./failed-retry.sh 5 ./test/oryx.test -test.timeout=1h -test.v -wait-ready -endpoint http://$SRS_DOMAIN.ossrs.io \
-srs-log=true -wait-ready=true -init-password=false -check-api-secret=true -test.run WithStream \
-no-bilibili-test=true
ret=$?; echo "Test result: $ret"
echo "Stop service"
sudo systemctl stop oryx
kill $pid_srs 2>/dev/null
kill $pid_nginx 2>/dev/null
echo "Log of srs.log" && cat srs.log
echo "Log of nginx.log" && cat nginx.log
exit $ret
- name: Write signal file
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
timeout: 600s
script: |
touch ctrl-test-done
# Map a step output to a job output, see https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
SRS_DROPLET_EIP: ${{ env.SRS_DROPLET_EIP }}
runs-on: ubuntu-20.04
dispose-waiting:
name: Dispose Waiting
if: always()
needs:
- envs
- run-test
steps:
- name: Covert output to env
run: |
echo "SRS_DOMAIN=${{ needs.envs.outputs.SRS_DOMAIN }}" >> $GITHUB_ENV
echo "SRS_DROPLET_EIP=${{ needs.run-test.outputs.SRS_DROPLET_EIP }}" >> $GITHUB_ENV
- name: Tips for Debugging
run: |
# We will handle the error by ourselves.
set +e
echo "Please use the following command to login the server:"
echo " ssh root@$SRS_DROPLET_EIP"
echo "Or check by web console:"
echo " http://$SRS_DOMAIN.ossrs.io"
echo "To terminate immediately:"
echo " ssh root@$SRS_DROPLET_EIP touch ctrl-abort"
echo "To reset the timer:"
echo " ssh root@$SRS_DROPLET_EIP touch ctrl-reset"
echo "To always wait for debugging:"
echo " ssh root@$SRS_DROPLET_EIP touch ctrl-debugging"
echo "Never dispose:"
echo " for((;;)); do ssh root@$SRS_DROPLET_EIP touch ctrl-debugging ctrl-reset; sleep 3; done"
if [[ -f test/.env ]]; then
echo "Environment variables:"
cat test/.env
fi
- name: Waiting for error debugging
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
timeout: 3600s
command_timeout: 3600s
script: |
# We will handle the error by ourselves.
set +e
if [[ -f ctrl-test-done && ! -f ctrl-debugging ]]; then
echo "Test done normally."
else
echo "Start service for debugging"
sudo systemctl start oryx
echo "Dispose in 60s..."
for ((i=60; i>0; i--)); do
echo "Dispose in ${i}s..."; sleep 3
if [[ -f ctrl-abort ]]; then echo "Abort by user."; break; fi
if [[ -f ctrl-reset ]]; then echo "Reset by user."; rm -f ctrl-reset; let i=i+600; fi
done
fi
- run: echo OK
# Map a step output to a job output, see https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
SRS_DROPLET_EIP: ${{ env.SRS_DROPLET_EIP }}
runs-on: ubuntu-20.04
dispose-final:
name: Dispose Final
if: always()
needs:
- envs
- dispose-waiting
steps:
- name: Covert output to env
run: |
echo "SRS_DOMAIN=${{ needs.envs.outputs.SRS_DOMAIN }}" >> $GITHUB_ENV
echo "SRS_DROPLET_EIP=${{ needs.dispose-waiting.outputs.SRS_DROPLET_EIP }}" >> $GITHUB_ENV
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Remove temporary VM
run: |
# We will handle the error by ourselves.
set +e
if [[ ! -z $SRS_DOMAIN ]]; then
echo "Remove machine $SRS_DOMAIN" &&
doctl compute droplet delete $SRS_DOMAIN -f
fi
- name: Remove temporary domain
run: |
# We will handle the error by ourselves.
set +e
DOMAIN_ID=$(doctl compute domain records ls ossrs.io --no-header |grep lego |grep $SRS_DOMAIN |awk '{print $1}')
if [[ ! -z $DOMAIN_ID ]]; then
echo "Remove $DOMAIN_ID" &&
doctl compute domain records delete ossrs.io $DOMAIN_ID -f
fi
- run: echo OK
runs-on: ubuntu-20.04
# Final test result, fail if any jobs failed.
test-online-final:
name: test-online-final
needs:
- envs
- run-test
- dispose-final
steps:
- run: echo OK
runs-on: ubuntu-20.04