Add pre-compiled deployment support (Dockerfile.fast) and optimized build process
This commit is contained in:
28
Dockerfile.fast
Normal file
28
Dockerfile.fast
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# 预编译生产镜像
|
||||||
|
# 使用此镜像前请先在本地运行: npm install && npm run build
|
||||||
|
|
||||||
|
FROM node:20-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 设置镜像源提高安装速度
|
||||||
|
RUN npm config set registry https://registry.npmmirror.com
|
||||||
|
|
||||||
|
# 只拷贝生产依赖和编译好的产物
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN apt-get update && apt-get install -y python3 make g++ \
|
||||||
|
&& npm install --omit=dev \
|
||||||
|
&& apt-get purge -y python3 make g++ \
|
||||||
|
&& apt-get autoremove -y \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# 拷贝本地编译好的 build 和 static 目录
|
||||||
|
COPY build ./build
|
||||||
|
COPY static ./static
|
||||||
|
|
||||||
|
ENV PORT=1995
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
EXPOSE 1995
|
||||||
|
|
||||||
|
CMD ["node", "build"]
|
||||||
14
README.md
14
README.md
@@ -24,3 +24,17 @@ docker-compose up -d
|
|||||||
# 查看日志
|
# 查看日志
|
||||||
docker-compose logs -f
|
docker-compose logs -f
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 3. 先编译后打包 (推荐:适用于性能较弱的服务器)
|
||||||
|
在本地预先编译,仅将结果推送到容器,可极大地减少部署时间。
|
||||||
|
```bash
|
||||||
|
# 1. 本地编译
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# 2. 使用精简版 Dockerfile 构建
|
||||||
|
docker build -t vox-fast -f Dockerfile.fast .
|
||||||
|
|
||||||
|
# 3. 运行
|
||||||
|
docker run -p 1995:1995 -v $(pwd)/data.db:/app/data.db vox-fast
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user