heroo commited on
Commit
94155ea
·
verified ·
1 Parent(s): 461a437

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -23
Dockerfile CHANGED
@@ -1,45 +1,45 @@
1
- FROM node:16 as builder
2
 
3
- WORKDIR /build
4
- RUN git clone https://github.com/MartialBE/one-hub.git .
5
  RUN wget -qO- -t1 -T2 "https://api.github.com/repos/ai365vip/chat-api/releases" | \
6
  grep "tag_name" | \
7
  head -n 1 | \
8
  awk -F ":" '{print $2}' | \
9
  sed 's/\"//g;s/,//g;s/ //g' > VERSION
10
 
11
- RUN sed -i'' 's|router.Group("/v1|router.Group("/hf/v1|g' /build/router/relay-router.go
12
- RUN sed -i'' 's|HasPrefix(path, "/v1|HasPrefix(path, "/hf/v1|g' /build/relay/common.go
 
13
 
14
- WORKDIR /build/web
15
- RUN npm install
16
- RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ../VERSION) npm run build
17
 
18
- FROM golang AS builder2
 
 
19
 
20
- ENV GO111MODULE=on \
21
- CGO_ENABLED=1 \
22
- GOOS=linux
23
 
24
  WORKDIR /build
25
- COPY --from=builder /build .
26
  RUN go mod download
27
- RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api
28
-
29
- FROM alpine
30
 
31
- RUN apk update \
32
- && apk upgrade \
33
- && apk add --no-cache ca-certificates tzdata \
34
- && update-ca-certificates 2>/dev/null || true
35
 
36
- COPY --from=builder2 /build/one-api /
37
 
 
38
 
39
- COPY --from=builder2 /build/one-api /
 
40
  COPY --from=cloudflare/cloudflared:latest /usr/local/bin/cloudflared /usr/local/bin/cloudflared
 
41
  EXPOSE 3000
 
42
  WORKDIR /data
43
  RUN chmod 777 -R /data
44
  ENTRYPOINT cloudflared tunnel --no-autoupdate run --token $CF_TOKEN & \
45
- /one-api
 
1
+ FROM node:18.19.0-alpine as react-builder
2
 
3
+ WORKDIR /app
4
+ RUN git clone https://github.com/ai365vip/chat-api.git .
5
  RUN wget -qO- -t1 -T2 "https://api.github.com/repos/ai365vip/chat-api/releases" | \
6
  grep "tag_name" | \
7
  head -n 1 | \
8
  awk -F ":" '{print $2}' | \
9
  sed 's/\"//g;s/,//g;s/ //g' > VERSION
10
 
11
+ # 复制 web-user 和 web-admin 的 package.json 和 package-lock.json 到当前目录
12
+ COPY web-user/package.json web-user/package-lock.json ./web-user/
13
+ COPY web-admin/package.json web-admin/package-lock.json ./web-admin/
14
 
15
+ # web-user 和 web-admin 安装依赖项
16
+ RUN npm ci --prefix web-user
17
+ RUN npm ci --prefix web-admin
18
 
19
+ # 构建 web-user 和 web-admin 应用
20
+ RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build --prefix web-user
21
+ RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build --prefix web-admin
22
 
23
+ FROM golang:latest AS go-builder
 
 
24
 
25
  WORKDIR /build
26
+ COPY --from=react-builder /app .
27
  RUN go mod download
 
 
 
28
 
29
+ # 构建 Go 二进制文件
30
+ RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o chat-api
 
 
31
 
32
+ FROM alpine:latest
33
 
34
+ RUN apk update && apk add --no-cache ca-certificates tzdata && update-ca-certificates && rm -rf /var/cache/apk/*
35
 
36
+ # 复制 Go 二进制文件
37
+ COPY --from=go-builder /build/chat-api /chat-api
38
  COPY --from=cloudflare/cloudflared:latest /usr/local/bin/cloudflared /usr/local/bin/cloudflared
39
+
40
  EXPOSE 3000
41
+
42
  WORKDIR /data
43
  RUN chmod 777 -R /data
44
  ENTRYPOINT cloudflared tunnel --no-autoupdate run --token $CF_TOKEN & \
45
+ /chat-api