Skip to content

Commit

Permalink
Merge pull request #313 from zebrunner/develop
Browse files Browse the repository at this point in the history
2.7
  • Loading branch information
vdelendik authored May 27, 2024
2 parents 2b2d0eb + 88f7f97 commit 1d3c6e8
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 163 deletions.
15 changes: 10 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
---
DEVICE_IMAGE: public.ecr.aws/zebrunner/mcloud-device
DEVICE_VERSION: 2.6.5
DEVICE_VERSION: 2.7

APPIUM_IMAGE: public.ecr.aws/zebrunner/appium
APPIUM_VERSION: 2.0.15
APPIUM_VERSION: 2.1

UPLOADER_IMAGE: public.ecr.aws/zebrunner/uploader
UPLOADER_VERSION: 3.4
UPLOADER_VERSION: 3.6

MITM_IMAGE: public.ecr.aws/zebrunner/mitmproxy
MITM_VERSION: 2.0

IOS_CONNECTOR_IMAGE: public.ecr.aws/zebrunner/mcloud-ios-connector
IOS_CONNECTOR_VERSION: 1.0

ANDROID_CONNECTOR_IMAGE: public.ecr.aws/zebrunner/mcloud-android-connector
ANDROID_CONNECTOR_VERSION: 1.0

# Put true to disable app size check using local appium storage
APPIUM_APP_SIZE_DISABLE: false

# Optomized app verifications for AppCenter and AWS S3 storages
# Optimized app verifications for AppCenter and AWS S3 storages
APPIUM_APP_FETCH_RETRIES: 2
APPIUM_MAX_LOCK_FILE_LIFETIME: 180
APPIUM_APP_WAITING_TIMEOUT: 90

226 changes: 140 additions & 86 deletions roles/devices/templates/zebrunner-farm
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,77 @@ function create_containers () {
{{ MITM_IMAGE }}:{{ MITM_VERSION }} || echo 'already created'
fi

#TODO: parametrized relaxed security, make false by default!
docker run -itd --name device-${device_name}-${udid}-appium -m 1g --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
docker run -itd --name device-${device_name}-${udid}-connector --net=${net} \
--restart on-failure $DEVICE_ARG \
-e DEVICE_BUS=$usb_bus \
-e DEVICE_BUS=$usb_bus \
-v mcloud-key-volume:/root/.android \
-v appium-storage-volume:/opt/appium-storage \
-v device-${device_name}-${udid}:/tmp/log \
-e TASK_LOG=/tmp/log/appium.log \
-e PLATFORM_NAME=$platform_name \
-e ANDROID_DEVICE=$ANDROID_DEVICE \
-e DEVICE_UDID="$STF_DEVICE_UDID" \
{{ ANDROID_CONNECTOR_IMAGE }}:{{ ANDROID_CONNECTOR_VERSION }} || echo 'already created'

docker run -d --name device-${device_name}-${udid} --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
--link device-${device_name}-${udid}-connector:connector \
-e STF_PROVIDER_ADB_HOST=connector \
-e STF_PROVIDER_ADB_PORT=5037 \
--health-start-period 60s \
--restart on-failure \
-e PLATFORM_NAME=$platform_name \
-e ANDROID_DEVICE=$ANDROID_DEVICE \
-e RETAIN_TASK=true \
-e CONNECT_TO_GRID=true \
-e CUSTOM_NODE_CONFIG=true \
-e STF_PROVIDER_DEVICE_NAME="${device_name}" \
-e DEVICE_UDID="$STF_DEVICE_UDID" \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}" \
-e STF_PROVIDER_MIN_PORT=$stf_min_port \
-e STF_PROVIDER_MAX_PORT=$stf_max_port \
-p $stf_min_port-$stf_max_port:$stf_min_port-$stf_max_port \
-e STF_PROVIDER_PUBLIC_IP={{ PUBLIC_IP }} \
-e PUBLIC_IP_PORT={{ PUBLIC_IP_PORT }} \
-e PUBLIC_IP_PROTOCOL={{ PUBLIC_IP_PROTOCOL }} \
-e STF_PROVIDER_CONNECT_SUB={{ STF_PROVIDER_CONNECT_SUB }} \
-e STF_PROVIDER_CONNECT_PUSH={{ STF_PROVIDER_CONNECT_PUSH }} \
-e RETHINKDB_PORT_28015_TCP={{ STF_RETHINKDB }} \
{{ DEVICE_IMAGE }}:{{DEVICE_VERSION }} || echo 'already created'

