orztv commited on
Commit
c03007d
·
1 Parent(s): 7695663
Files changed (4) hide show
  1. Dockerfile +4 -4
  2. services.json +1 -1
  3. start.sh +5 -1
  4. traefik/dynamic.yml +0 -29
Dockerfile CHANGED
@@ -20,11 +20,11 @@ USER pn
20
  # 设置工作目录
21
  WORKDIR /home/pn/app
22
 
23
- # 创建 Traefik 配置目录
24
- RUN mkdir -p /home/pn/app/traefik
25
 
26
  # 复制配置文件和启动脚本
27
- COPY --chown=pn:pn traefik/ /home/pn/app/traefik/
28
  COPY --chown=pn:pn start.sh /home/pn/app/start.sh
29
  COPY --chown=pn:pn services.json /home/pn/app/services.json
30
  RUN chmod +x /home/pn/app/start.sh
@@ -38,4 +38,4 @@ ENV TRAEFIK_PORT=7860 \
38
  EXPOSE $TRAEFIK_PORT $PYTHON_PORT $NODE_PORT
39
 
40
  # 启动容器时运行启动脚本
41
- CMD ["/home/pn/app/start.sh"]
 
20
  # 设置工作目录
21
  WORKDIR /home/pn/app
22
 
23
+ # 创建必要的目录
24
+ RUN mkdir -p /home/pn/app/traefik /home/pn/app/python /home/pn/app/node
25
 
26
  # 复制配置文件和启动脚本
27
+ COPY --chown=pn:pn traefik/traefik.yml /home/pn/app/traefik/
28
  COPY --chown=pn:pn start.sh /home/pn/app/start.sh
29
  COPY --chown=pn:pn services.json /home/pn/app/services.json
30
  RUN chmod +x /home/pn/app/start.sh
 
38
  EXPOSE $TRAEFIK_PORT $PYTHON_PORT $NODE_PORT
39
 
40
  # 启动容器时运行启动脚本
41
+ CMD ["/home/pn/app/start.sh"]
services.json CHANGED
@@ -12,7 +12,7 @@
12
  },
13
  {
14
  "name": "node-service",
15
- "command": "http-server",
16
  "port": 8001,
17
  "path_prefix": "/node",
18
  "health_check_path": "/",
 
12
  },
13
  {
14
  "name": "node-service",
15
+ "command": "npx http-server",
16
  "port": 8001,
17
  "path_prefix": "/node",
18
  "health_check_path": "/",
start.sh CHANGED
@@ -7,7 +7,7 @@ log() {
7
  }
8
 
9
  # 捕获 SIGTERM 信号,优雅关闭所有后台进程
10
- trap "log '收到终止信号,关闭进程...'; kill $(jobs -p); exit 0" SIGTERM
11
 
12
  # 读取服务配置
13
  services=$(jq -c '.[]' services.json)
@@ -76,6 +76,10 @@ echo "$services" | while read -r service; do
76
  eval $(echo $service | jq -r '.env // {} | to_entries | .[] | "export " + .key + "=\"" + .value + "\""')
77
 
78
  # 切换到工作目录并启动服务
 
 
 
 
79
  (cd $working_dir && $command -p $port) &
80
  done
81
 
 
7
  }
8
 
9
  # 捕获 SIGTERM 信号,优雅关闭所有后台进程
10
+ trap "log '收到终止信号,关闭进程...'; kill \$(jobs -p) 2>/dev/null; exit 0" SIGTERM
11
 
12
  # 读取服务配置
13
  services=$(jq -c '.[]' services.json)
 
76
  eval $(echo $service | jq -r '.env // {} | to_entries | .[] | "export " + .key + "=\"" + .value + "\""')
77
 
78
  # 切换到工作目录并启动服务
79
+ if [ ! -d "$working_dir" ]; then
80
+ log "ERROR: Directory $working_dir does not exist"
81
+ exit 1
82
+ fi
83
  (cd $working_dir && $command -p $port) &
84
  done
85
 
traefik/dynamic.yml DELETED
@@ -1,29 +0,0 @@
1
- http:
2
- routers:
3
- python-service:
4
- rule: "PathPrefix(`/python`)"
5
- service: python-service
6
- middlewares:
7
- - strip-prefix
8
- node-service:
9
- rule: "PathPrefix(`/node`)"
10
- service: node-service
11
- middlewares:
12
- - strip-prefix
13
-
14
- services:
15
- python-service:
16
- loadBalancer:
17
- servers:
18
- - url: "http://localhost:${PYTHON_PORT}"
19
- node-service:
20
- loadBalancer:
21
- servers:
22
- - url: "http://localhost:${NODE_PORT}"
23
-
24
- middlewares:
25
- strip-prefix:
26
- stripPrefix:
27
- prefixes:
28
- - "/python"
29
- - "/node"