-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (37 loc) · 1.08 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 前端构建阶段
FROM node:22-alpine AS web-builder
WORKDIR /app/web
# 复制前端配置文件和源码
COPY web/package*.json ./
RUN npm install
COPY web/ ./
RUN npm run build
# 后端构建阶段
FROM golang:1.25-alpine AS go-builder
WORKDIR /app
# 安装依赖
RUN apk add --no-cache git
# 复制依赖文件
COPY go.mod go.sum ./
RUN go mod download
# 复制后端源代码
COPY . .
# 将前端构建产物复制到内嵌目录
COPY --from=web-builder /app/web/dist ./internal/static/dist
# 编译
ARG VERSION=dev
ARG BUILD_TIME=unknown
ARG COMMIT=unknown
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w -X modelgate/internal/version.Version=${VERSION} -X modelgate/internal/version.BuildTime=${BUILD_TIME} -X modelgate/internal/version.Commit=${COMMIT}" -o modelgate ./cmd/server
# 生产镜像
FROM alpine:latest
WORKDIR /app
# 安装 ca-certificates 用于 HTTPS
RUN apk --no-cache add ca-certificates
# 复制二进制文件和配置文件
COPY --from=go-builder /app/modelgate .
COPY config.yaml.example ./config.yaml
# 暴露端口
EXPOSE 8080
# 运行
CMD ["./modelgate"]