From cf4d72575af68f22e322feaaf3a80d8a9eb6af6d Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 6 Feb 2024 12:44:25 +0100 Subject: [PATCH 01/15] usbmuxd connection check was modified --- files/start_all.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index 19ca898..53bb84f 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -27,8 +27,8 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then # start socat client and connect to appium usbmuxd socket rm -f /var/run/usbmuxd socat UNIX-LISTEN:/var/run/usbmuxd,fork,reuseaddr,mode=777 TCP:${USBMUXD_SOCKET_ADDRESS} & - if [[ -S /var/run/usbmuxd ]]; then - echo "Usbmuxd socket was created" + timeout 10 bash -c 'until [[ -S /var/run/usbmuxd ]]; do sleep 1; else echo "Usbmuxd socket was created"; done' + if [[ $? -eq 0 ]]; then socketCreated=1 break fi From 5b59d2c294c954c9b776735a64a6035ab17a820f Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 6 Feb 2024 12:44:50 +0100 Subject: [PATCH 02/15] fix misprint --- files/start_all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/start_all.sh b/files/start_all.sh index 53bb84f..766d508 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -114,7 +114,7 @@ elif [ "${PLATFORM_NAME}" == "ios" ]; then echo "Linked appium container is up and running." else echo "ERROR! Unable to get WDA status successfully!" - exit -1 + exit 1 fi From 6049ff45a28efc61d5700765c62ffaf486af9aa1 Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 6 Feb 2024 12:45:13 +0100 Subject: [PATCH 03/15] wda check status was modified --- files/start_all.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index 766d508..e3eca08 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -109,8 +109,13 @@ elif [ "${PLATFORM_NAME}" == "ios" ]; then ##Hit the WDA status URL to see if it is available RETRY_DELAY=$(( $WDA_WAIT_TIMEOUT / 3 )) - if curl --retry 3 --retry-delay ${RETRY_DELAY} -Is "http://${WDA_HOST}:${WDA_PORT}/status" | head -1 | grep -q '200 OK' - then + timeout "$WDA_WAIT_TIMEOUT" bash -c " + until curl -sf \"http://${WDA_HOST}:${WDA_PORT}/status\"; + do + echo \"http://${WDA_HOST}:${WDA_PORT}/status endpoint not available, one more attempt\"; + sleep ${RETRY_DELAY}; + done" + if [[ $? -eq 0 ]]; then echo "Linked appium container is up and running." else echo "ERROR! Unable to get WDA status successfully!" From 9e2945648717876fd698ce564f393c49c2459263 Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 6 Feb 2024 12:53:18 +0100 Subject: [PATCH 04/15] /var/run/usbmuxd socket check fixed --- files/start_all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/start_all.sh b/files/start_all.sh index e3eca08..1cfee69 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -27,7 +27,7 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then # start socat client and connect to appium usbmuxd socket rm -f /var/run/usbmuxd socat UNIX-LISTEN:/var/run/usbmuxd,fork,reuseaddr,mode=777 TCP:${USBMUXD_SOCKET_ADDRESS} & - timeout 10 bash -c 'until [[ -S /var/run/usbmuxd ]]; do sleep 1; else echo "Usbmuxd socket was created"; done' + timeout 10 bash -c 'until [[ -S /var/run/usbmuxd ]]; do sleep 1; echo "/var/run/usbmuxd socket existence check"; done' if [[ $? -eq 0 ]]; then socketCreated=1 break From d5d6ffb077699a6478bc3342188aea26b5989033 Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 6 Feb 2024 13:18:48 +0100 Subject: [PATCH 05/15] indent was fixed --- files/start_all.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index 1cfee69..e841811 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -110,11 +110,11 @@ elif [ "${PLATFORM_NAME}" == "ios" ]; then ##Hit the WDA status URL to see if it is available RETRY_DELAY=$(( $WDA_WAIT_TIMEOUT / 3 )) timeout "$WDA_WAIT_TIMEOUT" bash -c " - until curl -sf \"http://${WDA_HOST}:${WDA_PORT}/status\"; - do - echo \"http://${WDA_HOST}:${WDA_PORT}/status endpoint not available, one more attempt\"; - sleep ${RETRY_DELAY}; - done" + until curl -sf \"http://${WDA_HOST}:${WDA_PORT}/status\"; + do + echo \"http://${WDA_HOST}:${WDA_PORT}/status endpoint not available, one more attempt\"; + sleep ${RETRY_DELAY}; + done" if [[ $? -eq 0 ]]; then echo "Linked appium container is up and running." else From 8e96ef1d621c35c780da39757c4da13550d4524f Mon Sep 17 00:00:00 2001 From: azarouski Date: Mon, 12 Feb 2024 21:14:53 +0100 Subject: [PATCH 06/15] check stf ports was added --- files/start_all.sh | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index e841811..da410c1 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -1,11 +1,49 @@ #!/bin/bash +check_tcp_connection() { + # -z - Zero-I/O mode [used for scanning] + # -v - Verbose + # -w timeout - Timeout for connects and final net reads + nc -z -v -w 10 $1 +} + +parse_url_for_nc() { + # tcp://demo.zebrunner.farm:7250 -> demo.zebrunner.farm 7250 + echo "$1" | sed -nE 's/^([a-z]*:\/\/)*([a-z\.]+):([0-9]*)/\2 \3/pI' +} + +check_stf_provider_ports() { + push_port=$(parse_url_for_nc $STF_PROVIDER_CONNECT_PUSH) + sub_port=$(parse_url_for_nc $STF_PROVIDER_CONNECT_SUB) + rethink_port=$(parse_url_for_nc $RETHINKDB_PORT_28015_TCP) + + check_tcp_connection "$push_port" + if [[ $? -ne 0 ]]; then + echo "ERROR! STF_PROVIDER_CONNECT_PUSH [$STF_PROVIDER_CONNECT_PUSH] is not accessible! Stopping container." + exit 0 + fi + + check_tcp_connection "$sub_port" + if [[ $? -ne 0 ]]; then + echo "ERROR! STF_PROVIDER_CONNECT_SUB [$STF_PROVIDER_CONNECT_SUB] is not accessible! Stopping container." + exit 0 + fi + + check_tcp_connection "$rethink_port" + if [[ $? -ne 0 ]]; then + echo "ERROR! RETHINKDB_PORT_28015_TCP [$RETHINKDB_PORT_28015_TCP] is not accessible! Stopping container." + exit 0 + fi +} + #154 don't start stf and uploader if related settings are empty if [[ -z $STF_PROVIDER_CONNECT_PUSH ]] || [[ -z $STF_PROVIDER_CONNECT_SUB ]] || [[ -z $STF_PROVIDER_HOST ]]; then - echo "Existing without restart as one of important setting is missed!" + echo "Exiting without restart as one of important setting is missed!" exit 0 +else + check_stf_provider_ports fi #converting to lower case just in case @@ -22,7 +60,7 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then while [[ $(( startTime + $USBMUXD_SOCKET_TIMEOUT )) -gt "$(date +%s)" ]]; do # Check connection - nc -z -v -w 5 "$USBMUXD_SOCKET_HOST" "$USBMUXD_SOCKET_PORT" + check_tcp_connection "$USBMUXD_SOCKET_HOST $USBMUXD_SOCKET_PORT" if [[ $? -eq 0 ]]; then # start socat client and connect to appium usbmuxd socket rm -f /var/run/usbmuxd @@ -148,7 +186,7 @@ fi exit_status=$? echo "Exit status: $exit_status" -#TODO: #85 define exit strategy from container on exiit +#TODO: #85 define exit strategy from container on exit # do always restart until appium container state is not Exited! # for android stop of the appium container crash stf asap so verification of the appium container required only for iOS exit $exit_status From a32120ad82a46c17e26e6211e50b3bcdc912987d Mon Sep 17 00:00:00 2001 From: azarouski Date: Thu, 15 Feb 2024 14:45:18 +0100 Subject: [PATCH 07/15] WDA status connection check, before exit, was added --- files/start_all.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/files/start_all.sh b/files/start_all.sh index 7a83168..dd132c0 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -186,6 +186,13 @@ fi exit_status=$? echo "Exit status: $exit_status" +# #184 https://github.com/zebrunner/mcloud-device/issues/184 +if [ "${PLATFORM_NAME}" == "ios" ]; then + echo "WDA connection status:" + curl --verbose "http://${WDA_HOST}:${WDA_PORT}/status" +fi + + #TODO: #85 define exit strategy from container on exit # do always restart until appium container state is not Exited! # for android stop of the appium container crash stf asap so verification of the appium container required only for iOS From d5fd7b480f16b34e2bf68b5ebe1e622ce99b6d4b Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 20 Feb 2024 16:47:24 +0100 Subject: [PATCH 08/15] - remove go-ios calls - reformat script - modify devicetype detection --- files/start_all.sh | 157 +++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 83 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index dd132c0..6e1e9b2 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -37,25 +37,38 @@ check_stf_provider_ports() { fi } -#154 don't start stf and uploader if related settings are empty +#### Preparation steps +#converting to lower case just in case +PLATFORM_NAME=${PLATFORM_NAME,,} +PUBLIC_IP_PROTOCOL=${PUBLIC_IP_PROTOCOL,,} + +# Note: STF_PROVIDER_... is not a good choice for env variable as STF tries to resolve and provide ... as cmd argument to its service! +if [ -z "${STF_PROVIDER_HOST}" ]; then + # when STF_PROVIDER_HOST is empty + STF_PROVIDER_HOST=${STF_PROVIDER_PUBLIC_IP} +fi +SOCKET_PROTOCOL=ws +if [ "${PUBLIC_IP_PROTOCOL}" == "https" ]; then + SOCKET_PROTOCOL=wss +fi +####/ Preparation steps + +#### Check STF_PROVIDER vars if [[ -z $STF_PROVIDER_CONNECT_PUSH ]] || [[ -z $STF_PROVIDER_CONNECT_SUB ]] || [[ -z $STF_PROVIDER_HOST ]]; then echo "Exiting without restart as one of important setting is missed!" exit 0 else check_stf_provider_ports fi +####/ Check STF_PROVIDER vars -#converting to lower case just in case -PLATFORM_NAME=${PLATFORM_NAME,,} -PUBLIC_IP_PROTOCOL=${PUBLIC_IP_PROTOCOL,,} - +#### Prepare for iOS if [[ "$PLATFORM_NAME" == "ios" ]]; then - # Time variables + #### Connect usbmuxd startTime=$(date +%s) - # Socket creation status socketCreated=0 - # Parse usbmuxd host and port + # Parse usbmuxd host and port ( 'appium:22' -> 'appium 22' ) IFS=: read -r USBMUXD_SOCKET_HOST USBMUXD_SOCKET_PORT <<< "$USBMUXD_SOCKET_ADDRESS" while [[ $(( startTime + $USBMUXD_SOCKET_TIMEOUT )) -gt "$(date +%s)" ]]; do @@ -80,72 +93,9 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then echo "ERROR! usbmuxd socket not created" exit 1 fi + ####/ Connect usbmuxd - res=$(ios list 2>&1) - #echo "res: $res" - # {"err":"dial tcp 172.18.0.66:22: connect: connection refused","level":"fatal","msg":"failed getting device list","time":"2023-08-24T16:28:27Z"} - if [[ "${res}" == *"connection refused"* ]]; then - echo "ERROR! Can't establish connection to usbmuxd socket!" - exit 1 - fi - - if [[ "${res}" == *"no such host"* ]]; then - echo "ERROR! Appium is not ready yet!" - exit 1 - fi - - - deviceInfo=$(ios info --udid=$DEVICE_UDID 2>&1) - echo "device info: " $deviceInfo - - #{"err":"Device '111' not found. Is it attached to the machine?","level":"fatal","msg":"error getting devicelist","time":"2023-08-25T02:11:45-07:00"} - if [[ "${deviceInfo}" == *"not found. Is it attached to the machine"* ]]; then - echo "Device is not available!" - echo "Exiting without restarting..." - # exit with status 0 to stf device container restart - exit 0 - fi - - #{"err":"could not retrieve PairRecord with error: ReadPair failed with errorcode '2', is the device paired?","level":"fatal","msg":"failed getting info","time":"2023-08-24T16:20:00Z"} - if [[ "${deviceInfo}" == *"could not retrieve PairRecord with error"* ]]; then - echo "ERROR! Mounting is broken due to the invalid paring. Please re pair again!" - exit 1 - fi - - deviceClass=$(echo $deviceInfo | jq -r ".DeviceClass | select( . != null )") - export DEVICETYPE='Phone' - if [ "$deviceClass" = "iPad" ]; then - export DEVICETYPE='Tablet' - fi - if [ "$deviceClass" = "AppleTV" ]; then - export DEVICETYPE='tvOS' - fi - -fi - -# Note: STF_PROVIDER_... is not a good choice for env variable as STF tries to resolve and provide ... as cmd argument to its service! -if [ -z "${STF_PROVIDER_HOST}" ]; then - # when STF_PROVIDER_HOST is empty - STF_PROVIDER_HOST=${STF_PROVIDER_PUBLIC_IP} -fi - -SOCKET_PROTOCOL=ws -if [ "${PUBLIC_IP_PROTOCOL}" == "https" ]; then - SOCKET_PROTOCOL=wss -fi - - -if [ "${PLATFORM_NAME}" == "android" ]; then - - # stf provider for Android - stf provider --allow-remote \ - --connect-url-pattern "${STF_PROVIDER_HOST}:<%= publicPort %>" \ - --storage-url ${PUBLIC_IP_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/ \ - --screen-ws-url-pattern "${SOCKET_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/d/${STF_PROVIDER_HOST}/<%= serial %>/<%= publicPort %>/" - -elif [ "${PLATFORM_NAME}" == "ios" ]; then - - ##Hit the WDA status URL to see if it is available + #### Check {WDA}/status endpoint RETRY_DELAY=$(( $WDA_WAIT_TIMEOUT / 3 )) timeout "$WDA_WAIT_TIMEOUT" bash -c " until curl -sf \"http://${WDA_HOST}:${WDA_PORT}/status\"; @@ -160,10 +110,47 @@ elif [ "${PLATFORM_NAME}" == "ios" ]; then exit 1 fi + echo "WDA status:" + curl http://${WDA_HOST}:${WDA_PORT}/status + ####/ Check {WDA}/status endpoint + + #### Detect device type + wdaDeviceInfo=$(curl -sf http://${WDA_HOST}:${WDA_PORT}/wda/device/info) + device=$(echo "$wdaDeviceInfo" | jq -r ".value.model") + + echo "WDA device info:" + echo $wdaDeviceInfo + + case $device in + "iPhone") + export DEVICETYPE='Phone' + ;; + "iPad") + export DEVICETYPE='Tablet' + ;; + "AppleTV") + export DEVICETYPE='tvOS' + ;; + *) + echo "Device type: '$device' is not known. Setting DEVICETYPE to 'Phone'" + export DEVICETYPE='Phone' + esac + + echo "DEVICETYPE: $DEVICETYPE" + ####/ Detect device type +fi +####/ Prepare for iOS -# --screen-ws-url-pattern "${SOCKET_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/d/${STF_PROVIDER_HOST}/<%= serial %>/<%= publicPort %>/" \ - - node /app/lib/cli ios-device --serial ${DEVICE_UDID} \ +#### Connect to STF +if [ "${PLATFORM_NAME}" == "android" ]; then + stf provider \ + --allow-remote \ + --connect-url-pattern "${STF_PROVIDER_HOST}:<%= publicPort %>" \ + --storage-url ${PUBLIC_IP_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/ \ + --screen-ws-url-pattern "${SOCKET_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/d/${STF_PROVIDER_HOST}/<%= serial %>/<%= publicPort %>/" +elif [ "${PLATFORM_NAME}" == "ios" ]; then + node /app/lib/cli ios-device \ + --serial ${DEVICE_UDID} \ --device-name ${STF_PROVIDER_DEVICE_NAME} \ --device-type ${DEVICETYPE} \ --host ${STF_PROVIDER_HOST} \ @@ -173,18 +160,23 @@ elif [ "${PLATFORM_NAME}" == "ios" ]; then --public-ip ${STF_PROVIDER_PUBLIC_IP} \ --group-timeout ${STF_PROVIDER_GROUP_TIMEOUT} \ --storage-url ${PUBLIC_IP_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/ \ - --screen-jpeg-quality ${STF_PROVIDER_SCREEN_JPEG_QUALITY} --screen-ping-interval ${STF_PROVIDER_SCREEN_PING_INTERVAL} \ + --screen-jpeg-quality ${STF_PROVIDER_SCREEN_JPEG_QUALITY} \ + --screen-ping-interval ${STF_PROVIDER_SCREEN_PING_INTERVAL} \ --screen-ws-url-pattern "${SOCKET_PROTOCOL}://${STF_PROVIDER_PUBLIC_IP}:${PUBLIC_IP_PORT}/d/${STF_PROVIDER_HOST}/${DEVICE_UDID}/${STF_PROVIDER_MIN_PORT}/" \ - --boot-complete-timeout ${STF_PROVIDER_BOOT_COMPLETE_TIMEOUT} --mute-master ${STF_PROVIDER_MUTE_MASTER} \ - --connect-push ${STF_PROVIDER_CONNECT_PUSH} --connect-sub ${STF_PROVIDER_CONNECT_SUB} \ - --connect-app-dealer ${STF_PROVIDER_CONNECT_APP_DEALER} --connect-dev-dealer ${STF_PROVIDER_CONNECT_DEV_DEALER} \ + --boot-complete-timeout ${STF_PROVIDER_BOOT_COMPLETE_TIMEOUT} \ + --mute-master ${STF_PROVIDER_MUTE_MASTER} \ + --connect-push ${STF_PROVIDER_CONNECT_PUSH} \ + --connect-sub ${STF_PROVIDER_CONNECT_SUB} \ + --connect-app-dealer ${STF_PROVIDER_CONNECT_APP_DEALER} \ + --connect-dev-dealer ${STF_PROVIDER_CONNECT_DEV_DEALER} \ --connect-url-pattern "${STF_PROVIDER_HOST}:<%= publicPort %>" \ - --wda-host ${WDA_HOST} --wda-port ${WDA_PORT} - + --wda-host ${WDA_HOST} \ + --wda-port ${WDA_PORT} fi exit_status=$? echo "Exit status: $exit_status" +####/ Connect to STF # #184 https://github.com/zebrunner/mcloud-device/issues/184 if [ "${PLATFORM_NAME}" == "ios" ]; then @@ -192,7 +184,6 @@ if [ "${PLATFORM_NAME}" == "ios" ]; then curl --verbose "http://${WDA_HOST}:${WDA_PORT}/status" fi - #TODO: #85 define exit strategy from container on exit # do always restart until appium container state is not Exited! # for android stop of the appium container crash stf asap so verification of the appium container required only for iOS From 70df62706fd473d60ecfbc74d4c01e440486791d Mon Sep 17 00:00:00 2001 From: azarouski Date: Tue, 20 Feb 2024 20:30:07 +0100 Subject: [PATCH 09/15] some formatting --- files/start_all.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index 6e1e9b2..3d45f16 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -52,7 +52,6 @@ SOCKET_PROTOCOL=ws if [ "${PUBLIC_IP_PROTOCOL}" == "https" ]; then SOCKET_PROTOCOL=wss fi -####/ Preparation steps #### Check STF_PROVIDER vars if [[ -z $STF_PROVIDER_CONNECT_PUSH ]] || [[ -z $STF_PROVIDER_CONNECT_SUB ]] || [[ -z $STF_PROVIDER_HOST ]]; then @@ -61,7 +60,6 @@ if [[ -z $STF_PROVIDER_CONNECT_PUSH ]] || [[ -z $STF_PROVIDER_CONNECT_SUB ]] || else check_stf_provider_ports fi -####/ Check STF_PROVIDER vars #### Prepare for iOS if [[ "$PLATFORM_NAME" == "ios" ]]; then @@ -93,7 +91,6 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then echo "ERROR! usbmuxd socket not created" exit 1 fi - ####/ Connect usbmuxd #### Check {WDA}/status endpoint RETRY_DELAY=$(( $WDA_WAIT_TIMEOUT / 3 )) @@ -112,7 +109,6 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then echo "WDA status:" curl http://${WDA_HOST}:${WDA_PORT}/status - ####/ Check {WDA}/status endpoint #### Detect device type wdaDeviceInfo=$(curl -sf http://${WDA_HOST}:${WDA_PORT}/wda/device/info) @@ -137,9 +133,7 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then esac echo "DEVICETYPE: $DEVICETYPE" - ####/ Detect device type fi -####/ Prepare for iOS #### Connect to STF if [ "${PLATFORM_NAME}" == "android" ]; then @@ -176,7 +170,6 @@ fi exit_status=$? echo "Exit status: $exit_status" -####/ Connect to STF # #184 https://github.com/zebrunner/mcloud-device/issues/184 if [ "${PLATFORM_NAME}" == "ios" ]; then From 0ee49c361376c205951027e77341b35312275c5e Mon Sep 17 00:00:00 2001 From: azarouski Date: Thu, 22 Feb 2024 20:10:10 +0100 Subject: [PATCH 10/15] debug mode was added --- Dockerfile | 5 +++++ files/debug.sh | 24 ++++++++++++++++++++++++ files/healthcheck | 6 ++++++ files/start_all.sh | 7 ++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 files/debug.sh diff --git a/Dockerfile b/Dockerfile index 0e112b9..15edb47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,9 +54,14 @@ ENV USBMUXD_SOCKET_ADDRESS=appium:22 ENV USBMUXD_SOCKET_TIMEOUT=60 ENV USBMUXD_SOCKET_PERIOD=5 +# Additional vars +ENV DEBUG=false +ENV VERBOSE=false + # Need root user to clear existing /var/run/usbmuxd socket if any USER root +COPY files/debug.sh /opt/ COPY files/healthcheck /usr/local/bin/ COPY files/start_all.sh /opt/ CMD bash /opt/start_all.sh diff --git a/files/debug.sh b/files/debug.sh new file mode 100755 index 0000000..ccb17ad --- /dev/null +++ b/files/debug.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Debug mode activator +# You can use args and env vars for execution control +# -d - turn on debug mode [ $DEBUG=true ] +# -v - verbose output [ $VERBOSE=true ] + +if [[ "${DEBUG}" == 'true' || "$*" =~ "-d" ]]; then + echo "#######################################################" + echo "# #" + echo "# DEBUG mode is on! #" + echo "# #" + echo "#######################################################" + trap "echo 'Exit attempt intercepted. Sleep for 24h activated!'; sleep 86400;" EXIT +fi + +if [[ "${VERBOSE}" == 'true' || "$*" =~ "-v" ]]; then + echo "#######################################################" + echo "# #" + echo "# VERBOSE mode is on! #" + echo "# #" + echo "#######################################################" + set -x +fi diff --git a/files/healthcheck b/files/healthcheck index fc50089..eddcc17 100755 --- a/files/healthcheck +++ b/files/healthcheck @@ -1,5 +1,11 @@ #!/bin/bash +# Debug mode activator +# You can use args and env vars for execution control +# -d - turn on debug mode [ $DEBUG=true ] +# -v - verbose output [ $VERBOSE=true ] +. /opt/debug.sh + # STF device container is considered healthy if stf provider/cli and wda for iOS up&running # 0 - healthy # 1 - unhealthy diff --git a/files/start_all.sh b/files/start_all.sh index dd132c0..6135b18 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Debug mode activator +# You can use args and env vars for execution control +# -d - turn on debug mode [ $DEBUG=true ] +# -v - verbose output [ $VERBOSE=true ] +. /opt/debug.sh check_tcp_connection() { # -z - Zero-I/O mode [used for scanning] @@ -43,7 +48,7 @@ if [[ -z $STF_PROVIDER_CONNECT_PUSH ]] || [[ -z $STF_PROVIDER_CONNECT_SUB ]] || echo "Exiting without restart as one of important setting is missed!" exit 0 else - check_stf_provider_ports + check_stf_provider_ports fi #converting to lower case just in case From 7b48b177c9ebe345ac4324292f4c6288dfc0e99e Mon Sep 17 00:00:00 2001 From: azarouski Date: Fri, 23 Feb 2024 14:34:49 +0100 Subject: [PATCH 11/15] debug mode was edited --- Dockerfile | 3 ++- files/debug.sh | 20 +++++++++++++------- files/healthcheck | 6 ------ files/start_all.sh | 5 +---- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15edb47..0d0261e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,8 +54,9 @@ ENV USBMUXD_SOCKET_ADDRESS=appium:22 ENV USBMUXD_SOCKET_TIMEOUT=60 ENV USBMUXD_SOCKET_PERIOD=5 -# Additional vars +# Debug mode vars ENV DEBUG=false +ENV DEBUG_TIMEOUT=3600 ENV VERBOSE=false # Need root user to clear existing /var/run/usbmuxd socket if any diff --git a/files/debug.sh b/files/debug.sh index ccb17ad..d03814a 100755 --- a/files/debug.sh +++ b/files/debug.sh @@ -1,20 +1,26 @@ #!/bin/bash -# Debug mode activator -# You can use args and env vars for execution control -# -d - turn on debug mode [ $DEBUG=true ] -# -v - verbose output [ $VERBOSE=true ] +#### Debug mode activator +# To use this mode you need to call this file from your code e.g. +# '. /some/path/debug.sh' +# You can use following env vars to control debug mode: +# DEBUG=[true/false] - debug mode (default: false) +# DEBUG_TIMEOUT - delay before exit (default: 3600) +# VERBOSE=[true/false] - verbose mode (default: false) -if [[ "${DEBUG}" == 'true' || "$*" =~ "-d" ]]; then +# Set default value +${DEBUG_TIMEOUT:=3600} + +if [[ "${DEBUG}" == "true" ]]; then echo "#######################################################" echo "# #" echo "# DEBUG mode is on! #" echo "# #" echo "#######################################################" - trap "echo 'Exit attempt intercepted. Sleep for 24h activated!'; sleep 86400;" EXIT + trap 'echo "Exit attempt intercepted. Sleep for ${DEBUG_TIMEOUT} seconds activated!"; sleep ${DEBUG_TIMEOUT};' EXIT fi -if [[ "${VERBOSE}" == 'true' || "$*" =~ "-v" ]]; then +if [[ "${VERBOSE}" == "true" ]]; then echo "#######################################################" echo "# #" echo "# VERBOSE mode is on! #" diff --git a/files/healthcheck b/files/healthcheck index eddcc17..fc50089 100755 --- a/files/healthcheck +++ b/files/healthcheck @@ -1,11 +1,5 @@ #!/bin/bash -# Debug mode activator -# You can use args and env vars for execution control -# -d - turn on debug mode [ $DEBUG=true ] -# -v - verbose output [ $VERBOSE=true ] -. /opt/debug.sh - # STF device container is considered healthy if stf provider/cli and wda for iOS up&running # 0 - healthy # 1 - unhealthy diff --git a/files/start_all.sh b/files/start_all.sh index 6135b18..8f3b78c 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -1,9 +1,6 @@ #!/bin/bash -# Debug mode activator -# You can use args and env vars for execution control -# -d - turn on debug mode [ $DEBUG=true ] -# -v - verbose output [ $VERBOSE=true ] + . /opt/debug.sh check_tcp_connection() { From e67926c92e1a877c6536a708844b06473da1a08f Mon Sep 17 00:00:00 2001 From: azarouski Date: Mon, 26 Feb 2024 14:45:44 +0100 Subject: [PATCH 12/15] device type detection was removed --- files/start_all.sh | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/files/start_all.sh b/files/start_all.sh index 97619d5..59f816b 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -111,30 +111,6 @@ if [[ "$PLATFORM_NAME" == "ios" ]]; then echo "WDA status:" curl http://${WDA_HOST}:${WDA_PORT}/status - - #### Detect device type - wdaDeviceInfo=$(curl -sf http://${WDA_HOST}:${WDA_PORT}/wda/device/info) - device=$(echo "$wdaDeviceInfo" | jq -r ".value.model") - - echo "WDA device info:" - echo $wdaDeviceInfo - - case $device in - "iPhone") - export DEVICETYPE='Phone' - ;; - "iPad") - export DEVICETYPE='Tablet' - ;; - "AppleTV") - export DEVICETYPE='tvOS' - ;; - *) - echo "Device type: '$device' is not known. Setting DEVICETYPE to 'Phone'" - export DEVICETYPE='Phone' - esac - - echo "DEVICETYPE: $DEVICETYPE" fi #### Connect to STF @@ -148,7 +124,6 @@ elif [ "${PLATFORM_NAME}" == "ios" ]; then node /app/lib/cli ios-device \ --serial ${DEVICE_UDID} \ --device-name ${STF_PROVIDER_DEVICE_NAME} \ - --device-type ${DEVICETYPE} \ --host ${STF_PROVIDER_HOST} \ --screen-port ${STF_PROVIDER_MIN_PORT} \ --connect-port ${MJPEG_PORT} \ From 732606ef6e5b4cab0b09b69fad47f28234266b02 Mon Sep 17 00:00:00 2001 From: azarouski Date: Fri, 1 Mar 2024 12:01:48 +0000 Subject: [PATCH 13/15] default debug timeout invoke fix --- files/debug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/debug.sh b/files/debug.sh index d03814a..1238728 100755 --- a/files/debug.sh +++ b/files/debug.sh @@ -9,7 +9,7 @@ # VERBOSE=[true/false] - verbose mode (default: false) # Set default value -${DEBUG_TIMEOUT:=3600} +: ${DEBUG_TIMEOUT:=3600} if [[ "${DEBUG}" == "true" ]]; then echo "#######################################################" From 325f3ce99253512002bc8523fc33ec0cb65fd790 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Thu, 7 Mar 2024 00:13:58 +0300 Subject: [PATCH 14/15] #190: bump up to stf:2.6.4 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0d0261e..3bd781f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM public.ecr.aws/zebrunner/stf:2.6.3 +FROM public.ecr.aws/zebrunner/stf:2.6.4 # https://github.com/zebrunner/android-device/issues/70 # gray screen on android after 48 hours without restart From b4bbbfc40875d11892b31511194a7a94173a464d Mon Sep 17 00:00:00 2001 From: vdelendik Date: Thu, 7 Mar 2024 01:38:22 +0300 Subject: [PATCH 15/15] #192: add spport of ip for tcp host:port parser and verification --- files/start_all.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/files/start_all.sh b/files/start_all.sh index 8f3b78c..55f504e 100755 --- a/files/start_all.sh +++ b/files/start_all.sh @@ -12,7 +12,15 @@ check_tcp_connection() { parse_url_for_nc() { # tcp://demo.zebrunner.farm:7250 -> demo.zebrunner.farm 7250 - echo "$1" | sed -nE 's/^([a-z]*:\/\/)*([a-z\.]+):([0-9]*)/\2 \3/pI' + # tcp://192.168.88.88:7250 -> 192.168.88.88 7250 + + #192 tcp connection verification doesn't support usage of ip addresses + host=`echo $1 | cut -d ':' -f 2` + # remove forward slashes + host="${host//\//}" + + port=`echo $1 | cut -d ':' -f 3` + echo $host $port } check_stf_provider_ports() {