b / Dockerfile
asfag654's picture
Update Dockerfile
d957e53 verified
# 第一阶段:基础设置和代码克隆
FROM alpine:3.18 AS base
ENV TZ=Asia/Shanghai
# 设置时区并安装 Git
RUN apk add --no-cache git tzdata \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
WORKDIR /zmal
RUN git clone --recursive https://github.com/kmizmal/blivechat.git
# 第二阶段:前端构建
FROM node:18.17.0-bullseye AS builder
WORKDIR /zmal/blivechat/frontend
# 仅复制需要的文件以提高构建缓存命中率
COPY --from=base /zmal/blivechat/frontend/package.json package.json
RUN npm install
COPY --from=base /zmal/blivechat/frontend ./
RUN npm run build
# 第三阶段:后端设置
FROM python:3.12.7-bookworm
ENV TZ=Asia/Shanghai
WORKDIR /zmal/blivechat
# 拷贝基础代码和构建好的前端
COPY --from=base /zmal/blivechat ./
COPY --from=builder /zmal/blivechat/frontend/dist frontend/dist/
# 安装 Python 依赖
RUN pip3 install --no-cache-dir -r requirements.txt
# 设置时区并调整权限
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone \
&& chmod -R 777 /zmal
COPY config.ini /zmal/blivechat/data/config.ini
RUN --mount=type=secret,id=ID,mode=0444,required=true \
sed -i "s|^open_live_access_key_id *=.*|open_live_access_key_id = $(cat /run/secrets/ID)|" /zmal/blivechat/data/config.ini
#RUN --mount=type=secret,id=SECRET,mode=0444,required=true \
# sed -i "s|^open_live_access_key_secret *=.*|open_live_access_key_secret = $(cat /run/secrets/SECRET)|" /zmal/blivechat/data/config.ini
# 暴露端口并启动
EXPOSE 12450
# 设置目录权限
RUN chmod -R 777 /zmal
RUN cat /zmal/blivechat/data/config.ini
ENTRYPOINT ["python3", "main.py"]
CMD ["--host", "0.0.0.0", "--port", "12450","--debug"]