| FROM node:18.19.0-alpine as react-builder |
|
|
| WORKDIR /app |
| RUN apk add --no-cache git |
| RUN wget -qO- -t1 -T2 "https://api.github.com/repos/ai365vip/chat-api/releases" | \ |
| grep "tag_name" | \ |
| head -n 1 | \ |
| awk -F ":" '{print $2}' | \ |
| sed 's/\"//g;s/,//g;s/ //g' > VERSION |
| RUN git clone https://github.com/ai365vip/chat-api.git chat-api |
| WORKDIR /app/chat-api |
| |
|
|
| |
| RUN npm ci --prefix web-user |
| RUN npm ci --prefix web-admin |
|
|
| |
| RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build --prefix web-user |
| RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build --prefix web-admin |
|
|
| FROM golang:latest AS go-builder |
|
|
| WORKDIR /build/chat-api |
| COPY --from=react-builder /app/chat-api . |
| RUN go mod download |
|
|
| |
| RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o chat-api |
|
|
| FROM alpine:latest |
|
|
| RUN apk update && apk add --no-cache ca-certificates tzdata && update-ca-certificates && rm -rf /var/cache/apk/* |
|
|
| |
| COPY --from=go-builder /build/chat-api/chat-api /chat-api |
| COPY --from=cloudflare/cloudflared:latest /usr/local/bin/cloudflared /usr/local/bin/cloudflared |
|
|
| EXPOSE 3000 |
|
|
| WORKDIR /data |
| RUN chmod 777 -R /data |
| ENTRYPOINT cloudflared tunnel --no-autoupdate run --token $CF_TOKEN & \ |
| /chat-api |