Skip to content

Commit efcaaf8

Browse files
jss-tgipcjscli
authored
feat: 使用docker自动下载前端 (#23)
* wip: add web-downloader * wip: xx * fix: `no such file or directory` * wip: add bus * wip: 更新readme * wip: xx * wip: refactor to use override * wip: 添加覆写目录 * wip: 更新文档 * wip: 使用index-seo.html来处理爬虫获取不到JS更新之后的标题的问题 * wip: 更新文档和distar部署脚本, 使用index-seo.html来交给爬虫读取 --------- Co-authored-by: ipcjs.mac4 <[email protected]> Co-authored-by: cli <cli@debian>
1 parent 5f2f988 commit efcaaf8

File tree

12 files changed

+183
-16
lines changed

12 files changed

+183
-16
lines changed

.env.default

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,28 @@ WEB_BASE_URL='' # https://livedvr.tripsdd.com
2525
DATA_DIR=/data
2626
# docker仓库的目录, 不建议在compose文件中引用docker仓库的绝对路径, 建议使用configs替代: https://docs.docker.com/reference/compose-file/configs/
2727
DOCKER_DIR=/home/docker
28+
DOCKER_COMPOSE_DIR=/home/docker-compose
2829

2930
## 版本号, 设为latest则使用最新版
3031
# bus前端版本
3132
BUS_WEB_VERSION=5.30.0
33+
# bus前端文件复写目录, 该目录中的文件会在compose被up时被复制到bus前端目录, 通常可以复写如下文件:
34+
# - _app.config.js: 前端配置文件
35+
BUS_WEB_OVERRIDE_DIR=${DOCKER_COMPOSE_DIR}/bus-override
3236
# bus的后端, gateway-web和gateway-dispatch共用一个版本号
3337
BUS_GATEWAY_VERSION=1.21.1
3438
BUS_GATEWAY_808_2019_VERSION=25.8.25
3539
BUS_GATEWAY_JSATL12_VERSION=23.1.21
3640
BUS_GATEWAY_CALCULATION_VERSION=1.17.0
3741
# track前端版本
3842
TRACK_WEB_VERSION=1.53.0
43+
# track前端文件复写目录, 该目录中的文件会在compose被up时被复制到track前端目录, 通常可以复写如下文件:
44+
# - _app.config.js: 前端配置文件
45+
# - index-seo.html: 交给爬虫(搜索引擎/Line网页摘要等)读取的静态页面
46+
# - favicon.ico: ico图标
47+
# - favicon.png: png图标
48+
# - logo.png: 大图标
49+
TRACK_WEB_OVERRIDE_DIR=${DOCKER_COMPOSE_DIR}/track-override
3950
TRACK_MAINTAIN_VERSION=1.45.0
4051
TRACK_JTT808_VERSION=1.18.0
4152

@@ -92,7 +103,7 @@ MAINTAIN_PORT='8080'
92103
# - access/ras_key|ras_key.pub: 访问密钥的公私钥对
93104
# - refresh/ras_key|ras_key.pub: 刷新密钥的公私钥对
94105
# - ip2region.xdb: ip到区域的映射数据, 手动下载连接: https://raw.githubusercontent.com/lionsoul2014/ip2region/master/data/ip2region.xdb
95-
MAINTAIN_TOKEN_DIR='/home/docker-compose/token'
106+
MAINTAIN_TOKEN_DIR=${DOCKER_COMPOSE_DIR}/token
96107

97108
## MYSQL, 必填
98109
MYSQL_HOST='mysql8' # mysql8 | ${SERVER_IP_INTERNAL} | ${SERVER_IP_PUBLIC}

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ git clone https://github.com/TranscodeGroup/docker.git /home/docker
1919
- [video-storage](./examples/video-storage/compose.yaml): RTP存储
2020
- [video-stream](./examples/video-stream/compose.yaml): RTP视频
2121
- [track](./examples/track/compose.yaml): Tracker V2单机部署
22+
- etc.
2223

2324
### 3. 配置`.env`
2425

@@ -38,6 +39,16 @@ docker compose config > compose-stack.yaml
3839

3940
### 4. 下载前端文件
4041

42+
#### 使用Docker自动下载
43+
44+
`/home/docker-compose/compose.yaml`文件中, `include`如下服务, 即可自动下载前端:
45+
46+
- [compose.yaml](./web-downloader/compose.yaml): 自动下载的基础配置
47+
- [compose.track.yaml](./web-downloader/compose.track.yaml): 自动下载track的配置, 可选;
48+
- [compose.bus.yaml](./web-downloader/compose.bus.yaml): 自动下载bus的配置, 可选;
49+
50+
#### 手动下载
51+
4152
部署distar等项目的前端:
4253
[说明文件](projects/README.md)
4354

nginx/conf/conf.d/track.conf.template

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ server {
1818

1919
# 平台前端
2020
location / {
21-
alias /usr/share/nginx/html/track/;
21+
root /usr/share/nginx/html/track;
2222
index index.html index.htm;
23+
24+
if ($is_crawler) {
25+
rewrite ^/(index.html)?$ /index-seo.html last;
26+
}
27+
}
28+
29+
# 平台前端, 交给爬虫读取的index文件
30+
location = /index-seo.html {
31+
root /usr/share/nginx/html/track;
32+
try_files /index-seo.html /index.html =404;
2333
}
2434

2535
location /track {

nginx/conf/nginx.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ http {
6464
'' close;
6565
}
6666

67+
# 检测是否是爬虫
68+
map $http_user_agent $is_crawler {
69+
default 0;
70+
# 搜索引擎
71+
~*(Googlebot|Bingbot|Baiduspider|Slurp|DuckDuckBot|Sogou|360Spider|Yandex|Applebot) 1;
72+
# 社交媒体
73+
~*(facebookexternalhit|Twitterbot|LinkedInBot|Slackbot|Discordbot|Linespider|Bytespider) 1;
74+
# 新兴AI
75+
~*(GPTBot|ChatGPT-User|ClaudeBot|PerplexityBot|CCBot) 1;
76+
}
77+
6778
# Docker Compose的默认DNS
6879
# https://stackoverflow.com/questions/35744650/docker-network-nginx-resolver
6980
resolver 127.0.0.11;

projects/distar-beta-deploy.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,22 @@ cp -Rfv "$CONFIG_DIR"/* "$target_dir"
123123
# 指定要处理的HTML文件
124124
cd "$target_dir"
125125
html_file="index.html"
126-
127-
# 使用sed命令进行文本替换, 网站微缩图
128-
OLD_TITLE='中车在线'
129-
NEW_TITLE='DiStarGPS'
130-
OLD_DIV='数字交通云平台'
131-
NEW_DIV='ดูแลการเดินรถของคุ'
132-
133-
# 使用sed命令进行文本替换
134-
sed -i.bak "s|$OLD_TITLE|$NEW_TITLE|g" "$html_file"
135-
sed -i.bak "s|$OLD_DIV|$NEW_DIV|g" "$html_file"
136-
rm "$html_file".bak
137-
138-
echo "替换完成:$html_file 中的 '工物员' 已被替换为 'DiStarGPS ดูแลการเดินรถของคุณ'"
126+
if [ -f "index-seo.html" ]; then
127+
echo "index-seo.html文件已存在, 爬虫访问网站时, 它的优先级更高, 不需要替换${html_file}里面的标题&描述"
128+
else
129+
# 使用sed命令进行文本替换, 网站微缩图
130+
OLD_TITLE='中车在线'
131+
NEW_TITLE='DiStarGPS'
132+
OLD_DIV='数字交通云平台'
133+
NEW_DIV='ดูแลการเดินรถของคุ'
134+
135+
# 使用sed命令进行文本替换
136+
sed -i.bak "s|$OLD_TITLE|$NEW_TITLE|g" "$html_file"
137+
sed -i.bak "s|$OLD_DIV|$NEW_DIV|g" "$html_file"
138+
rm "$html_file".bak
139+
140+
echo "替换完成:$html_file 中的 '工物员' 已被替换为 'DiStarGPS ดูแลการเดินรถของคุณ'"
141+
fi
139142

140143
echo "解压完成,目录 -> " "$target_dir"
141144
echo "beta路径,复制到浏览器可预览 -> " https://tripsdd.com/beta/"$target_dir"

projects/distar/index-seo.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width,initial-scale=1" />
7+
<title>DiStarGPS</title>
8+
<meta name="description" content="ดูแลการเดินรถของคุณ" />
9+
<link rel="apple-touch-icon" href="./favicon.png" />
10+
<link rel="shortcut icon" href="./favicon.ico" />
11+
</head>
12+
13+
<body>
14+
<h1>DiStarGPS</h1>
15+
<p>ดูแลการเดินรถของคุณ</p>
16+
</body>
17+
18+
</html>

projects/teamcity-download-artifact.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# 默认使用名为artifacts的token, 权限较小(被设置为: `<Root project>: View build runtime parameters and data`)
44
# @see http://th-ci.transcodegroup.cn:9080/profile.html?item=accessTokens

web-downloader/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.env.default

web-downloader/compose.bus.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
web-downloader-bus:
3+
# Remove the profiles field to enable the service
4+
profiles: !reset null

web-downloader/compose.track.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
web-downloader-track:
3+
# Remove the profiles field to enable the service
4+
profiles: !reset null

0 commit comments

Comments
 (0)