diff --git a/Dockerfile b/Dockerfile index 5919b5c7..4a48bdc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,28 @@ 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 . -RUN npm config set registry https://registry.npmmirror.com && \ - npm install --prefix /web/default --legacy-peer-deps --retry 5 & \ - npm install --prefix /web/berry --legacy-peer-deps --retry 5 & \ - npm install --prefix /web/air --legacy-peer-deps --retry 5 & \ +# 并行安装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 & \ @@ -17,22 +30,26 @@ RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run buil FROM golang:alpine AS builder2 -RUN apk add --no-cache \ +# 配置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 -ENV GO111MODULE=on \ - CGO_ENABLED=1 \ - GOOS=linux \ - GOPROXY=https://goproxy.cn,direct \ - GOSUMDB=off - WORKDIR /build ADD go.mod go.sum ./ -RUN go mod download -x +RUN go mod download COPY . . COPY --from=builder /web/build ./web/build @@ -41,7 +58,10 @@ RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/commo FROM alpine:latest -RUN apk add --no-cache ca-certificates tzdata +# 使用阿里云 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 /