Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 911f3bc

Browse files
committed
Sauce Labs tunneling support
1 parent 5be92f5 commit 911f3bc

File tree

8 files changed

+152
-7
lines changed

8 files changed

+152
-7
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ ENV FIREFOX_VERSIONS="${FIREFOX_VERSIONS1}, ${FIREFOX_VERSIONS2}, ${FIREFOX_VERS
766766
SUPERVISOR_HTTP_PASSWORD=somehttpbasicauthpwd \
767767
SUPERVISOR_REQUIRED_SRV_LIST="vnc|novnc|sshd|xmanager|xvfb" \
768768
SLEEP_SECS_AFTER_KILLING_SUPERVISORD=3 \
769+
SUPERVISOR_STOPWAITSECS=20 \
769770
# Supervisor loglevel and also general docker log level
770771
# can be: debug, warn, trace, info
771772
LOG_LEVEL=info \
@@ -811,11 +812,13 @@ ENV FIREFOX_VERSIONS="${FIREFOX_VERSIONS1}, ${FIREFOX_VERSIONS2}, ${FIREFOX_VERS
811812
SAUCE_TUNNEL_ID="docker-selenium" \
812813
SAUCE_TUNNEL_READY_FILE="/tmp/sauce-connect-ready" \
813814
SAUCE_LOCAL_SEL_PORT="4445" \
815+
SAUCE_WAIT_TIMEOUT="100s" \
814816
# BrowserStack tunneling. Naming is required: BSTACK_TUNNEL_ID
815817
BSTACK_TUNNEL="false" \
816818
BSTACK_ACCESS_KEY="" \
817819
BSTACK_TUNNEL_ID="docker-selenium" \
818820
BSTACK_TUNNEL_OPTS="-skipCheck -v -forcelocal" \
821+
BSTACK_WAIT_TIMEOUT="70s" \
819822
# Java stuff
820823
# MEM_JAVA="1024m" \
821824
#===============================

bin/entry.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export DISPLAY=":${DISP_N}"
1111
export XEPHYR_DISPLAY=":${DISP_N}"
1212
export VIDEO_LOG_FILE="${LOGS_DIR}/video-rec-stdout.log"
1313
export VIDEO_PIDFILE="${RUN_DIR}/video.pid"
14+
export SAUCE_LOG_FILE="${LOGS_DIR}/saucelabs-stdout.log"
1415
export BSTACK_LOG_FILE="${LOGS_DIR}/browserstack-stdout.log"
1516
export SUPERVISOR_PIDFILE="${RUN_DIR}/supervisord.pid"
1617
export DOCKER_SELENIUM_STATUS="${LOGS_DIR}/docker-selenium-status.log"
@@ -42,6 +43,8 @@ export FFMPEG_FRAME_SIZE="${SCREEN_WIDTH}x${SCREEN_HEIGHT}"
4243
SUPERVISOR_REQUIRED_SRV_LIST="${SUPERVISOR_REQUIRED_SRV_LIST}|selenium-node-firefox"
4344
[ "${VIDEO}" = "true" ] && export \
4445
SUPERVISOR_REQUIRED_SRV_LIST="${SUPERVISOR_REQUIRED_SRV_LIST}|video-rec"
46+
[ "${SAUCE_TUNNEL}" = "true" ] && export \
47+
SUPERVISOR_REQUIRED_SRV_LIST="${SUPERVISOR_REQUIRED_SRV_LIST}|saucelabs"
4548
[ "${BSTACK_TUNNEL}" = "true" ] && export \
4649
SUPERVISOR_REQUIRED_SRV_LIST="${SUPERVISOR_REQUIRED_SRV_LIST}|browserstack"
4750

browserstack/bin/start-browserstack.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ function shutdown {
4040
exit 0
4141
}
4242

43-
# Wait for the file to exists (Sauce Labs only)
44-
# echo "Waiting for file ${SAUCE_TUNNEL_READY_FILE} to be created..."
45-
# while ! ls -l "${SAUCE_TUNNEL_READY_FILE}"* >/dev/null 2>&1; do sleep 0.1; done
46-
4743
# Now wait for the tunnel to finish starting
48-
timeout --foreground ${WAIT_TIMEOUT} wait-browserstack.sh
44+
timeout --foreground ${BSTACK_WAIT_TIMEOUT} wait-browserstack.sh
4945