# Adb config env vars
# -e ADB_SERVER_SOCKET=tcp:connector:5037 \
# or
# -e ANDROID_ADB_SERVER_ADDRESS=connector \
# -e ANDROID_ADB_SERVER_PORT=5037 \

#TODO: parametrized relaxed security, make false by default!
docker run -itd --name device-${device_name}-${udid}-appium -m 1g --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
--restart on-failure \
--link device-${device_name}-${udid}:device \
--link device-${device_name}-${udid}-connector:connector \
-v appium-storage-volume:/opt/appium-storage \
-v device-${device_name}-${udid}:/tmp/log \
-e TASK_LOG=/tmp/log/appium.log \
-e PLATFORM_NAME=$platform_name \
-e ANDROID_DEVICE=$ANDROID_DEVICE \
-e RETAIN_TASK=true \
-e CONNECT_TO_GRID=true \
-e CUSTOM_NODE_CONFIG=true \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e APPIUM_APP_SIZE_DISABLE={{ APPIUM_APP_SIZE_DISABLE }} \
-e APPIUM_APP_FETCH_RETRIES={{ APPIUM_APP_FETCH_RETRIES }} \
-e APPIUM_MAX_LOCK_FILE_LIFETIME={{ APPIUM_MAX_LOCK_FILE_LIFETIME }} \
-e APPIUM_APP_WAITING_TIMEOUT={{ APPIUM_APP_WAITING_TIMEOUT }} \
-e SELENIUM_HOST={{ SELENIUM_HUB_HOST }} -e SELENIUM_PORT={{ SELENIUM_HUB_PORT }} \
-e SELENIUM_HOST={{ SELENIUM_HUB_HOST }} \
-e SELENIUM_PORT={{ SELENIUM_HUB_PORT }} \
-e DEFAULT_CAPABILITIES=true \
-e DEVICE_NAME="${device_name}" -e DEVICE_UDID="$STF_DEVICE_UDID" \
-e ADB_PORT=$device_adb_port \
-e PROXY_PORT=$proxy_port \
-e SERVER_PROXY_PORT=$server_proxy_port \
-e APPIUM_PORT=$appium_port \
-p $appium_port:$appium_port \
-e DEVICE_NAME="${device_name}" \
-e DEVICE_UDID="$STF_DEVICE_UDID" \
-e ADB_PORT=$device_adb_port \
-e PROXY_PORT=$proxy_port \
-e SERVER_PROXY_PORT=$server_proxy_port \
-e APPIUM_PORT=$appium_port \
-p $appium_port:$appium_port \
-e RELAXED_SECURITY=true \
-e ADB_SERVER_SOCKET=tcp:connector:5037 \
-e REMOTE_ADB_HOST=connector \
-e STF_API_URL={{ STF_API_URL }} \
-e STF_AUTH_TOKEN={{ STF_AUTH_TOKEN }} \
{{ APPIUM_IMAGE }}:{{ APPIUM_VERSION }} || echo 'already created'

docker run -d --name device-${device_name}-${udid}-uploader --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
Expand All @@ -155,29 +199,9 @@ function create_containers () {
-e AWS_DEFAULT_REGION={{ S3_REGION }} \
{{ UPLOADER_IMAGE }}:{{ UPLOADER_VERSION }} || echo 'already created'


docker run -d --name device-${device_name}-${udid} --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
--link device-${device_name}-${udid}-appium:appium \
-e STF_PROVIDER_ADB_HOST=appium \
--health-start-period 60s \
--restart on-failure \
-e PLATFORM_NAME=$platform_name \
-e STF_PROVIDER_DEVICE_NAME="${device_name}" -e DEVICE_UDID="$STF_DEVICE_UDID" \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}" \
-e STF_PROVIDER_MIN_PORT=$stf_min_port \
-e STF_PROVIDER_MAX_PORT=$stf_max_port \
-p $stf_min_port-$stf_max_port:$stf_min_port-$stf_max_port \
-e STF_PROVIDER_PUBLIC_IP={{ PUBLIC_IP }} \
-e PUBLIC_IP_PORT={{ PUBLIC_IP_PORT }} \
-e PUBLIC_IP_PROTOCOL={{ PUBLIC_IP_PROTOCOL }} \
-e STF_PROVIDER_CONNECT_SUB={{ STF_PROVIDER_CONNECT_SUB }} \
-e STF_PROVIDER_CONNECT_PUSH={{ STF_PROVIDER_CONNECT_PUSH }} \
-e RETHINKDB_PORT_28015_TCP={{ STF_RETHINKDB }} \
{{ DEVICE_IMAGE }}:{{DEVICE_VERSION }} || echo 'already created'
elif [ $platform_name == "ios" ]; then

