-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathp
executable file
·795 lines (704 loc) · 26.4 KB
/
p
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
#!/usr/bin/env bash
# One-liner Zalenium & Docker-selenium (dosel) installer
#-- With love by team-tip
# set -e: exit asap if a command exits with a non-zero status
set -e
# In OSX install gtimeout through
# brew install coreutils
function mtimeout() {
if [ "$(uname -s)" = 'Darwin' ]; then
gtimeout "$@"
else
timeout "$@"
fi
}
function please_install_gnu_grep() {
echo "GNU grep is not installed, please install with:"
echo " brew tap homebrew/dupes"
B_VERSION=$(IFS=" " read -r -a array <<< "$(brew -v)" && echo "${array[1]}" && [[ ${array[1]} == 2* ]])
if [ $B_VERSION == 1.* ]; then
echo " brew install grep --with-default-names"
else
echo " brew install grep"
fi
echo ""
exit 16
}
# In OSX install GNU grep through
# brew tap homebrew/dupes
# brew install grep --with-default-names
# /usr/local/Cellar/grep/*/bin/grep --version
function set_mgrep() {
if [ "$(uname -s)" != 'Darwin' ]; then
M_GREP="grep"
else
if grep --version >/dev/null; then
if grep --version | grep GNU >/dev/null; then
# All good here, we can use this default grep.
M_GREP="grep"
else
# Looks like BSD grep is installed so try GNU
if [ -f /usr/local/Cellar/grep/*/bin/grep ]; then
# Found GNU grep installed
M_GREP="/usr/local/Cellar/grep/*/bin/grep"
elif [ -f /usr/local/Cellar/grep/*/bin/ggrep ]; then
# Found GNU grep installed
M_GREP="/usr/local/Cellar/grep/*/bin/ggrep"
else
# Will need to install GNU grep
please_install_gnu_grep
fi
fi
else
# No grep found in the path, try Cellar
if [ -f /usr/local/Cellar/grep/*/bin/grep ]; then
# Found GNU grep installed
M_GREP="/usr/local/Cellar/grep/*/bin/grep"
elif [ -f /usr/local/Cellar/grep/*/bin/ggrep ]; then
# Found GNU grep installed
M_GREP="/usr/local/Cellar/grep/*/bin/ggrep"
else
# Will need to install GNU grep
please_install_gnu_grep
fi
fi
fi
}
export -f set_mgrep
set_mgrep
# In OSX install GNU gsort through
# brew install coreutils
function set_msort() {
if [ "$(uname -s)" = 'Darwin' ]; then
M_SORT="gsort"
else
M_SORT="sort"
fi
}
export -f set_msort
set_msort
# Actively waits for Zalenium to fully starts
# you can copy paste this in your Jenkins scripts
WaitZaleniumStarted()
{
set_mgrep
DONE_MSG="Zalenium is now ready!"
while ! docker logs zalenium | ${M_GREP} "${DONE_MSG}" >/dev/null; do
echo -n '.'
sleep 0.2
done
}
export -f WaitZaleniumStarted
EnsureCleanEnv()
{
local __containers=$(docker ps -a -f name=zalenium_ -q | wc -l)
if [ ${__containers} -gt 0 ]; then
echo "Removing exited docker-selenium containers..."
docker rm -f $(docker ps -a -f name=zalenium_ -q)
fi
}
toolchainStop() {
# This works differently in certain peculiar environment
if [ "${TOOLCHAIN_LOOKUP_REGISTRY}" != "" ]; then
local __video=${VIDEO:-"true"}
if [ "${__video}" == "true" ]; then
rm -rf ./videos || true
/tools/run :stups -v /tmp:/tmp -- \
cp --recursive --copy-contents /tmp/videos/${BUILD_NUMBER} ./videos || true
ls -la ./videos || true
fi
fi
}
getDockerOpts(){
# Supported: 1.11, 1.12, 1.13
local __docker_ver=$(docker --version | ${M_GREP} -Po '(?<=version )([a-z0-9]+\.[a-z0-9]+)')
local __z_default_docker_opts="--name zalenium"
if [ "${USE_NET_HOST}" == "true" ]; then
local __z_docker_opts="${__z_default_docker_opts} --net=host"
else
local __z_docker_opts="${__z_default_docker_opts} -p 4444:4444 ${ADDITIONAL_DOCKER_OPTS}"
fi
local __z_startup_opts=""
local __interactive="${1}"
if [ "${__interactive}" == "true" ]; then
__z_docker_opts="${__z_docker_opts} -t --rm"
else
__z_docker_opts="${__z_docker_opts} -t -d"
fi
if [ -n "${FORCED_DOCKER_OPTS}" ]; then
__z_docker_opts="${FORCED_DOCKER_OPTS}"
else
__z_docker_opts="${__z_docker_opts} ${CUSTOM_DOCKER_OPTS}"
fi
if docker-machine active >/dev/null 2>&1; then
# With docker-machine the file might not be here
# but will be available during docker run.
# Also on some installations executable is in /usr/local/bin
if [ -f /usr/local/bin/docker ]; then
__z_docker_opts="${__z_docker_opts} -v /usr/local/bin/docker:/usr/bin/docker"
else
__z_docker_opts="${__z_docker_opts} -v /usr/bin/docker:/usr/bin/docker"
fi
else
if [ -f /usr/bin/docker ]; then
__z_docker_opts="${__z_docker_opts} -v /usr/bin/docker:/usr/bin/docker"
else
# This should only be necessary in docker native for OSX
__z_docker_opts="${__z_docker_opts} -e DOCKER=${__docker_ver}"
fi
fi
if [ -f /etc/timezone ]; then
__z_startup_opts="${__z_startup_opts} --timeZone $(cat /etc/timezone)"
# TODO: else: Figure out how to get timezone in OSX
fi
# Docker in docker in docker related fixes
if ls /lib/x86_64-linux-gnu/libsystemd-journal.so.0 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /lib/x86_64-linux-gnu/libsystemd-journal.so.0:/lib/x86_64-linux-gnu/libsystemd-journal.so.0:ro"
fi
if ls /lib/x86_64-linux-gnu/libcgmanager.so.0 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /lib/x86_64-linux-gnu/libcgmanager.so.0:/lib/x86_64-linux-gnu/libcgmanager.so.0:ro"
fi
if ls /lib/x86_64-linux-gnu/libnih.so.1 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /lib/x86_64-linux-gnu/libnih.so.1:/lib/x86_64-linux-gnu/libnih.so.1:ro"
fi
if ls /lib/x86_64-linux-gnu/libnih-dbus.so.1 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /lib/x86_64-linux-gnu/libnih-dbus.so.1:/lib/x86_64-linux-gnu/libnih-dbus.so.1:ro"
fi
if ls /lib/x86_64-linux-gnu/libdbus-1.so.3 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /lib/x86_64-linux-gnu/libdbus-1.so.3:/lib/x86_64-linux-gnu/libdbus-1.so.3:ro"
fi
if ls /lib/x86_64-linux-gnu/libgcrypt.so.11 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /lib/x86_64-linux-gnu/libgcrypt.so.11:/lib/x86_64-linux-gnu/libgcrypt.so.11:ro"
fi
if ls /usr/lib/x86_64-linux-gnu/libapparmor.so.1 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /usr/lib/x86_64-linux-gnu/libapparmor.so.1:/usr/lib/x86_64-linux-gnu/libapparmor.so.1:ro"
fi
if ls /usr/lib/x86_64-linux-gnu/libltdl.so.7 >/dev/null 2>&1; then
__z_docker_opts="${__z_docker_opts} -v /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7:ro"
fi
local __start_tunnel=false
local __video=${VIDEO:-"true"}
local __screen_width=${SCREEN_WIDTH:-"1920"}
local __screen_height=${SCREEN_HEIGHT:-"1080"}
local __desired_containers_count=${DESIRED_CONTAINERS_START_COUNT:-"2"}
local __chrome_count=${CHROME_START_COUNT:-"1"}
local __firefox_count=${FIREFOX_START_COUNT:-"1"}
local __max_containers=${MAX_CONTAINERS_COUNT:-"60"}
local __time_zone=${TIME_ZONE:-"Europe/Berlin"}
local __debug_enabled=${DEBUG_ENABLED:-"false"}
local __selenium_image_name=${SELENIUM_IMAGE_NAME:-${docker_selenium_image}}
local __max_test_sessions=${MAX_TEST_SESSIONS:-"1"}
local __keep_only_failed_tests=${KEEP_ONLY_FAILED_TESTS:-"false"}
local __send_anonymous_usage_info=${SEND_ANONYMOUS_USAGE_INFO:-"true"}
if [ "${deprecated_parameters}" == "true" ]; then
__desired_containers_count=$((__chrome_count + __firefox_count))
fi
# Map video folder if videos are enabled
if [ "${__video}" == "true" ]; then
local __videos_dir=""
# This works differently in certain peculiar environment
if [ "${TOOLCHAIN_LOOKUP_REGISTRY}" != "" ]; then
__videos_dir="/tmp/videos/${BUILD_NUMBER}"
export HOST_UID="$(id -u)"
export HOST_GID="$(id -g)"
docker run --rm -v /tmp:/tmp alpine mkdir -p ${__videos_dir} >&2
docker run --rm -v /tmp:/tmp alpine chown -R ${HOST_UID}:${HOST_GID} ${__videos_dir} >&2
else
__videos_dir=${VIDEOS_DIR:-"/tmp/videos"}
mkdir -p "${__videos_dir}"
fi
__z_docker_opts="${__z_docker_opts} -v ${__videos_dir}:/home/seluser/videos"
fi
# Pre-alpha Android emulation in Appium - appium port (4723)
if [ "${APPIUM_PORT}" != "" ]; then
# Only export ports when not using --net=host
if [ "${USE_NET_HOST}" != "true" ]; then
__z_docker_opts="${__z_docker_opts} -p ${APPIUM_PORT}:${APPIUM_PORT}"
fi
fi
# Pre-alpha Android emulation in Appium - vnc port (6080)
if [ "${APPIUM_VNC}" != "" ]; then
# Only export ports when not using --net=host
if [ "${USE_NET_HOST}" != "true" ]; then
__z_docker_opts="${__z_docker_opts} -p ${APPIUM_VNC}:${APPIUM_VNC}"
fi
fi
# Sauce Labs
if [ "${SAUCE_USERNAME}" == "" ]; then
echo "WARN: Sauce Labs will not be enabled because the var \$SAUCE_USERNAME is NOT present" >&2
SAUCE_LABS_ENABLED=false
else
echo "INFO: Sauce Labs will be enabled because the var \$SAUCE_USERNAME is present" >&2
if [ "${SAUCE_ACCESS_KEY}" == "" ]; then
echo "\$SAUCE_USERNAME is set but \$SAUCE_ACCESS_KEY is not so failing..." >&2
exit 17
fi
SAUCE_LABS_ENABLED=true
export SAUCE_TUNNEL_ID="zalenium${BUILD_NUMBER}"
__start_tunnel=true
fi
# BrowserStack
if [ "${BROWSER_STACK_USER}" == "" ]; then
echo "WARN: BrowserStack will not be enabled because the var \$BROWSER_STACK_USER is NOT present" >&2
BROWSER_STACK_ENABLED=false
else
echo "INFO: BrowserStack will be enabled because the var \$BROWSER_STACK_USER is present" >&2
if [ "${BROWSER_STACK_KEY}" == "" ]; then
echo "\$BROWSER_STACK_USER is set but \$BROWSER_STACK_KEY is not so failing..." >&2
exit 18
fi
BROWSER_STACK_ENABLED=true
export BROWSER_STACK_TUNNEL_ID="zalenium${BUILD_NUMBER}"
__start_tunnel=true
fi
# Testing Bot
if [ "${TESTINGBOT_SECRET}" == "" ]; then
echo "WARN: Testing Bot will not be enabled because the var \$TESTINGBOT_SECRET is NOT present" >&2
TESTINGBOT_ENABLED=false
else
echo "INFO: Testing Bot will be enabled because the var \$TESTINGBOT_SECRET is present" >&2
if [ "${TESTINGBOT_KEY}" == "" ]; then
echo "\$TESTINGBOT_SECRET is set but \$TESTINGBOT_KEY is not so failing..." >&2
exit 19
fi
TESTINGBOT_ENABLED=true
__start_tunnel=true
fi
mkdir -p /tmp/mounted
echo ${__z_docker_opts} \
-e BUILD_URL="${BUILD_URL}" \
-e CDP_TARGET_REPOSITORY="${CDP_TARGET_REPOSITORY}" \
-e KUBERNETES_ENABLED="${KUBERNETES_ENABLED}" \
-e SAUCE_USERNAME="${SAUCE_USERNAME}" \
-e SAUCE_ACCESS_KEY="${SAUCE_ACCESS_KEY}" \
-e SAUCE_TUNNEL_ID="${SAUCE_TUNNEL_ID}" \
-e BROWSER_STACK_USER="${BROWSER_STACK_USER}" \
-e BROWSER_STACK_KEY="${BROWSER_STACK_KEY}" \
-e BROWSER_STACK_TUNNEL_ID="${BROWSER_STACK_TUNNEL_ID}" \
-e TESTINGBOT_SECRET="${TESTINGBOT_SECRET}" \
-e TESTINGBOT_KEY="${TESTINGBOT_KEY}" \
-e HOST_UID="$(id -u)" \
-e HOST_GID="$(id -g)" \
-v /var/run/docker.sock:/var/run/docker.sock \
--privileged \
-v /tmp/mounted:/tmp/mounted \
-v /dev/shm:/dev/shm \
--label zalenium_main \
${zalenium_image}:${zalenium_tag} \
start ${__z_startup_opts} \
--desiredContainers "${__desired_containers_count}" \
--maxDockerSeleniumContainers "${__max_containers}" \
--screenWidth "${__screen_width}" --screenHeight "${__screen_height}" \
--videoRecordingEnabled "${__video}" \
--sauceLabsEnabled ${SAUCE_LABS_ENABLED} \
--browserStackEnabled ${BROWSER_STACK_ENABLED} \
--testingBotEnabled ${TESTINGBOT_ENABLED} \
--startTunnel "${__start_tunnel}" \
--timeZone "${__time_zone}" \
--debugEnabled "${__debug_enabled}" \
--seleniumImageName "${__selenium_image_name}" \
--maxTestSessions "${__max_test_sessions}" \
--keepOnlyFailedTests "${__keep_only_failed_tests}" \
--sendAnonymousUsageInfo "${__send_anonymous_usage_info}"
}
ShutDownZalenium(){
echo "Terminating Zalenium properly..."
local __containers=$(docker ps -q --filter "label=zalenium_main" | wc -l)
if [ ${__containers} -gt 0 ]; then
if [ -z "${INTERACTIVE}" ]; then
docker logs zalenium
fi
docker attach --no-stdin zalenium &
if [ "${TOOLCHAIN_LOOKUP_REGISTRY}" != "" ]; then
echo "Waiting for video processing..."
sleep 60
fi
docker stop --time 90 zalenium
fi
__containers=$(docker ps -a -q --filter "label=zalenium_main" | wc -l)
if [ ${__containers} -gt 0 ]; then
docker rm zalenium
fi
__containers=$(docker ps -a -q --filter "label=zalenium_main" | wc -l)
if [ ${__containers} -gt 0 ]; then
docker rm -f zalenium
fi
toolchainStop
EnsureCleanEnv
echo "Zalenium stopped!"
exit 0
}
StartZalenium(){
echo "Starting Zalenium in docker..."
local opts="$(getDockerOpts ${INTERACTIVE})"
docker run ${opts}
if [ -z "${INTERACTIVE}" ]; then
# When running in daemon mode we want to wait for Zalenium to start
# before returning the prompt to the user
if ! mtimeout --foreground "2m" bash -c WaitZaleniumStarted; then
echo "Zalenium failed to start after 2 minutes, failing..."
docker logs zalenium
exit 4
fi
echo "Zalenium in docker started!"
fi
}
function InstallDockerCompose() {
DOCKER_COMPOSE_VERSION="1.9.0"
PLATFORM=`uname -s`-`uname -m`
url="https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-${PLATFORM}"
curl -ssL "${url}" >docker-compose
chmod +x docker-compose
if [ "${we_have_sudo}" == "true" ]; then
sudo rm -f /usr/bin/docker-compose
sudo rm -f /usr/local/bin/docker-compose
sudo mv docker-compose /usr/local/bin
docker-compose --version
else
./docker-compose --version
fi
}
# VersionGt tell if the 1st argument version is greater than the 2nd
# VersionGt "1.12.3" "1.11" #=> exit 0
# VersionGt "1.12.3" "1.12" #=> exit 0
# VersionGt "1.12.3" "1.13" #=> exit 1
# VersionGt "1.12.3" "1.12.3" #=> exit 1
function VersionGt() {
test "$(printf '%s\n' "$@" | ${M_SORT} -V | head -n 1)" != "$1";
}
function CheckDependencies() {
# TODO: Only check upon new Zalenium versions
echo -n "${checking_and_or_updating} dependencies... "
if ! which test >/dev/null; then
echo "Please install test"
echo " brew install coreutils"
exit 1
fi
if ! which printf >/dev/null; then
echo "Please install printf"
echo " brew install coreutils"
exit 2
fi
if ! ${M_SORT} --version >/dev/null; then
echo "Please install ${M_SORT} (GNU sort)"
echo " brew install coreutils"
exit 3
fi
if ! ${M_GREP} --version >/dev/null; then
please_install_gnu_grep
fi
if ! which wc >/dev/null; then
echo "Please install wc"
echo " brew install coreutils"
exit 5
fi
if ! which head >/dev/null; then
echo "Please install head"
echo " brew install coreutils"
exit 6
fi
if ! perl --version >/dev/null; then
echo "Please install perl, e.g. brew install perl"
exit 7
fi
if ! wget --version >/dev/null; then
echo "Please install wget, e.g. brew install wget"
exit 8
fi
if ! jq --version >/dev/null; then
echo "Please install jq, e.g. brew install jq"
exit 20
fi
if ! mtimeout --version >/dev/null; then
echo "Please install GNU timeout"
echo " brew install coreutils"
exit 10
fi
if ! docker --version >/dev/null; then
echo "Please install docker, e.g. brew install docker"
exit 11
fi
# Grab docker version, e.g. "1.12.3"
DOCKER_VERSION=$(docker --version | ${M_GREP} -Po '(?<=version )([a-z0-9\.]+)')
# Check supported docker range of versions, e.g. > 1.11.0
if ! VersionGt "${DOCKER_VERSION}" "1.11.0"; then
echo "Current docker version '${DOCKER_VERSION}' is not supported by Zalenium"
echo "Docker version >= 1.11.1 is required"
exit 12
fi
# Note it doesn't matter if the container named `grid` exists
# `docker ps` will only fail if docker is not running
if ! docker ps -q --filter=name=grid >/dev/null; then
echo "Docker is installed but doesn't seem to be running properly."
echo "Make sure docker commands like 'docker ps' work."
exit 13
fi
if ! docker ps -a -q --filter "label=zalenium_main" >/dev/null; then
echo "Docker is installed but the current version doesn't support --filter."
echo "Make sure you have a recent or latest version of Docker."
exit 21
fi
if ! docker-compose --version >/dev/null 2>&1; then
echo "--INFO: docker-compose is not installed"
else
# Grab docker-compose version, e.g. "1.9.0"
DOCKER_COMPOSE_VERSION=$(docker-compose --version | ${M_GREP} -Po '(?<=version )([a-z0-9\.]+)')
# Check supported docker-compose range of versions, e.g. > 1.7.0
if ! VersionGt "${DOCKER_COMPOSE_VERSION}" "1.7.0"; then
echo "Current docker-compose version '${DOCKER_COMPOSE_VERSION}' is not supported by Zalenium"
if [ "${upgrade_if_needed}" == "true" ]; then
echo "Will upgrade docker-compose because you passed the 'upd' argument"
#InstallDockerCompose
else
echo "Docker-compose version >= 1.7.1 is required"
exit 14
fi
fi
fi
# If we have docker-machine then docker.sock is not in the current host
if ! docker-machine active >/dev/null 2>&1; then
if ! ls /var/run/docker.sock >/dev/null; then
echo "ERROR: Zalenium needs /var/run/docker.sock but couldn't find it!"
exit 15
fi
fi
echo "Done ${checking_and_or_updating} dependencies."
}
function PullDependencies() {
# Retry pulls up to 3 times as networks are known to be unreliable
# https://github.com/zalando/zalenium
docker pull ${zalenium_image}:${zalenium_tag} || \
docker pull ${zalenium_image}:${zalenium_tag} || \
docker pull ${zalenium_image}:${zalenium_tag}
[ -z "${docker_selenium_tag}" ] && docker_selenium_tag="${zalenium_tag}"
# https://github.com/elgalu/docker-selenium
docker pull ${docker_selenium_image}:${docker_selenium_tag} || \
docker pull ${docker_selenium_image}:${docker_selenium_tag} || \
docker pull ${docker_selenium_image}:${docker_selenium_tag}
}
function usage() {
echo "Usage:"
echo ""
echo "$0"
echo -e "\t -h, --help\t\t\tPrint usage"
echo ""
echo -e "\t Start/stop:"
echo ""
echo -e "\t start, -s, --start\t\tStart Zalenium"
echo -e "\t stop, --stop\t\t\tStop Zalenium"
echo -e "\t -i, --interactive\t\tAttach to current process (default detached)"
echo -e "\t --docker-opt\t\t\tCustom Zalenium docker startup options"
echo -e "\t --force-docker-opts\t\tOverwrite the default Zalenium docker startup options"
echo -e "\t --tag\t\t\t\tUse a specific tag of Zalenium and Docker-Selenium from Zalando's open source registry"
#echo -e "\t -u ." //TODO: define upgrade mechanism
echo ""
echo -e "\t Tests:"
echo ""
echo -e "\t --desiredContainers\t\tNumber of nodes/containers created on startup. Default is 2."
echo -e "\t --maxDockerSeleniumContainers\tMax number of docker-selenium containers running at the same time (default 10)"
echo -e "\t --sauceLabsEnabled\t\tDetermines if the Sauce Labs node is started (default true)"
echo -e "\t --videoRecordingEnabled\tRecord video of tests (default true)"
echo -e "\t --videos-dir\t\t\tDirectory where to store videos (default /tmp/videos)"
echo -e "\t --screenWidth\t\t\tSets the screen width (default 1900)"
echo -e "\t --screenHeight\t\t\tSets the screen height (default 1800)"
echo -e "\t --timeZone\t\t\tSets the time zone in the containers (default \"Europe/Berlin\")"
echo -e "\t --sendAnonymousUsageInfo\tCollects anonymous usage of the tool. Defaults to 'true'"
echo -e "\t --debugEnabled\t\t\tEnables LogLevel.FINE. Defaults to 'false'"
echo -e "\t --seleniumImageName\t\tEnables overriding of the Docker selenium image to use. Defaults to \"elgalu/selenium\""
echo -e "\t --maxTestSessions\t\tMax amount of tests executed per container, defaults to '1'."
echo -e "\t --keepOnlyFailedTests\t\tKeeps only videos of failed tests (you need to send a cookie). Defaults to 'false'"
echo ""
echo ""
echo -e "\t Examples:"
echo ""
echo -e "\t - Starting Zalenium with 2 nodes/containers and without Sauce Labs"
echo -e "\t start --desiredContainers 2 --sauceLabsEnabled false"
echo -e "\t - Starting Zalenium screen width 1440 and height 810, time zone \"America/Montreal\""
echo -e "\t start --screenWidth 1440 --screenHeight 810 --timeZone \"America/Montreal\""
}
#----------
# Defaults
#----------
upgrade_if_needed="false"
we_have_sudo="true"
start_it="false"
stop_it="false"
zalenium_image="dosel/zalenium"
docker_selenium_image="elgalu/selenium"
zalenium_tag="latest"
deprecated_parameters="false"
# Overwrite defaults in certain peculiar environments
if [ "${TOOLCHAIN_LOOKUP_REGISTRY}" != "" ]; then
upgrade_if_needed="true"
we_have_sudo="false"
fi
#---------------------
# Parse CLI arguments
#---------------------
while [ "$1" != "" ]; do
# PARAM="$(echo $1)"
PARAM="$1"
case ${PARAM} in
-h | --help)
usage
exit 0
;;
--upgrade_if_needed)
upgrade_if_needed="true"
;;
--upd)
upgrade_if_needed="true"
;;
upd)
upgrade_if_needed="true"
;;
-u)
upgrade_if_needed="true"
;;
u)
upgrade_if_needed="true"
;;
no-sudo)
we_have_sudo="false"
;;
--no-sudo)
we_have_sudo="false"
;;
-i | --interactive)
INTERACTIVE="true"
;;
--docker-opt)
CUSTOM_DOCKER_OPTS="${CUSTOM_DOCKER_OPTS} ${2}"
shift
;;
--force-docker-opts)
FORCED_DOCKER_OPTS="${FORCED_DOCKER_OPTS} ${2}"
shift
;;
--start)
start_it="true"
;;
start)
start_it="true"
;;
-s)
start_it="true"
;;
s)
start_it="true"
;;
--stop)
stop_it="true"
;;
stop)
stop_it="true"
;;
--tag)
zalenium_tag="${2}"
docker_selenium_tag="${2}"
zalenium_image="registry.opensource.zalan.do/tip/zalenium"
docker_selenium_image="registry.opensource.zalan.do/tip/docker-selenium"
shift
;;
--desiredContainers)
deprecated_parameters="false"
DESIRED_CONTAINERS_START_COUNT="${2}"
shift
;;
--chromeContainers)
echo "Using DEPRECATED --chromeContainers parameter, will fallback to --desiredContainers with the sum of Chrome and Firefox."
deprecated_parameters="true"
CHROME_START_COUNT="${2}"
shift
;;
--firefoxContainers)
echo "Using DEPRECATED --firefoxContainers parameter, will fallback to --desiredContainers with the sum of Chrome and Firefox."
deprecated_parameters="true"
FIREFOX_START_COUNT="${2}"
shift
;;
--maxDockerSeleniumContainers)
MAX_CONTAINERS_COUNT="${2}"
shift
;;
--screenWidth)
SCREEN_WIDTH="${2}"
shift
;;
--screenHeight)
SCREEN_HEIGHT="${2}"
shift
;;
--videoRecordingEnabled)
VIDEO="${2}"
shift
;;
--videos-dir)
VIDEOS_DIR="${2}"
shift
;;
--timeZone)
TIME_ZONE="${2}"
shift
;;
--debugEnabled)
DEBUG_ENABLED="${2}"
shift
;;
--seleniumImageName)
SELENIUM_IMAGE_NAME="${2}"
shift
;;
--maxTestSessions)
MAX_TEST_SESSIONS="${2}"
shift
;;
--keepOnlyFailedTests)
KEEP_ONLY_FAILED_TESTS="${2}"
shift
;;
--sendAnonymousUsageInfo)
SEND_ANONYMOUS_USAGE_INFO="${2}"
shift
;;
3)
zalenium_tag="3"
;;
2)
echo "Unsupported version 2 so falling back to Selenium 3"
zalenium_tag="3"
;;
3*)
echo "Will use zalenium:${PARAM} and docker-selenium:3"
zalenium_tag="${PARAM}"
docker_selenium_tag="3"
;;
2*)
zalenium_tag="$1"
echo "Will use zalenium:${zalenium_tag}"
;;
*)
echo "ERROR: unknown parameter \"${PARAM}\""
usage
exit 10
;;
esac
shift 1
done
trap ShutDownZalenium SIGTERM SIGINT
if [ "${stop_it}" == "true" ]; then
ShutDownZalenium
fi
if [ "${upgrade_if_needed}" == "true" ]; then
checking_and_or_updating="Checking and updating"
else
checking_and_or_updating="Checking"
fi
CheckDependencies
if [ "${PULL_DEPENDENCIES}" != "false" ]; then
PullDependencies
fi
if [ "${start_it}" == "true" ]; then
EnsureCleanEnv
StartZalenium
fi