大幅度优化打包速度

This commit is contained in:
sijinhui
2024-01-06 00:31:35 +08:00
parent 8af6362afd
commit a806f07d1c
4 changed files with 130 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
#FROM registry.cn-hangzhou.aliyuncs.com/sijinhui/node:18-alpine AS base
FROM node:18-alpine AS base
FROM node:20-alpine AS base
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk update && apk add --no-cache git tzdata
# 设置时区环境变量
@@ -7,52 +7,53 @@ ENV TZ=Asia/Chongqing
# 更新并安装时区工具
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM base AS deps
RUN apk add --no-cache libc6-compat g++ make
WORKDIR /app
COPY package.json ./
RUN yarn config set registry 'https://registry.npmmirror.com/'
RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
RUN # 清理遗留的缓存
RUN yarn cache clean
RUN yarn install
# 避免下面那个报错
RUN mkdir -p "/app/node_modules/tiktoken"
FROM base AS builder
ENV OPENAI_API_KEY=""
ENV GOOGLE_API_KEY=""
ENV CODE=""
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build
#FROM base AS deps
#RUN apk add --no-cache libc6-compat g++ make
#
#WORKDIR /app
#
#COPY package.json ./
#
#RUN yarn config set registry 'https://registry.npmmirror.com/'
#RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
#RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
#RUN # 清理遗留的缓存
#RUN yarn cache clean
#RUN yarn install
#
## 避免下面那个报错
#RUN mkdir -p "/app/node_modules/tiktoken"
#
#FROM base AS builder
#
#ENV OPENAI_API_KEY=""
#ENV GOOGLE_API_KEY=""
#ENV CODE=""
#
#WORKDIR /app
#COPY . .
#COPY --from=deps /app/node_modules ./node_modules
#
#RUN yarn build
#
FROM base AS runner
WORKDIR /app
RUN apk add proxychains-ng
ENV PROXY_URL=""
ENV OPENAI_API_KEY=""
ENV GOOGLE_API_KEY=""
ENV CODE=""
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/.next/server ./.next/server
# 一个插件一直有问题。
COPY --from=deps /app/node_modules/tiktoken ./node_modules/tiktoken
#
#RUN apk add proxychains-ng
#
#ENV PROXY_URL=""
#ENV OPENAI_API_KEY=""
#ENV GOOGLE_API_KEY=""
#ENV CODE=""
#
#COPY --from=builder /app/public ./public
#COPY --from=builder /app/.next/standalone ./
#COPY --from=builder /app/.next/static ./.next/static
#COPY --from=builder /app/.next/server ./.next/server
#
## 一个插件一直有问题。
#COPY --from=deps /app/node_modules/tiktoken ./node_modules/tiktoken
COPY out/ .
RUN rm -f .env