大幅度优化打包速度

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

@ -39,7 +39,7 @@ jobs:
- name: Check out the repo - name: Check out the repo
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
clean: true clean: false
ref: 'dev' ref: 'dev'
- name: Set up SSH key - name: Set up SSH key
uses: webfactory/ssh-agent@v0.8.0 uses: webfactory/ssh-agent@v0.8.0

View File

@ -22,7 +22,7 @@ jobs:
- name: Check out the repo - name: Check out the repo
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
clean: true clean: false
- name: build and deploy to Docker Hub - name: build and deploy to Docker Hub
run: | run: |
echo ${{ secrets.ALY_DOCKER_PASSWORD }} | docker login registry.cn-hangzhou.aliyuncs.com -u ${{ secrets.ALY_DOCKER_USERNAME }} --password-stdin echo ${{ secrets.ALY_DOCKER_PASSWORD }} | docker login registry.cn-hangzhou.aliyuncs.com -u ${{ secrets.ALY_DOCKER_USERNAME }} --password-stdin

View File

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

82
Dockerfile.bak Normal file
View File

@ -0,0 +1,82 @@
#FROM registry.cn-hangzhou.aliyuncs.com/sijinhui/node:18-alpine AS base
FROM node:18-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
# 设置时区环境变量
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 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 rm -f .env
EXPOSE 3000
ENV KEEP_ALIVE_TIMEOUT=30
ENV HOSTNAME=""
CMD if [ -n "$PROXY_URL" ]; then \
export HOSTNAME="127.0.0.1"; \
protocol=$(echo $PROXY_URL | cut -d: -f1); \
host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
port=$(echo $PROXY_URL | cut -d: -f3); \
conf=/etc/proxychains.conf; \
echo "strict_chain" > $conf; \
echo "proxy_dns" >> $conf; \
echo "remote_dns_subnet 224" >> $conf; \
echo "tcp_read_time_out 15000" >> $conf; \
echo "tcp_connect_time_out 8000" >> $conf; \
echo "localnet 127.0.0.0/255.0.0.0" >> $conf; \
echo "localnet ::1/128" >> $conf; \
echo "[ProxyList]" >> $conf; \
echo "$protocol $host $port" >> $conf; \
cat /etc/proxychains.conf; \
proxychains -f $conf node server.js; \
else \
node server.js; \
fi