Docker Compose 部署 OpenSTF
当前已废弃
项目迁移至https://github.com/DeviceFarmer/stf
使用过的部署方式:
- 使用过npm 方式来安装docker ,这种方式会由于网络,环境等原因产生很多 不可预知的问题,需要一步一步的解决 ,坑很多,很麻烦 .(不推荐)
- 使用 systemctl + docker 来部署stf环境 ,这个种方式已经方便了很多,可以依靠systemctl 来时服务一直在运行,开机自启.(第二推荐)
- 使用 Docker Compose 部署 OpenSTF, (推荐)
环境
Ubuntu 18.04 LTS (Linux ubuntu 4.15.0-42-generic)
Docker 18.09.0
Docker Compose 1.23.2
OpenSTF 3.4.0
IP地址
OpenSTF 服务端:10.8.8.128
OpenSTF 设备提供端:10.8.8.131
Hosts
10.8.8.128 stf.ovwane.com
10.8.8.128 devside.stf.ovwane.com
10.8.8.131 provider1.stf.ovwane.com
一、部署 OpenSTF 服务端
Docker 和 Docker Compose服务请自行百度安装.
拉取镜像
for name in nginx:1.15.7-alpine rethinkdb:2.3.6 openstf/stf:v3.4.0; do
docker pull $name
done
新建目录
mkdir -p /data/stf/nginx/
mkdir stf_app
nginx.conf 配置文件
请修改IP地址和域名 `vim /data/stf/nginx/nginx.conf`
#daemon off
worker_processes 4;
events {
worker_connections 1024;
}
http {
upstream stf_app {
server 10.8.8.128:3100 max_fails=0;
}
upstream stf_auth {
server 10.8.8.128:3101 max_fails=0;
}
upstream stf_storage_apk {
server 10.8.8.128:3102 max_fails=0;
}
upstream stf_storage_image {
server 10.8.8.128:3103 max_fails=0;
}
upstream stf_storage {
server 10.8.8.128:3104 max_fails=0;
}
upstream stf_websocket {
server 10.8.8.128:3105 max_fails=0;
}
upstream stf_api {
server 10.8.8.128:3106 max_fails=0;
}
types {
application/javascript js;
image/gif gif;
image/jpeg jpg;
text/css css;
text/html html;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name stf.ovwane.com;
keepalive_timeout 70;
# resolver 114.114.114.114 8.8.8.8 valid=300s;
# resolver_timeout 10s;
location ~ "^/d/provider1/([^/]+)/(?<port>[0-9]{5})/$" {
proxy_pass http://10.8.8.131:$port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}
location ~ "^/d/provider2/([^/]+)/(?<port>[0-9]{5})/$" {
proxy_pass http://10.8.8.132:$port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}
location /auth/ {
proxy_pass http://stf_auth/auth/;
}
location /api/ {
proxy_pass http://stf_api/api/;
}
location /s/image/ {
proxy_pass http://stf_storage_image;
}
location /s/apk/ {
proxy_pass http://stf_storage_apk;
}
location /s/ {
client_max_body_size 1024m;
client_body_buffer_size 128k;
proxy_pass http://stf_storage;
}
location /socket.io/ {
proxy_pass http://stf_websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $http_x_real_ip;
}
location / {
proxy_pass http://stf_app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $http_x_real_ip;
}
}
}
进入stf_app目录
cd stf_app
配置文件
vim .env
# STF_VERSION=3.4.0 # OpenSTF 版本
# STF_HOST=stf.ovwane.com # 域名
# STF_URL=http://stf.ovwane.com # http 或者 https
# STF_IMAGE=openstf/stf:v3.4.0 # OpenSTF 镜像版本
STF_VERSION=3.4.0
STF_HOST=stf.ovwane.com
STF_URL=http://stf.ovwane.com
STF_IMAGE=openstf/stf:v3.4.0
STF_SECRET=RETHINKDBAUTHKEYANY
Docker Compose 配置文件
vim docker-compose.yml
如果使用 IP 访问,需要修改 stf-log-rethinkdb 处 devside.$STF_HOST 为你的 IP。
version: '3'
services:
nginx:
image: nginx:1.15.7-alpine
volumes:
- /data/stf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
network_mode: "host"
rethinkdb:
depends_on:
- nginx
image: rethinkdb:2.3.6
command: rethinkdb --bind all --cache-size 8192 --http-port 8090 --no-update-check
volumes:
- /data/stf/rethinkdb:/data
network_mode: "host"
stf-migrate:
depends_on:
- rethinkdb
image: $STF_IMAGE
command: stf migrate
network_mode: "host"
stf-app:
depends_on:
- stf-migrate
image: $STF_IMAGE
command: stf app --port 3100 --auth-url ${STF_URL}/auth/mock/ --websocket-url ws://${STF_HOST}/
network_mode: "host"
environment:
SECRET: $STF_SECRET
stf-auth:
depends_on:
- stf-app
image: $STF_IMAGE
command: stf auth-mock --port 3101 --app-url ${STF_URL}
network_mode: "host"
environment:
SECRET: $STF_SECRET
stf-storage-plugin-apk:
depends_on:
- stf-api
image: $STF_IMAGE
command: stf storage-plugin-apk --port 3102 --storage-url ${STF_URL}
network_mode: "host"
stf-storage-plugin-image:
depends_on:
- stf-storage-plugin-apk
image: $STF_IMAGE
command: stf storage-plugin-image --port 3103 --storage-url $STF_URL
network_mode: "host"
stf-storage-temp:
depends_on:
- stf-storage-plugin-image
image: $STF_IMAGE
command: stf storage-temp --port 3104 --save-dir /tmp
network_mode: "host"
stf-websocket:
depends_on:
- stf-auth
image: $STF_IMAGE
command: stf websocket --port 3105 --storage-url $STF_URL --connect-sub tcp://$STF_HOST:7150 --connect-push tcp://$STF_HOST:7170
network_mode: "host"
environment:
SECRET: $STF_SECRET
stf-api:
depends_on:
- stf-websocket
image: $STF_IMAGE
command: stf api --port 3106 --connect-sub tcp://$STF_HOST:7150 --connect-push tcp://$STF_HOST:7170
network_mode: "host"
environment:
SECRET: $STF_SECRET
stf-triproxy-app:
depends_on:
- stf-storage-temp
image: $STF_IMAGE
command: stf triproxy app --bind-pub "tcp://*:7150" --bind-dealer "tcp://*:7160" --bind-pull "tcp://*:7170"
network_mode: "host"
stf-processor:
depends_on:
- stf-triproxy-app
image: $STF_IMAGE
command: stf processor stf-processer --connect-app-dealer tcp://$STF_HOST:7160 --connect-dev-dealer tcp://$STF_HOST:7260
network_mode: "host"
stf-triproxy-dev:
depends_on:
- stf-processor
image: $STF_IMAGE
command: stf triproxy dev --bind-pub "tcp://*:7250" --bind-dealer "tcp://*:7260" --bind-pull "tcp://*:7270"
network_mode: "host"
stf-reaper:
depends_on:
- stf-triproxy-dev
image: $STF_IMAGE
command: stf reaper dev --connect-push tcp://$STF_HOST:7270 --connect-sub tcp://$STF_HOST:7150 --heartbeat-timeout 30000
network_mode: "host"
stf-log-rethinkdb:
depends_on:
- stf-reaper
image: $STF_IMAGE
command: stf log-rethinkdb --connect-sub tcp://devside.$STF_HOST:7150
network_mode: "host"
启动
docker-compose up -d
二、部署 OpenSTF 设备提供端
安装ADB
apt -y install adb
编辑 adbd.service
vim /etc/systemd/system/adbd.service
[Unit]
Description=Android Debug Bridge daemon
After=network.target
[Service]
Restart=always
RestartSec=2s
Type=forking
User=root
ExecStartPre=/usr/bin/adb kill-server
ExecStart=/usr/bin/adb start-server
ExecStop=/usr/bin/adb kill-server
[Install]
WantedBy=multi-user.target
启动 ADB
# 开机自启动
systemctl enable adbd.service
# 启动
systemctl start adbd.service
部署OpenSTF
# 拉取镜像
docker pull openstf/stf:v3.4.0
# 新建目录
mkdir stf_provider
# 进入stf_provider目录
cd stf_provider
配置文件
vim .env
# STF_VERSION=3.4.0 # OpenSTF 版本
# STF_HOST=stf.ovwane.com # 域名
# STF_URL=http://stf.ovwane.com # http 或者 https
# STF_IMAGE=openstf/stf:v3.4.0 # OpenSTF 镜像版本
# STF_PROVIDER=provider1 # provider 编号
STF_VERSION=3.4.0
STF_HOST=stf.ovwane.com
STF_URL=http://stf.ovwane.com
STF_IMAGE=openstf/stf:v3.4.0
STF_PROVIDER=provider1
Docker Compose 配置文件vim docker-compose.yml
如果使用 IP 访问,需要修改 devside.$STF_HOST 为你的 IP。
如果使用 IP 访问,需要修改
S
T
F
P
R
O
V
I
D
E
R
.
STF_PROVIDER.
STFPROVIDER.STF_HOST 为你的 IP。如果此处使用 IP 不能访问,请用域名的方式,然后所有主机绑定 hosts。
version: '3'
services:
stf-provider:
image: $STF_IMAGE
command: stf provider --name "${STF_PROVIDER}" --connect-sub tcp://devside.$STF_HOST:7250 --connect-push tcp://devside.$STF_HOST:7270 --storage-url $STF_URL --public-ip $STF_PROVIDER.$STF_HOST --min-port=15000 --max-port=25000 --heartbeat-interval 20000 --screen-ws-url-pattern "ws://${STF_HOST}/d/${STF_PROVIDER}/<%= serial %>/<%= publicPort %>/"
network_mode: "host"
启动docker-compose up -d