5046
# Run function shutdown() when this process a killer signal
5147
trap shutdown SIGTERM SIGINT SIGKILL

saucelabs/bin/start-saucelabs.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
5+
6+
# echo fn that outputs to stderr http://stackoverflow.com/a/2990533/511069
7+
echoerr() {
8+
cat <<< "$@" 1>&2;
9+
}
10+
11+
# print error and exit
12+
die () {
13+
echoerr "ERROR: $1"
14+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "160"
15+
errnum=${2-160}
16+
exit $errnum
17+
}
18+
19+
# Required params
20+
[ -z "${SAUCE_LOCAL_SEL_PORT}" ] && die "Required SAUCE_LOCAL_SEL_PORT"
21+
[ -z "${SAUCE_USER_NAME}" ] && die "Required env var SAUCE_USER_NAME"
22+
[ -z "${SAUCE_API_KEY}" ] && die "Required env var SAUCE_API_KEY"
23+
[ -z "${SAUCE_TUNNEL_READY_FILE}" ] && die "Required SAUCE_TUNNEL_READY_FILE"
24+
[ -z "${SAUCE_TUNNEL_ID}" ] && die "Required env var SAUCE_TUNNEL_ID"
25+
26+
# Wait for this process dependencies
27+
# - none, the tunnel has no dependencies
28+
# timeout --foreground ${WAIT_TIMEOUT} wait-xvfb.sh
29+
30+
# Start tunnel
31+
sc --se-port ${SAUCE_LOCAL_SEL_PORT} \
32+
--user "${SAUCE_USER_NAME}" \
33+
--api-key "${SAUCE_API_KEY}" \
34+
--readyfile "${SAUCE_TUNNEL_READY_FILE}" \
35+
--tunnel-identifier "${SAUCE_TUNNEL_ID}" &
36+
SAUCE_TUNNEL_PID=$!
37+
38+
function shutdown {
39+
echo "Trapped SIGTERM/SIGINT so shutting down Sauce Labs gracefully..."
40+
kill -SIGINT ${SAUCE_TUNNEL_PID}
41+
wait ${SAUCE_TUNNEL_PID}
42+
echo "Sauce Labs tunnel shutdown complete."
43+
exit 0
44+
}
45+
46+
# Wait for the file to exists
47+
echo "Waiting for file ${SAUCE_TUNNEL_READY_FILE} to be created..."
48+
while ! ls -l "${SAUCE_TUNNEL_READY_FILE}" >/dev/null 2>&1; do sleep 0.1; done
49+
50+
# Now wait for the tunnel to finish starting
51+
timeout --foreground ${SAUCE_WAIT_TIMEOUT} wait-saucelabs.sh
52+
53+
# Run function shutdown() when this process a killer signal
54+
trap shutdown SIGTERM SIGINT SIGKILL
55+
56+
# tells bash to wait until child processes have exited
57+
wait

