wd21 commited on
Commit
d9cdb03
·
verified ·
1 Parent(s): fbe6ce0

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -0
Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 构建阶段
2
+ FROM golang:1.21-alpine AS builder
3
+
4
+ WORKDIR /app
5
+
6
+ # 复制依赖文件并下载
7
+ COPY go.mod go.sum ./
8
+ RUN go mod download
9
+
10
+ # 复制所有源码并编译
11
+ COPY . .
12
+ RUN CGO_ENABLED=0 GOOS=linux go build -o /hdhive-test ./hdhive-api
13
+
14
+ # 运行阶段
15
+ FROM alpine:latest
16
+
17
+ # 创建非 root 用户(与 Hugging Face 的 UID 1000 匹配)
18
+ RUN adduser -D -u 1000 user && mkdir -p /app && chown -R user /app
19
+ USER user
20
+
21
+ WORKDIR /app
22
+
23
+ # 复制二进制
24
+ COPY --from=builder /hdhive-test /app/hdhive-test
25
+
26
+ # 暴露端口(与代码中监听端口一致,默认 8890)
27
+ EXPOSE 8890
28
+
29
+ # 启动
30
+ CMD ["/app/hdhive-test"]