Docker 部署 STF / Connect to Android
一、Docker-compose 部署
创建配置文件docker-compose.yaml
注意替换掉 YOUR_IP
# yaml 配置实例
version: "3"
services:
rethinkdb:
container_name: rethinkdb
image: rethinkdb:2.3
restart: unless-stopped
volumes:
- "rethinkdb-data:/data"
networks:
- my-stf
command: "rethinkdb --bind all --cache-size 2048"
adb:
container_name: adb
image: devicefarmer/adb:latest
restart: unless-stopped
volumes:
- "/dev/bus/usb:/dev/bus/usb"
networks:
- my-stf
privileged: true
stf:
container_name: stf
image: devicefarmer/stf
networks:
- my-stf
ports:
- "7100:7100"
- "7110:7110"
- "7400-7500:7400-7500"
environment:
- TZ='America/Los_Angeles'
- RETHINKDB_PORT_28015_TCP=tcp://rethinkdb:28015
- STF_ADMIN_EMAIL=<YOUR_EMAIL>
- STF_ADMIN_NAME=<YOUR_NAME>
restart: unless-stopped
command: stf local --adb-host adb --public-ip 10.112.95.227 --provider-min-port 7400 --provider-max-port 7500
volumes:
rethinkdb-data: {}
networks:
my-stf:
在当前目录执行docker-compose up -d
二、Docker 部署
1.安装docker
apt install docker docker.io
用户加入
Docker用户组
后执行 Docker 命令 无需 添加sudo
即可执行
- 创建docker用户组
sudo groupadd docker
- 应用用户加入docker用户组
sudo usermod -aG docker ${USER}
- 重启docker服务
sudo systemctl restart docker
- 切换或者退出当前账户再从新登入
su root 切换到root用户 su ${USER} 再切换到原来的应用用户以上配置才生效
2. docker pull images(STF_Docker镜像)
# Docker Pull Images
# STF镜像 / ambassador镜像 (老版不再维护) / Devicefarmer/stf(新版)
sudo docker pull openstf/stf:latest
sudo docker pull openstf/ambassador:latest
sudo docker pull devicefarmer/stf
# Android adb镜像
sudo docker pull sorccu/adb:latest
# rethinkdb镜像
sudo docker pull rethinkdb:latest
# nginx代理镜像
sudo docker pull nginx:latest
3. 创建容器实例
# 1.启动 rethinkdb数据库
sudo docker run -d --name rethinkdb -v /srv/rethinkdb:/data --net host rethinkdb rethinkdb --bind all --cache-size 8192 --http-port 8090
# 2.启动adb service
sudo docker run -d --name adbd --privileged -v /dev/bus/usb:/dev/bus/usb --net host sorccu/adb:latest
# 3.启动stf
# ${Server_IP}参数为本机的局域网ip地址(服务器ip)
# ImagesName(openstf/stf、openstf/ambassador、devicefarmer/stf)
sudo docker run -d --name stf --net host ${ImagesName} stf local --public-ip ${Server_IP} --allow-remote
访问
http://Server_IP:7100
Login:输入任意邮箱地址
4. 容器可视化
# 拉取 image sudo docker pull portainer/portainer # 启动 portainerUI sudo docker run -d --name portainerUI -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
访问
http://${Server_IP}:9000
二、Local链接Server(分布式多节点部署)
STF分布式有2种方案,方案如下:
1. Local端未安装 STF(多节点_子节点未安装服务)
主节点部署STF服务并允许远程访问API,子节点只需部署ADB,保证ADB 5037端口对外暴露即可。这种方案的优点是部署简单,而且子节点无需部署STF服务。缺点就是子节点新增机器需要在主节点重新运行STF命令以识别子节点上新增的机器
1.1 Local端 对外暴露 adb_Server端口
# Windowds # adb -v ==>> 1.0.32, adb nodaemon server -a -P 5037 # adb -v <<== 1.0.32, adb -a -P 5037 fork-server server # Linux adb -a -P 5037 fork-server server
- 出现该提示请执行
adb kill-server
后再次执行命令,这是adb 端口冲突引起adb F 08-22 18:04:11 6244 13288 main.cpp:140] could not install *smartsocket*listener:cannot bind to 0.0.0.0:5037
进入Docker_STF,启动 STF 服务 (参考启动 docker_STF)# 进入容器 docker exec -it ${stf} /bin/bash # 启动服务 stf@u-BAD-INDEX:/app$ stf local --public-ip ${Server_IP} --allow-remote
1.2 连接 Server (Server_Docker 内执行) 1
Android可通过WiFi
或USB
方式链接至Local adb
配置 adb host 的方式连上 Local 主机上的Android设备
在Server上,执行下述命令:
仅针对其它操作系统上没有安装stf,所以采用 adb host 的方式连上对应操作系统上的安卓设备
stf provider --name ${Local_Name} --min-port 7400 --max-port 7700 --connect-sub tcp://127.0.0.1:7114 --connect-push tcp://127.0.0.1:7116 --group-timeout 20000 --public-ip ${Server_IP} --storage-url http://localhost:7100/ --adb-host ${Local_IP} --adb-port 5037 --vnc-initial-size 600x800 --allow-remote
当不知道命令如何写的时候,从上面运行STF服务里查找日志里面有
provider
的一行,可以比照出内容怎么写*** STF服务里Log ***
*** 提取到的命令 ***
2. Local系统服务上已安装stf相应组件(多节点_子节点已安装服务)
主节点部署STF服务并允许远程访问API,子节点也部署STF服务并允许远程访问API。然后主节点连接子节点。
这种方案的优点是子节点新增设备可以自动识别。缺点就是 子节点也需要部署STF服务
如:10.16.6.63_Liunx主机,安装了 stf,想将Liunx主机的安卓设备连接到主 Master(MAC:172.17.9.49)平台上。配置新的
provider
连上Liunx 主机上的设备: 在Liunx主机上启动 stf provider 【差异在于,不需要增加--adb-host
】
stf provider --name ${Local_Name} --min-port 7400 --max-port 7700 --connect-sub tcp://172.17.9.49:7114 --connect-push tcp://172.17.9.49:7116 --group-timeout 20000 --public-ip 172.17.9.49 --storage-url http://172.17.9.49:7100/ --vnc-initial-size 600x800 --allow-remote
2.3 重新配置 Docker
在docker中删除原来的stf镜像,重新运行(192.168.1.102 是宿主机IP【本地】,5037 是宿主机暴露的adb端口,192.168.1.120 服务器IP):
docker run -d --name stf --privileged=true --net host openstf/stf stf local --public-ip 15.2.23.203 --adb-host 192.168.1.120 --adb-port 5037 --allow-remote
3. 大功告成
STF 平台效果
执行连接命令 ↩︎
自动 Install Server.apk
↩︎stf@u-BAD-INDEX:/app$ stf provider --name Win_loacl --min-port 7400 --max-port 7700 --connect-sub tcp://127.0.0.1:7114 --connect-push tcp://127.0.0.1:7116 --group-timeout 20000 --public-ip 192.168.50.200 --storage-url http://localhost:7100/ --adb-host 192.168.50.27 --adb-port 5037 --vnc-initial-size 600x800 --allow-remote 2020-11-06T02:15:30.530Z INF/provider 745 [*] Subscribing to permanent channel "vXr8HgAUQVuhwUV5jVqC+A==" 2020-11-06T02:15:30.546Z INF/provider 745 [*] Sending output to "tcp://127.0.0.1:7116" 2020-11-06T02:15:30.547Z INF/provider 745 [*] Receiving input from "tcp://127.0.0.1:7114" 2020-11-06T02:15:30.583Z INF/provider 745 [*] Tracking devices 2020-11-06T02:15:30.875Z INF/provider 745 [*] Found device "127.0.0.1:11509" (device) 2020-11-06T02:15:30.886Z INF/provider 745 [*] Found device "127.0.0.1:62001" (device) 2020-11-06T02:15:30.913Z INF/provider 745 [*] Registered device "127.0.0.1:62001" 2020-11-06T02:15:30.919Z INF/provider 745 [*] Registered device "127.0.0.1:11509" 2020-11-06T02:15:31.250Z INF/device:support:push 753 [127.0.0.1:62001] Sending output to "tcp://127.0.0.1:7116" 2020-11-06T02:15:31.253Z INF/device 753 [127.0.0.1:62001] Preparing device 2020-11-06T02:15:31.253Z INF/device:support:push 758 [127.0.0.1:11509] Sending output to "tcp://127.0.0.1:7116" 2020-11-06T02:15:31.256Z INF/device 758 [127.0.0.1:11509] Preparing device 2020-11-06T02:15:31.562Z INF/device:support:sub 753 [127.0.0.1:62001] Receiving input from "tcp://127.0.0.1:7114" 2020-11-06T02:15:31.562Z INF/device:support:sub 758 [127.0.0.1:11509] Receiving input from "tcp://127.0.0.1:7114" 2020-11-06T02:15:31.563Z INF/device:support:sub 753 [127.0.0.1:62001] Subscribing to permanent channel "*ALL" 2020-11-06T02:15:31.563Z INF/device:support:sub 758 [127.0.0.1:11509] Subscribing to permanent channel "*ALL" 2020-11-06T02:15:31.596Z INF/device:support:properties 758 [127.0.0.1:11509] Loading properties 2020-11-06T02:15:31.597Z INF/device:support:properties 753 [127.0.0.1:62001] Loading properties 2020-11-06T02:15:31.616Z INF/device:support:sdk 753 [127.0.0.1:62001] Supports SDK 22 2020-11-06T02:15:31.617Z INF/device:support:abi 753 [127.0.0.1:62001] Supports ABIs x86, armeabi-v7a, armeabi 2020-11-06T02:15:31.618Z INF/device:support:sdk 758 [127.0.0.1:11509] Supports SDK 25 2020-11-06T02:15:31.618Z INF/device:support:abi 758 [127.0.0.1:11509] Supports ABIs x86, armeabi-v7a, armeabi 2020-11-06T02:15:31.653Z INF/device:resources:minicap 753 [127.0.0.1:62001] Installing "/app/node_modules/minicap-prebuilt-beta/prebuilt/x86/bin/minicap" as "/data/local/tmp/minicap" 2020-11-06T02:15:31.654Z INF/device:resources:minicap 753 [127.0.0.1:62001] Installing "/app/node_modules/minicap-prebuilt-beta/prebuilt/x86/lib/android-22/minicap.so" as "/data/local/tmp/minicap.so" 2020-11-06T02:15:31.867Z INF/device:resources:minicap 758 [127.0.0.1:11509] Installing "/app/node_modules/minicap-prebuilt-beta/prebuilt/x86/bin/minicap" as "/data/local/tmp/minicap" 2020-11-06T02:15:31.868Z INF/device:resources:minicap 758 [127.0.0.1:11509] Installing "/app/node_modules/minicap-prebuilt-beta/prebuilt/x86/lib/android-25/minicap.so" as "/data/local/tmp/minicap.so" 2020-11-06T02:15:32.167Z INF/device:resources:service 758 [127.0.0.1:11509] Checking whether we need to install STFService 2020-11-06T02:15:32.413Z INF/device:resources:service 758 [127.0.0.1:11509] Installing STFService 2020-11-06T02:15:33.282Z INF/device:resources:service 753 [127.0.0.1:62001] Checking whether we need to install STFService 2020-11-06T02:15:33.638Z INF/device:resources:service 753 [127.0.0.1:62001] Running version check 2020-11-06T02:15:34.150Z INF/device:resources:service 758 [127.0.0.1:11509] STFService up to date 2020-11-06T02:15:34.154Z INF/device:plugins:service 758 [127.0.0.1:11509] Launching agent 2020-11-06T02:15:34.156Z INF/device:resources:service 753 [127.0.0.1:62001] STFService up to date 2020-11-06T02:15:34.157Z INF/device:plugins:service 753 [127.0.0.1:62001] Launching agent 2020-11-06T02:15:34.389Z INF/device:plugins:service 758 [127.0.0.1:11509] Agent says: "Listening on @stfagent" 2020-11-06T02:15:34.455Z INF/device:plugins:service 758 [127.0.0.1:11509] Agent says: "InputClient started" 2020-11-06T02:15:34.459Z INF/device:plugins:service 758 [127.0.0.1:11509] Launching service 2020-11-06T02:15:34.461Z INF/device:plugins:service 758 [127.0.0.1:11509] using 'startservice' command for API 25 2020-11-06T02:15:34.506Z INF/device:plugins:service 753 [127.0.0.1:62001] Agent says: "Listening on @stfagent" 2020-11-06T02:15:34.558Z INF/device:plugins:service 753 [127.0.0.1:62001] Agent says: "InputClient started" 2020-11-06T02:15:34.562Z INF/device:plugins:service 753 [127.0.0.1:62001] Launching service 2020-11-06T02:15:34.563Z INF/device:plugins:service 753 [127.0.0.1:62001] using 'startservice' command for API 22 2020-11-06T02:15:34.726Z INF/device:plugins:display 758 [127.0.0.1:11509] Reading display info 2020-11-06T02:15:34.739Z INF/device:plugins:phone 758 [127.0.0.1:11509] Fetching phone info 2020-11-06T02:15:34.747Z INF/device:plugins:identity 758 [127.0.0.1:11509] Solving identity 2020-11-06T02:15:34.752Z INF/device:plugins:solo 758 [127.0.0.1:11509] Subscribing to permanent channel "r6bI/R9p6OMVfH8yXKFPuDFeKCE=" 2020-11-06T02:15:34.753Z INF/device:plugins:screen:stream 758 [127.0.0.1:11509] Starting WebSocket server on port 7404 2020-11-06T02:15:34.790Z INF/device:resources:minitouch 758 [127.0.0.1:11509] Installing "/app/node_modules/minitouch-prebuilt-beta/prebuilt/x86/bin/minitouch" as "/data/local/tmp/minitouch" 2020-11-06T02:15:34.874Z WRN/device:plugins:data 758 [127.0.0.1:11509] Unable to find device data { serial: '127.0.0.1:11509', platform: 'Android', manufacturer: 'LENOVO', operator: 'China Mobile GSM', model: ' L79031', version: '7.1.2', abi: 'x86', sdk: '25', product: 'LENOVO L79031', cpuPlatform: 'gmin', openGLESVersion: '3.1', marketName: 'LENOVO L79031', display: { id: 0, width: 1080, height: 1920, xdpi: 288, ydpi: 288, fps: 60.000003814697266, density: 1.8000000715255737, rotation: 0, secure: true, size: 7.648983229452425, url: 'ws://192.168.50.200:7404' }, phone: { imei: '869307419105530', imsi: '460007514254656', phoneNumber: '+8617630362631', iccid: '89860047730382961832', network: 'UNKNOWN' } } 2020-11-06T02:15:34.887Z INF/device:plugins:touch 758 [127.0.0.1:11509] Touch origin is top left 2020-11-06T02:15:34.888Z INF/device:plugins:touch 758 [127.0.0.1:11509] Requesting touch consumer to start 2020-11-06T02:15:34.890Z INF/device:plugins:touch 758 [127.0.0.1:11509] Launching touch service 2020-11-06T02:15:34.907Z INF/device:plugins:touch 758 [127.0.0.1:11509] Connecting to minitouch service 2020-11-06T02:15:34.909Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Note: device /dev/input/mouse2 is not supported by libevdev" 2020-11-06T02:15:34.996Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Note: device /dev/input/mouse0 is not supported by libevdev" 2020-11-06T02:15:35.118Z INF/device:plugins:display 753 [127.0.0.1:62001] Reading display info 2020-11-06T02:15:35.119Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Note: device /dev/input/mice is not supported by libevdev" 2020-11-06T02:15:35.141Z INF/device:plugins:phone 753 [127.0.0.1:62001] Fetching phone info 2020-11-06T02:15:35.152Z INF/device:plugins:identity 753 [127.0.0.1:62001] Solving identity 2020-11-06T02:15:35.156Z INF/device:plugins:solo 753 [127.0.0.1:62001] Subscribing to permanent channel "RrnVzWA4LxALM2sX1oF/jtolX3M=" 2020-11-06T02:15:35.158Z INF/device:plugins:screen:stream 753 [127.0.0.1:62001] Starting WebSocket server on port 7400 2020-11-06T02:15:35.184Z INF/device:resources:minitouch 753 [127.0.0.1:62001] Installing "/app/node_modules/minitouch-prebuilt-beta/prebuilt/x86/bin/minitouch" as "/data/local/tmp/minitouch" 2020-11-06T02:15:35.239Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Note: device /dev/input/mouse1 is not supported by libevdev" 2020-11-06T02:15:35.241Z WRN/device:plugins:data 753 [127.0.0.1:62001] Unable to find device data { serial: '127.0.0.1:62001', platform: 'Android', manufacturer: 'MOTOROLA', operator: null, model: 'AOSP on Shama', version: '5.1.1', abi: 'x86', sdk: '22', product: 'shamu', cpuPlatform: 'msm8084', openGLESVersion: '2.0', marketName: 'Nexus 6', display: { id: 0, width: 1080, height: 1920, xdpi: 240, ydpi: 240, fps: 60.000003814697266, density: 2, rotation: 0, secure: true, size: 9.17877987534291, url: 'ws://192.168.50.200:7400' }, phone: { imei: '355757210452153', imsi: '460072071521585', phoneNumber: '15801164016', iccid: '89860081012071521585', network: 'EDGE' } } 2020-11-06T02:15:35.255Z INF/device:plugins:touch 753 [127.0.0.1:62001] Touch origin is top left 2020-11-06T02:15:35.257Z INF/device:plugins:touch 753 [127.0.0.1:62001] Requesting touch consumer to start 2020-11-06T02:15:35.259Z INF/device:plugins:touch 753 [127.0.0.1:62001] Launching touch service 2020-11-06T02:15:35.273Z INF/device:plugins:touch 753 [127.0.0.1:62001] Connecting to minitouch service 2020-11-06T02:15:35.277Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "WARNING: linker: /data/local/tmp/minitouch: unused DT entry: type 0x6ffffef5 arg 0x754" 2020-11-06T02:15:35.278Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "WARNING: linker: /data/local/tmp/minitouch: unused DT entry: type 0x6ffffffe arg 0x954" 2020-11-06T02:15:35.279Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "WARNING: linker: /data/local/tmp/minitouch: unused DT entry: type 0x6fffffff arg 0x1" 2020-11-06T02:15:35.280Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "Note: device /dev/input/mouse1 is not supported by libevdev" 2020-11-06T02:15:35.372Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Type B touch device User Input (1080x1920 with 16 contacts) detected on /dev/input/event6 (score 12455)" 2020-11-06T02:15:35.373Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Note: hard-limiting maximum number of contacts to 10" 2020-11-06T02:15:35.470Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "Note: device /dev/input/mice is not supported by libevdev" 2020-11-06T02:15:35.520Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "Note: device /dev/input/mouse0 is not supported by libevdev" 2020-11-06T02:15:35.661Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "Type A touch device Android_Input (1080x1920 with 2 contacts) detected on /dev/input/event5 (score 11440)" 2020-11-06T02:15:35.664Z INF/device:plugins:touch 758 [127.0.0.1:11509] Reading minitouch banner 2020-11-06T02:15:35.669Z INF/device:plugins:touch 758 [127.0.0.1:11509] minitouch says: "Connection established" 2020-11-06T02:15:35.682Z INF/device:plugins:vnc 758 [127.0.0.1:11509] Starting VNC server on port 7406 2020-11-06T02:15:35.688Z INF/device:plugins:browser 758 [127.0.0.1:11509] Loading browser list 2020-11-06T02:15:35.714Z INF/device:plugins:browser 758 [127.0.0.1:11509] Updating browser list 2020-11-06T02:15:35.719Z INF/device:plugins:mute 758 [127.0.0.1:11509] Will not mute master volume 2020-11-06T02:15:35.761Z INF/device:resources:minirev 758 [127.0.0.1:11509] Installing "/app/vendor/minirev/x86/minirev" as "/data/local/tmp/minirev" 2020-11-06T02:15:35.834Z INF/device:plugins:forward 758 [127.0.0.1:11509] Launching reverse port forwarding service 2020-11-06T02:15:35.846Z INF/device:plugins:forward 758 [127.0.0.1:11509] Connecting to reverse port forwarding service 2020-11-06T02:15:36.032Z INF/device:plugins:touch 753 [127.0.0.1:62001] minitouch says: "Connection established" 2020-11-06T02:15:36.034Z INF/device:plugins:touch 753 [127.0.0.1:62001] Reading minitouch banner 2020-11-06T02:15:36.040Z INF/device:plugins:vnc 753 [127.0.0.1:62001] Starting VNC server on port 7402 2020-11-06T02:15:36.041Z INF/device:plugins:browser 753 [127.0.0.1:62001] Loading browser list 2020-11-06T02:15:36.047Z INF/device:plugins:browser 753 [127.0.0.1:62001] Updating browser list 2020-11-06T02:15:36.047Z WRN/device:plugins:browser 753 [127.0.0.1:62001] Unmapped browser "com.baidu.searchbox" 2020-11-06T02:15:36.048Z WRN/device:plugins:browser 753 [127.0.0.1:62001] Unmapped browser "com.taobao.taobao" 2020-11-06T02:15:36.048Z WRN/device:plugins:browser 753 [127.0.0.1:62001] Unmapped browser "com.taobao.litetao" 2020-11-06T02:15:36.050Z INF/device:plugins:mute 753 [127.0.0.1:62001] Will not mute master volume 2020-11-06T02:15:36.070Z INF/device:resources:minirev 753 [127.0.0.1:62001] Installing "/app/vendor/minirev/x86/minirev" as "/data/local/tmp/minirev" 2020-11-06T02:15:36.128Z INF/device:plugins:forward 753 [127.0.0.1:62001] Launching reverse port forwarding service 2020-11-06T02:15:36.133Z INF/device 758 [127.0.0.1:11509] Fully operational 2020-11-06T02:15:36.385Z INF/device:plugins:forward 753 [127.0.0.1:62001] Connecting to reverse port forwarding service 2020-11-06T02:15:37.239Z INF/device 753 [127.0.0.1:62001] Fully operational 2020-11-06T02:15:40.890Z INF/provider 745 [*] Providing all 2 device(s)
Docker_STF_Log ==>> Android Connect Successful ↩︎