2024-01-23 21:45:25 +08:00
|
|
|
|
# 编译阶段
|
2024-07-07 13:09:08 +08:00
|
|
|
|
FROM node:20.14.0-alpine AS build
|
2024-01-23 21:45:25 +08:00
|
|
|
|
|
2024-07-07 13:09:08 +08:00
|
|
|
|
WORKDIR /app
|
2024-04-20 22:15:08 +08:00
|
|
|
|
|
2024-07-07 13:09:08 +08:00
|
|
|
|
COPY package*.json ./
|
2024-04-21 08:23:07 +08:00
|
|
|
|
|
2024-07-07 13:09:08 +08:00
|
|
|
|
# 设置环境变量来忽略一些警告
|
|
|
|
|
ENV NPM_CONFIG_LOGLEVEL=error
|
|
|
|
|
ENV NODE_OPTIONS=--max-old-space-size=4096
|
2024-04-22 13:55:54 +08:00
|
|
|
|
|
2024-07-07 13:09:08 +08:00
|
|
|
|
# 合并RUN命令,更新依赖,设置镜像源,安装依赖,然后清理
|
|
|
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
|
|
|
|
npm config set registry https://registry.npmmirror.com && \
|
|
|
|
|
apk add --no-cache --virtual .build-deps git && \
|
|
|
|
|
npm install -g npm@latest && \
|
|
|
|
|
npm install --production --no-optional --legacy-peer-deps && \
|
|
|
|
|
npm cache clean --force && \
|
|
|
|
|
apk del .build-deps && \
|
|
|
|
|
rm -rf /var/cache/apk/* /tmp/*
|
2024-01-23 21:45:25 +08:00
|
|
|
|
|
|
|
|
|
# 运行阶段
|
2024-07-07 13:09:08 +08:00
|
|
|
|
FROM node:20.14.0-alpine AS runner
|
|
|
|
|
|
|
|
|
|
ENV TZ="Asia/Shanghai" \
|
|
|
|
|
NODE_ENV=production
|
2024-01-23 21:45:25 +08:00
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
2024-04-22 13:55:54 +08:00
|
|
|
|
|
|
|
|
|
COPY --from=build /app/node_modules ./node_modules
|
|
|
|
|
COPY . .
|
|
|
|
|
|
2024-01-23 21:45:25 +08:00
|
|
|
|
EXPOSE 9520
|
|
|
|
|
|
2024-07-07 13:09:08 +08:00
|
|
|
|
CMD ["node", "--max-old-space-size=4096", "./dist/main.js"]
|