kylinpoet commited on
Commit
9f3fe57
·
verified ·
1 Parent(s): eaf2111

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +45 -0
Dockerfile ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用官方 Golang 镜像作为构建环境
2
+ FROM golang:1.23-alpine AS builder
3
+
4
+ # 设置工作目录
5
+ WORKDIR /app
6
+
7
+ # 复制 go.mod 和 go.sum 文件
8
+ COPY go.mod go.sum ./
9
+
10
+ # 下载依赖
11
+ RUN go mod download
12
+
13
+ # 复制源代码
14
+ COPY . .
15
+
16
+ # 构建应用
17
+ RUN CGO_ENABLED=0 GOOS=linux go build -o augment2api
18
+
19
+ # 使用轻量级的 alpine 镜像
20
+ FROM alpine:latest
21
+
22
+ # 安装 ca-certificates 以支持 HTTPS
23
+ RUN apk --no-cache add ca-certificates tzdata
24
+
25
+ # 创建非 root 用户
26
+ RUN adduser -D -g '' appuser
27
+
28
+ # 从构建阶段复制二进制文件
29
+ COPY --from=builder /app/augment2api /app/augment2api
30
+
31
+ # 复制静态文件和模板
32
+ COPY --from=builder /app/templates /app/templates
33
+
34
+ # 设置工作目录
35
+ WORKDIR /app
36
+
37
+ # 使用非 root 用户运行
38
+ USER appuser
39
+
40
+ # 暴露端口
41
+ EXPOSE 27080
42
+
43
+
44
+ # 运行应用
45
+ CMD ["/app/augment2api"]