#TODO: comment echoing wda related detailes before release
#TODO: comment echoing wda related detailes before release
local wdaIpaPath={{ WDA_FILE }}
local deviceWdaIpaPath=`cat ${devices} | grep "$udid" | cut -d '|' -f 10`
if [ ! -z $deviceWdaIpaPath ] && [ ! "$deviceWdaIpaPath" == "/dev/null" ]; then
Expand Down Expand Up @@ -209,30 +233,65 @@ function create_containers () {
{{ MITM_IMAGE }}:{{ MITM_VERSION }} || echo 'already created'
fi

# candidates for removal: ADB_PORT, STF_PROVIDER_MAX_PORT
docker run -itd --name device-${device_name}-${udid}-appium -m 1g --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
docker run -itd --name device-${device_name}-${udid}-connector --net=${net} \
--restart on-failure $DEVICE_ARG \
-e DEVICE_BUS=$usb_bus \
-v appium-storage-volume:/opt/appium-storage \
-v device-${device_name}-${udid}:/tmp/log \
-v device-${device_name}-${udid}-lockdown:/var/lib/lockdown \
-e TASK_LOG=/tmp/log/appium.log \
-e APPIUM_CLI="--session-override" \
-e WDA_BUNDLEID=$wdaBundleId \
-e WDA_FILE=/tmp/zebrunner/WebDriverAgent.ipa \
-v ${wdaIpaPath}:/tmp/zebrunner/WebDriverAgent.ipa \
-e WDA_FILE=/tmp/zebrunner/WebDriverAgent.ipa \
-v ${wdaIpaPath}:/tmp/zebrunner/WebDriverAgent.ipa \
-v device-${device_name}-${udid}-lockdown:/var/lib/lockdown \
-v device-${device_name}-${udid}:/tmp/log \
-e DEVICE_UDID="$STF_DEVICE_UDID" \
{{ IOS_CONNECTOR_IMAGE }}:{{ IOS_CONNECTOR_VERSION }} || echo 'already created'

# Linking with apppium required to share usbmuxd via socat
docker run -d --name device-${device_name}-${udid} --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
--restart on-failure \
--link device-${device_name}-${udid}-connector:connector \
-e WDA_HOST=connector \
-e WDA_WAIT_TIMEOUT=60 \
-e PLATFORM_NAME=$platform_name \
-e STF_PROVIDER_DEVICE_NAME="${device_name}" \
-e DEVICE_UDID="${udid}" \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}" \
-e STF_PROVIDER_MIN_PORT=$stf_min_port \
-e STF_PROVIDER_MAX_PORT=$stf_max_port \
-p $stf_min_port-$stf_max_port:$stf_min_port-$stf_max_port \
-e STF_PROVIDER_PUBLIC_IP={{ PUBLIC_IP }} \
-e PUBLIC_IP_PORT={{ PUBLIC_IP_PORT }} \
-e PUBLIC_IP_PROTOCOL={{ PUBLIC_IP_PROTOCOL }} \
-e STF_PROVIDER_CONNECT_SUB={{ STF_PROVIDER_CONNECT_SUB }} \
-e STF_PROVIDER_CONNECT_PUSH={{ STF_PROVIDER_CONNECT_PUSH }} \
-e STF_PROVIDER_CONNECT_APP_DEALER={{ STF_PROVIDER_CONNECT_APP_DEALER }} \
-e STF_PROVIDER_CONNECT_DEV_DEALER={{ STF_PROVIDER_CONNECT_DEV_DEALER }} \
-e RETHINKDB_PORT_28015_TCP={{ STF_RETHINKDB }} \
{{ DEVICE_IMAGE }}:{{DEVICE_VERSION }} || echo 'already created'