saucelabs/bin/wait-saucelabs.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
5+
6+
# echo fn that outputs to stderr http://stackoverflow.com/a/2990533/511069
7+
echoerr() {
8+
cat <<< "$@" 1>&2;
9+
}
10+
11+
# print error and exit
12+
die () {
13+
echoerr "ERROR: $1"
14+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "160"
15+
errnum=${2-160}
16+
exit $errnum
17+
}
18+
19+
export DONE_MSG="Connection established."
20+
21+
if [ "${SAUCE_TUNNEL}" = "true" ]; then
22+
echo "Waiting for Sauce Labs tunnel to start..."
23+
# Required params
24+
[ -z "${SAUCE_LOG_FILE}" ] && die "Required env var SAUCE_LOG_FILE"
25+
while ! grep "${DONE_MSG}" ${SAUCE_LOG_FILE} >/dev/null; do
26+
echo -n '.'
27+
sleep 0.2;
28+
done
29+
echo "Sauce Labs tunnel started! (wait-saucelabs.sh)"
30+
else
31+
echo "Won't start Sauce Labs tunnel due to SAUCE_TUNNEL false"
32+
fi
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[program:saucelabs]
2+
3+
;The relative priority of the program in the start and shutdown ordering.
4+
;Lower priorities indicate programs that start first and shut down last.
5+
priority=15
6+
7+
;User to run-as, note environment expansion outside of `command` is only
8+
;supported in supervisor >= 3.2
9+
user=%(ENV_NORMAL_USER)s
10+
11+
;The command that will be run when this program is started.
12+
;Controlled programs should themselves not be daemons, as supervisord
13+
;assumes it is responsible for daemonizing its subprocesses
14+
directory=%(ENV_NORMAL_USER_HOME)s
15+
command=%(ENV_BIN_UTILS)s/start-saucelabs.sh
16+
17+
;If true, this program will start automatically when supervisord is started.
18+
;default=true
19+
autostart=%(ENV_SAUCE_TUNNEL)s
20+
21+
;If false, the process will never be autorestarted.
22+
;If true, the process will be unconditionally restarted when it exits,
23+
;without regard to its exit code. default=unexpected
24+
;If unexpected, the process will be restart when the program exits with an
25+
;exit code that is not one of the exit codes associated with this process.
26+
autorestart=false
27+
28+
;Set to 0 to indicate that the program needn’t stay running for any
29+
;particular amount of time.
30+
;So using custom wait-xxxx.sh scripts to perform a more efficient
31+
;active waiting until https://github.com/Supervisor/supervisor/issues/584
32+
startsecs=0
33+
34+
;The number of serial failure attempts that supervisord will allow when
35+
;attempting to start the program before giving up and puting the process
36+
;into an FATAL state.
37+
startretries=0
38+
39+
;Logs
40+
redirect_stderr=false
41+
stdout_logfile=%(ENV_LOGS_DIR)s/saucelabs-stdout.log
42+
stderr_logfile=%(ENV_LOGS_DIR)s/saucelabs-stderr.log
43+
stdout_logfile_maxbytes=%(ENV_LOGFILE_MAXBYTES)s
44+
stderr_logfile_maxbytes=%(ENV_LOGFILE_MAXBYTES)s
45+
stdout_logfile_backups=%(ENV_LOGFILE_BACKUPS)s
46+
stderr_logfile_backups=%(ENV_LOGFILE_BACKUPS)s
47+
stdout_capture_maxbytes=%(ENV_LOGFILE_MAXBYTES)s
48+
stderr_capture_maxbytes=%(ENV_LOGFILE_MAXBYTES)s
49+
50+
;The signal used to kill the program when a stop is requested. This can be
51+
;any of TERM, HUP, INT, QUIT, KILL, USR1, or USR2. default=TERM
52+
stopsignal=INT

supervisor/etc/supervisor/supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ childlogdir=%(ENV_LOGS_DIR)s
3030
;If this number of seconds elapses before supervisord receives a SIGCHILD
3131
;from the process, supervisord will attempt to kill it with a final.
3232
;default=10
33-
stopwaitsecs=1
33+
stopwaitsecs=%(ENV_SUPERVISOR_STOPWAITSECS)s
3434

3535
[unix_http_server]
3636
file=%(ENV_RUN_DIR)s/supervisor.sock

xterm/bin/start-xterm.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ timeout --foreground ${WAIT_TIMEOUT} wait-selenium-node-firefox.sh || shutdown \
5050
"Failed while waiting for selenium node firefox to start!"
5151
timeout --foreground ${WAIT_TIMEOUT} wait-video-rec.sh || shutdown \
5252
"Failed while waiting for video recording to start!"
53-
timeout --foreground ${WAIT_TIMEOUT} wait-browserstack.sh || shutdown \
53+
timeout --foreground ${SAUCE_WAIT_TIMEOUT} wait-saucelabs.sh || shutdown \
54+
"Failed while waiting for Sauce Labs tunnel to start!"
55+
timeout --foreground ${BSTACK_WAIT_TIMEOUT} wait-browserstack.sh || shutdown \
5456
"Failed while waiting for BrowserStack tunnel to start!"
5557

5658
# Help at http://supervisord.org/subprocess.html#process-states

0 commit comments

Comments
 (0)