-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
41 lines (30 loc) · 1.05 KB
/
Dockerfile
File metadata and controls
41 lines (30 loc) · 1.05 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
# --- Builder Stage ---
FROM golang:1.24-alpine AS builder
WORKDIR /app
# 预先复制 go.mod 和 go.sum 以利用 Docker 缓存
COPY go.mod go.sum ./
RUN go mod download
# 复制所有需要的源代码
# 我们需要 pkg 和 proto 因为它们是共享库
COPY pkg/ ./pkg/
COPY proto/ ./proto/
# 复制 core-service 的所有源代码
COPY core-service/ ./core-service/
# 编译应用,生成一个静态链接的二进制文件
# 构建路径现在指向 core-service 内部的 cmd/server
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /core-server ./core-service/cmd/server
# --- Final Stage ---
FROM alpine:latest
# 安装 ca-certificates 以支持 SSL/TLS
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# 从 builder 阶段复制编译好的二进制文件
COPY --from=builder /core-server .
# 复制配置文件
COPY core-service/configs/ ./configs/
# 暴露 HTTP 和 gRPC 端口
EXPOSE 8081
EXPOSE 50051
# 运行应用
# 运行时通过 -config 标志,明确指定容器内的配置路径
CMD ["./core-server", "-config", "./configs"]