asfag654 commited on
Commit
a162cf7
·
verified ·
1 Parent(s): 14d9583

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -35
Dockerfile CHANGED
@@ -1,50 +1,33 @@
1
- FROM node:latest
 
2
  ENV TZ=Asia/Shanghai
3
- RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
4
- echo $TZ > /etc/timezone
5
- ENV DEBIAN_FRONTEND=noninteractive
6
- RUN apt-get update && \
7
- apt-get install -y -qq git
8
  WORKDIR /zmal
9
  RUN git clone --recursive https://github.com/xfgryujk/blivechat.git
10
- WORKDIR /zmal/blivechat
11
-
12
- #
13
- # 构建前端
14
- #
15
 
 
16
  FROM node:18.17.0-bullseye AS builder
17
- ARG BASE_PATH='/root/blivechat'
18
- WORKDIR "${BASE_PATH}/frontend"
19
-
20
- # 前端依赖
21
- COPY frontend/package.json ./
22
- RUN npm i
23
-
24
- # 编译前端
25
- COPY frontend ./
26
  RUN npm run build
27
 
28
- #
29
- # 准备后端
30
- #
31
-
32
  FROM python:3.12.7-bookworm
33
- ARG BASE_PATH='/zmal/blivechat'
34
- WORKDIR "${BASE_PATH}"
35
 
36
- # 后端依赖
37
- COPY blivedm/requirements.txt blivedm/
38
- COPY requirements.txt ./
39
- RUN pip3 install --no-cache-dir -r requirements.txt
40
 
41
- # 拷贝代码
42
- COPY . ./
43
 
44
- # 编译好的前端
45
- COPY --from=builder "${BASE_PATH}/frontend/dist" frontend/dist/
46
 
47
- # 运行
48
  EXPOSE 12450
49
  ENTRYPOINT ["python3", "main.py"]
50
  CMD ["--host", "0.0.0.0", "--port", "12450"]
 
1
+ # 第一阶段:基础设置和代码克隆
2
+ FROM node:latest AS base
3
  ENV TZ=Asia/Shanghai
4
+ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
5
+ RUN apt-get update && apt-get install -y -qq git
 
 
 
6
  WORKDIR /zmal
7
  RUN git clone --recursive https://github.com/xfgryujk/blivechat.git
 
 
 
 
 
8
 
9
+ # 第二阶段:前端构建
10
  FROM node:18.17.0-bullseye AS builder
11
+ WORKDIR /zmal/blivechat/frontend
12
+ COPY --from=base /zmal/blivechat/frontend/package.json ./
13
+ RUN npm install
14
+ COPY --from=base /zmal/blivechat/frontend ./
 
 
 
 
 
15
  RUN npm run build
16
 
17
+ # 第三阶段:后端设置
 
 
 
18
  FROM python:3.12.7-bookworm
19
+ WORKDIR /zmal/blivechat
 
20
 
21
+ # 从第一阶段复制克隆的代码
22
+ COPY --from=base /zmal/blivechat ./
 
 
23
 
24
+ # 安装 Python 依赖
25
+ RUN pip3 install --no-cache-dir -r requirements.txt
26
 
27
+ # 拷贝编译好的前端
28
+ COPY --from=builder /zmal/blivechat/frontend/dist frontend/dist/
29
 
30
+ # 暴露端口并启动
31
  EXPOSE 12450
32
  ENTRYPOINT ["python3", "main.py"]
33
  CMD ["--host", "0.0.0.0", "--port", "12450"]