STF 使用 Docker Compose 部署 OpenSTF

ovwane · December 11, 2018 · Last by zailushang replied at June 13, 2019 · 2406 hits

简介

这只是一个操作步骤,背景知识参考 STF 正式环境 docker 化集群部署

环境

软件版本

  • 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

安装 Docker


apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 添加 Docker
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# 安装 Docker
apt-get install -y docker-ce

# 启动 Docker
systemctl start docker.service

安装 Docker Compose

# 下载 Docker Compose
curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# 添加执行权限
chmod +x /usr/local/bin/docker-compose

部署 OpenSTF 服务端

拉取镜像

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
STF_HOST=stf.ovwane.com
STF_URL=http://stf.ovwane.com
STF_IMAGE=openstf/stf:v3.4.0
STF_SECRET=RETHINKDBAUTHKEYANY

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 镜像版本

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
STF_HOST=stf.ovwane.com
STF_URL=http://stf.ovwane.com
STF_IMAGE=openstf/stf:v3.4.0
STF_PROVIDER=provider1

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 编号

Docker Compose 配置文件

vim docker-compose.yml

如果使用 IP 访问,需要修改 devside.$STF_HOST 为你的 IP。
如果使用 IP 访问,需要修改 $STF_PROVIDER.$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

参考

共收到 8 条回复 时间 点赞
ovwane STF 正式环境 docker 化集群部署 中提及了此贴 11 Dec 20:47

挺好的文章呀!为啥没人回复呢?

多谢楼主分享,文章很好。
目前的服务端已经搭建完毕,并且可以正常登录。
但是,provider启动后,在服务端没有发现provider端的设备。
server端的域名我改成了IP,跟这个没关系吧?

方便加微信请教一下吗?TTMMD155

x 回复

你配置成功了吗?我遇到点问题

zailushang 回复

我添加你的微信了,但是没有找到这个帐号。我的微信:samjquan

社区就是用compose部署的

8Floor has been deleted
9Floor has been deleted
恒温 回复

嗯嗯,compose确实很方便

你好,我遇到了点问题
用docker部署后在本机是能访问的到的 在局域网 用其他机器访问ip地址就不行?是什么原因呢? 是docker配置问题吗?

补充:

1、docker-compose up -d报错

ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

解决方案:https://stackoverflow.com/questions/42139982/version-in-docker-compose-yml-is-unsupported-you-might-be-seeing-this-error

2、小米手机连接问题

参考贴:https://testerhome.com/topics/12524
关键:需要登录小米账号

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up