# candidates for removal: ADB_PORT, STF_PROVIDER_MAX_PORT
docker run -itd --name device-${device_name}-${udid}-appium -m 1g --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
--restart on-failure $DEVICE_ARG \
--link device-${device_name}-${udid}:device \
--link device-${device_name}-${udid}-connector:connector \
-e WDA_HOST=connector \
-v appium-storage-volume:/opt/appium-storage \
-v device-${device_name}-${udid}:/tmp/log \
-e TASK_LOG=/tmp/log/appium.log \
-e APPIUM_CLI="--session-override" \
-e PLATFORM_NAME=$platform_name \
-e RETAIN_TASK=true \
-e CONNECT_TO_GRID=true \
-e CUSTOM_NODE_CONFIG=true \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e APPIUM_APP_SIZE_DISABLE={{ APPIUM_APP_SIZE_DISABLE }} \
-e APPIUM_APP_FETCH_RETRIES={{ APPIUM_APP_FETCH_RETRIES }} \
-e APPIUM_MAX_LOCK_FILE_LIFETIME={{ APPIUM_MAX_LOCK_FILE_LIFETIME }} \
-e APPIUM_APP_WAITING_TIMEOUT={{ APPIUM_APP_WAITING_TIMEOUT }} \
-e SELENIUM_HOST={{ SELENIUM_HUB_HOST }} -e SELENIUM_PORT={{ SELENIUM_HUB_PORT }} \
-e DEFAULT_CAPABILITIES=true \
-e DEVICE_NAME="${device_name}" -e DEVICE_UDID="${udid}" \
-e SELENIUM_HOST={{ SELENIUM_HUB_HOST }} \
-e SELENIUM_PORT={{ SELENIUM_HUB_PORT }} \
-e DEFAULT_CAPABILITIES=true \
-e DEVICE_NAME="${device_name}" \
-e DEVICE_UDID="${udid}" \
-e ADB_PORT=$device_adb_port \
-e PROXY_PORT=$proxy_port \
-e SERVER_PROXY_PORT=$server_proxy_port \
Expand All @@ -245,34 +304,12 @@ function create_containers () {
--restart on-failure \
-v device-${device_name}-${udid}:/tmp/log \
-e ENDPOINT_URL={{ S3_ENDPOINT }} \
-e S3_KEY_PATTERN=${S3_KEY_PATTERN} \
-e AWS_ACCESS_KEY_ID={{ S3_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY={{ S3_SECRET }} \
-e AWS_DEFAULT_REGION={{ S3_REGION }} \
-e S3_KEY_PATTERN=${S3_KEY_PATTERN} \
-e AWS_ACCESS_KEY_ID={{ S3_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY={{ S3_SECRET }} \
-e AWS_DEFAULT_REGION={{ S3_REGION }} \
{{ UPLOADER_IMAGE }}:{{ UPLOADER_VERSION }} || echo 'already created'

# Linking with apppium required to share usbmuxd via socat
docker run -d --name device-${device_name}-${udid} --log-opt max-size=1024m --log-opt max-file=2 --net=${net} \
--restart on-failure \
--link device-${device_name}-${udid}-appium:appium \
-e WDA_HOST=appium \
-e WDA_WAIT_TIMEOUT=60 \
-e PLATFORM_NAME=$platform_name \
-e STF_PROVIDER_DEVICE_NAME="${device_name}" -e DEVICE_UDID="${udid}" \
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}" \
-e STF_PROVIDER_MIN_PORT=$stf_min_port \
-e STF_PROVIDER_MAX_PORT=$stf_max_port \
-p $stf_min_port-$stf_max_port:$stf_min_port-$stf_max_port \
-e STF_PROVIDER_PUBLIC_IP={{ PUBLIC_IP }} \
-e PUBLIC_IP_PORT={{ PUBLIC_IP_PORT }} \
-e PUBLIC_IP_PROTOCOL={{ PUBLIC_IP_PROTOCOL }} \
-e STF_PROVIDER_CONNECT_SUB={{ STF_PROVIDER_CONNECT_SUB }} \
-e STF_PROVIDER_CONNECT_PUSH={{ STF_PROVIDER_CONNECT_PUSH }} \
-e STF_PROVIDER_CONNECT_APP_DEALER={{ STF_PROVIDER_CONNECT_APP_DEALER }} \
-e STF_PROVIDER_CONNECT_DEV_DEALER={{ STF_PROVIDER_CONNECT_DEV_DEALER }} \
-e RETHINKDB_PORT_28015_TCP={{ STF_RETHINKDB }} \
{{ DEVICE_IMAGE }}:{{DEVICE_VERSION }} || echo 'already created'
else
echo "ERROR! Unsupported platform: ${platform_name}"
fi
Expand Down Expand Up @@ -321,11 +358,13 @@ function stop_containers() {
local container=device-$device-$udid
echo
echo "$container stopping..."
#TODO: retest below assumption
# appium should be stopped first to disconnect in STF asap
docker stop $container
docker stop $container-mitm
docker stop $container-appium
docker stop $container
docker stop $container-uploader
docker stop $container-connector
}

function down() {
Expand Down Expand Up @@ -366,26 +405,32 @@ function remove_containers() {
local container=device-$device-$udid
#echo "$container removing..."
# remove container(s) only if exists
docker ps -a | grep -v appium | grep $container > /dev/null
if [ $? -eq 0 ]; then
docker rm -f $container
fi

docker ps -a | grep mitm | grep $container > /dev/null
if [ $? -eq 0 ]; then
docker rm -f $container-mitm
fi

docker ps -a | grep appium | grep $container > /dev/null
if [ $? -eq 0 ]; then
# remove appium first to disconnect device in stf asap
docker rm -f $container-appium
fi

docker ps -a | grep -v appium | grep $container > /dev/null
docker ps -a | grep uploader | grep $container > /dev/null
if [ $? -eq 0 ]; then
docker rm -f $container
docker rm -f $container-uploader
fi

docker ps -a | grep uploader | grep $container > /dev/null
docker ps -a | grep connector | grep $container > /dev/null
if [ $? -eq 0 ]; then
docker rm -f $container-uploader
docker rm -f $container-connector
fi

docker ps -a | grep mitm | grep $container > /dev/null
if [ $? -eq 0 ]; then
docker rm -f $container-mitm
fi

docker volume ls | grep $container > /dev/null
if [ $? -eq 0 ]; then
Expand Down Expand Up @@ -421,8 +466,15 @@ function verify_containers() {
if [ $? -eq 0 ]; then
appiumState=`docker inspect --format='{{ '{{' }}json .State.Health.Status{{ '}}' }}' $container-appium`
fi

local connectorState="UNKNOWN"
docker ps -a | grep connector | grep $container > /dev/null
if [ $? -eq 0 ]; then
connectorState=`docker inspect --format='{{ '{{' }}json .State.Health.Status{{ '}}' }}' $container-connector`
fi

echo $container
echo "Appium: $appiumState; STF: $stfState"
echo "Connector: $connectorState; Appium: $appiumState; STF: $stfState"
fi
echo
}
Expand Down Expand Up @@ -472,8 +524,10 @@ function start_containers() {
echo
echo "$container starting..."
docker start $container
docker start $container-mitm
docker start $container-appium
docker start $container-uploader
docker start $container-connector
}

function status() {
Expand Down
4 changes: 4 additions & 0 deletions roles/devices/vars/main.yml.original
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ STF_PROVIDER_HOST: linux-agent.zebrunner.farm
# [OPTIONAL] provider/location name for devices. Use short city name like NYC
STF_PROVIDER_NAME: mcloud-linux

# [OPTIONAL] STF integration settings to move devices into Unhealthy state
STF_API_URL:
STF_AUTH_TOKEN:

# [OPTIONAL] S3 compatible storage for video recordings.
S3_BUCKET:
S3_TENANT:
Expand Down
6 changes: 6 additions & 0 deletions roles/download/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
- name: Pull an Zebrunner Mitm image
shell: docker pull "{{ MITM_IMAGE }}:{{ MITM_VERSION }}"

- name: Pull an Zebrunner Connector image
shell: docker pull "{{ IOS_CONNECTOR_IMAGE }}:{{ IOS_CONNECTOR_VERSION }}"

- name: Pull an Zebrunner Connector image
shell: docker pull "{{ ANDROID_CONNECTOR_IMAGE }}:{{ ANDROID_CONNECTOR_VERSION }}"

- name: Create infra network if absent
shell: docker network inspect "{{ STF_DOCKER_NETWORK }}" >/dev/null 2>&1 || docker network create "{{ STF_DOCKER_NETWORK }}"
Loading

0 comments on commit 1d3c6e8

Please sign in to comment.