mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-03-23 00:00:38 +08:00
整理docker构建、使用多阶段构建
This commit is contained in:
parent
801280efbd
commit
9f8f238426
55
Dockerfile
55
Dockerfile
@ -1,35 +1,46 @@
|
|||||||
# 运行时
|
#
|
||||||
FROM python:3.7.10-slim-stretch
|
# 构建前端
|
||||||
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak \
|
#
|
||||||
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free">>/etc/apt/sources.list \
|
|
||||||
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free">>/etc/apt/sources.list \
|
|
||||||
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free">>/etc/apt/sources.list \
|
|
||||||
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free">>/etc/apt/sources.list \
|
|
||||||
&& apt-get update \
|
|
||||||
&& apt-get install -y wget tar xz-utils
|
|
||||||
RUN wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz \
|
|
||||||
&& tar -xvf node-v10.16.0-linux-x64.tar.xz \
|
|
||||||
&& rm node-v10.16.0-linux-x64.tar.xz \
|
|
||||||
&& ln -s /node-v10.16.0-linux-x64/bin/node /usr/local/bin/node \
|
|
||||||
&& ln -s /node-v10.16.0-linux-x64/bin/npm /usr/local/bin/npm
|
|
||||||
|
|
||||||
# 后端依赖
|
FROM node:16.14.0-bullseye AS builder
|
||||||
WORKDIR /blivechat
|
ARG BASE_PATH='/root/blivechat'
|
||||||
COPY requirements.txt ./
|
WORKDIR "${BASE_PATH}/frontend"
|
||||||
RUN pip3 install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
|
|
||||||
|
|
||||||
# 前端依赖
|
# 前端依赖
|
||||||
WORKDIR ./frontend
|
|
||||||
COPY frontend/package.json ./
|
COPY frontend/package.json ./
|
||||||
RUN npm i --registry=https://registry.npmmirror.com
|
RUN npm i --registry=https://registry.npmmirror.com
|
||||||
|
|
||||||
# 编译前端
|
# 编译前端
|
||||||
COPY . ../
|
COPY frontend ./
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
#
|
||||||
|
# 准备后端
|
||||||
|
#
|
||||||
|
|
||||||
|
FROM python:3.8.12-bullseye
|
||||||
|
ARG BASE_PATH='/root/blivechat'
|
||||||
|
ARG EXT_DATA_PATH='/mnt/data'
|
||||||
|
WORKDIR "${BASE_PATH}"
|
||||||
|
|
||||||
|
# 后端依赖
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip3 install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
|
||||||
|
|
||||||
|
# 数据目录
|
||||||
|
COPY . ./
|
||||||
|
RUN mkdir -p "${EXT_DATA_PATH}/frontend/dist" \
|
||||||
|
&& mv data "${EXT_DATA_PATH}/data" \
|
||||||
|
&& ln -s "${EXT_DATA_PATH}/data" data \
|
||||||
|
&& mv log "${EXT_DATA_PATH}/log" \
|
||||||
|
&& ln -s "${EXT_DATA_PATH}/log" log \
|
||||||
|
&& ln -s "${EXT_DATA_PATH}/frontend/dist" frontend/dist
|
||||||
|
|
||||||
|
# 编译好的前端
|
||||||
|
COPY --from=builder "${BASE_PATH}/frontend/dist" "${EXT_DATA_PATH}/frontend/dist/"
|
||||||
|
|
||||||
# 运行
|
# 运行
|
||||||
WORKDIR ..
|
VOLUME "${EXT_DATA_PATH}"
|
||||||
VOLUME /blivechat/data /blivechat/log /blivechat/frontend/dist
|
|
||||||
EXPOSE 12450
|
EXPOSE 12450
|
||||||
ENTRYPOINT ["python3", "main.py"]
|
ENTRYPOINT ["python3", "main.py"]
|
||||||
CMD ["--host", "0.0.0.0", "--port", "12450"]
|
CMD ["--host", "0.0.0.0", "--port", "12450"]
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
* 高亮舰队、房管、主播的用户名
|
* 高亮舰队、房管、主播的用户名
|
||||||
* 支持屏蔽弹幕、合并相似弹幕等设置
|
* 支持屏蔽弹幕、合并相似弹幕等设置
|
||||||
* 自带两种样式生成器,经典YouTube风格和仿微信风格
|
* 自带两种样式生成器,经典YouTube风格和仿微信风格
|
||||||
|
* 支持前端直连B站服务器或者通过后端转发
|
||||||
* 支持自动翻译弹幕、醒目留言到日语,可以在后台配置翻译目标语言
|
* 支持自动翻译弹幕、醒目留言到日语,可以在后台配置翻译目标语言
|
||||||
* 支持标注打赏用户名的读音,可选拼音或日文假名
|
* 支持标注打赏用户名的读音,可选拼音或日文假名
|
||||||
* 支持配置自定义表情,不需要开通B站官方表情
|
* 支持配置自定义表情,不需要开通B站官方表情
|
||||||
@ -68,9 +69,7 @@
|
|||||||
### 四、Docker(自建服务器)
|
### 四、Docker(自建服务器)
|
||||||
1. ```sh
|
1. ```sh
|
||||||
docker run --name blivechat -d -p 12450:12450 \
|
docker run --name blivechat -d -p 12450:12450 \
|
||||||
--mount source=blc-data,target=/blivechat/data \
|
--mount source=blivechat-data,target=/mnt/data \
|
||||||
--mount source=blc-log,target=/blivechat/log \
|
|
||||||
--mount source=blc-frontend,target=/blivechat/frontend/dist \
|
|
||||||
xfgryujk/blivechat:latest
|
xfgryujk/blivechat:latest
|
||||||
```
|
```
|
||||||
2. 用浏览器打开[http://localhost:12450](http://localhost:12450),以下略
|
2. 用浏览器打开[http://localhost:12450](http://localhost:12450),以下略
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import asyncio
|
import asyncio
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import tornado.web
|
import tornado.web
|
||||||
@ -9,6 +10,8 @@ import api.base
|
|||||||
import config
|
import config
|
||||||
import update
|
import update
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MainHandler(tornado.web.StaticFileHandler): # noqa
|
class MainHandler(tornado.web.StaticFileHandler): # noqa
|
||||||
"""为了使用Vue Router的history模式,把不存在的文件请求转发到index.html"""
|
"""为了使用Vue Router的history模式,把不存在的文件请求转发到index.html"""
|
||||||
@ -51,16 +54,18 @@ class UploadEmoticonHandler(api.base.ApiHandler): # noqa
|
|||||||
raise tornado.web.HTTPError(415)
|
raise tornado.web.HTTPError(415)
|
||||||
|
|
||||||
url = await asyncio.get_event_loop().run_in_executor(
|
url = await asyncio.get_event_loop().run_in_executor(
|
||||||
None, self._save_file, self.settings['WEB_ROOT'], file.body
|
None, self._save_file, file.body, self.settings['WEB_ROOT'], self.request.remote_ip
|
||||||
)
|
)
|
||||||
self.write({
|
self.write({
|
||||||
'url': url
|
'url': url
|
||||||
})
|
})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _save_file(web_root, body):
|
def _save_file(body, web_root, client):
|
||||||
md5 = hashlib.md5(body).hexdigest()
|
md5 = hashlib.md5(body).hexdigest()
|
||||||
rel_path = os.path.join('upload', md5 + '.png')
|
rel_path = os.path.join('upload', md5 + '.png')
|
||||||
|
logger.info('client=%s uploaded file, path=%s, size=%d', client, rel_path, len(body))
|
||||||
|
|
||||||
abs_path = os.path.join(web_root, rel_path)
|
abs_path = os.path.join(web_root, rel_path)
|
||||||
tmp_path = abs_path + '.tmp'
|
tmp_path = abs_path + '.tmp'
|
||||||
with open(tmp_path, 'wb') as f:
|
with open(tmp_path, 'wb') as f:
|
||||||
|
Loading…
Reference in New Issue
Block a user