mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-20 15:13:44 +08:00
- Add comprehensive npm mirror configuration for faster package downloads - Use parallel npm install and build processes for better performance - Configure Go proxy and Alpine package mirrors for network reliability - Fix frontend dependency issues that caused blank page display 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
70 lines
2.5 KiB
Docker
70 lines
2.5 KiB
Docker
FROM --platform=$BUILDPLATFORM node:16 AS builder
|
||
|
||
# 配置npm使用淘宝镜像源
|
||
RUN npm config set registry https://registry.npmmirror.com && \
|
||
npm config set disturl https://npmmirror.com/dist && \
|
||
npm config set sass_binary_site https://npmmirror.com/mirrors/node-sass/ && \
|
||
npm config set electron_mirror https://npmmirror.com/mirrors/electron/ && \
|
||
npm config set puppeteer_download_host https://npmmirror.com/mirrors && \
|
||
npm config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver && \
|
||
npm config set operadriver_cdnurl https://npmmirror.com/mirrors/operadriver && \
|
||
npm config set phantomjs_cdnurl https://npmmirror.com/mirrors/phantomjs && \
|
||
npm config set selenium_cdnurl https://npmmirror.com/mirrors/selenium && \
|
||
npm config set node_inspector_cdnurl https://npmmirror.com/mirrors/node-inspector
|
||
|
||
WORKDIR /web
|
||
COPY ./VERSION .
|
||
COPY ./web .
|
||
|
||
# 并行安装npm依赖,提高构建速度
|
||
RUN npm install --prefix /web/default --prefer-offline --no-audit & \
|
||
npm install --prefix /web/berry --prefer-offline --no-audit & \
|
||
npm install --prefix /web/air --prefer-offline --no-audit & \
|
||
wait
|
||
|
||
# 并行构建前端项目,提高构建速度
|
||
RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/default & \
|
||
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/berry & \
|
||
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/air & \
|
||
wait
|
||
|
||
FROM golang:alpine AS builder2
|
||
|
||
# 配置Go使用国内镜像源
|
||
ENV GOPROXY=https://goproxy.cn,direct \
|
||
GOSUMDB=sum.golang.google.cn \
|
||
GO111MODULE=on \
|
||
CGO_ENABLED=1 \
|
||
GOOS=linux
|
||
|
||
# 使用阿里云 Alpine 源以加速 apk 包安装
|
||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||
apk update && \
|
||
apk add --no-cache \
|
||
gcc \
|
||
musl-dev \
|
||
sqlite-dev \
|
||
build-base
|
||
|
||
WORKDIR /build
|
||
|
||
ADD go.mod go.sum ./
|
||
RUN go mod download
|
||
|
||
COPY . .
|
||
COPY --from=builder /web/build ./web/build
|
||
|
||
RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/common.Version=$(cat VERSION)' -linkmode external -extldflags '-static'" -o one-api
|
||
|
||
FROM alpine:latest
|
||
|
||
# 使用阿里云 Alpine 源以加速 apk 包安装
|
||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||
apk update && \
|
||
apk add --no-cache ca-certificates tzdata
|
||
|
||
COPY --from=builder2 /build/one-api /
|
||
|
||
EXPOSE 3000
|
||
WORKDIR /data
|
||
ENTRYPOINT ["/one-api"] |