sanbo110 commited on
Commit
4034f5c
·
verified ·
1 Parent(s): 7000a10

update release files

Browse files
Files changed (1) hide show
  1. Dockerfile +6 -17
Dockerfile CHANGED
@@ -1,42 +1,31 @@
1
- # 构建阶段
2
  FROM golang:1.22-alpine AS builder
3
 
4
- # 设置工作目录
5
  WORKDIR /app
6
 
7
- # 为了减少Docker层数,先复制 go.mod 和 go.sum 并下载依赖
8
  COPY go.mod go.sum ./
9
  RUN go mod download
10
 
11
- # 复制源代码
12
  COPY . .
13
 
14
- # 编译Go应用,启用优化参数
15
- RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ddg .
16
 
17
- # 运行阶段
18
  FROM alpine:3.18
19
 
20
- # 设置工作目录
21
  WORKDIR /app
22
 
23
- # 将编译好的二进制文件从构建阶段复制过来
24
- COPY --from=builder /app/ddg .
25
 
26
- # 设置环境变量
27
  ENV MAX_RETRY_COUNT=3
28
  ENV RETRY_DELAY=5000
29
  ENV PORT=7860
 
30
 
31
- # 公开端口
32
  EXPOSE 7860
33
 
34
- # 确保二进制文件具有可执行权限
35
- RUN chmod +x ddg
36
 
37
- # 使用非 root 用户运行应用(增强安全性)
38
  RUN addgroup -S appgroup && adduser -S appuser -G appgroup
39
  USER appuser
40
 
41
- # 启动应用
42
- ENTRYPOINT ["./ddg"]
 
 
1
  FROM golang:1.22-alpine AS builder
2
 
 
3
  WORKDIR /app
4
 
5
+ RUN go mod tidy
6
  COPY go.mod go.sum ./
7
  RUN go mod download
8
 
 
9
  COPY . .
10
 
11
+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o x .
 
12
 
 
13
  FROM alpine:3.18
14
 
 
15
  WORKDIR /app
16
 
17
+ COPY --from=builder /app/x .
 
18
 
 
19
  ENV MAX_RETRY_COUNT=3
20
  ENV RETRY_DELAY=5000
21
  ENV PORT=7860
22
+ ENV GIN_MODE=release
23
 
 
24
  EXPOSE 7860
25
 
26
+ RUN chmod +x x
 
27
 
 
28
  RUN addgroup -S appgroup && adduser -S appuser -G appgroup
29
  USER appuser
30
 
31
+ ENTRYPOINT ["./x"]