优化镜像体积

缩小体积
This commit is contained in:
KenGrofork 2024-04-22 13:55:54 +08:00
parent 11283a3906
commit 49a72b7198
2 changed files with 15 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules
pnpm-lock.yaml
sql
data
.idea

View File

@ -1,8 +1,8 @@
# 编译阶段
FROM node:18-alpine AS build
FROM node:18-alpine AS base
FROM base AS build
WORKDIR /app
COPY . .
COPY package.json ./
# 使用腾讯源(国内服务器可取消下方注释以提升安装速度)
# RUN npm config set registry https://mirrors.cloud.tencent.com/npm/
@ -13,16 +13,21 @@ COPY . .
# 如遇到提示网站证书无效取消下方注释禁止严格SS策略
# RUN npm config set strict-ssl false
# 使用 pnpm 安装项目依赖
RUN npm install -g pnpm
RUN pnpm install
# 安装项目依赖
RUN apk add --no-cache --virtual .build-deps git && \
npm install --omit=dev && \
apk del .build-deps
# 运行阶段
FROM node:18-alpine
FROM base AS runner
ENV TZ="Asia/Shanghai"
WORKDIR /app
COPY --from=build /app .
COPY --from=build /app/node_modules ./node_modules
COPY . .
EXPOSE 9520
CMD ["node", "./dist/main.js"]