bohesocool commited on
Commit
91bda2b
·
verified ·
1 Parent(s): cb123ca

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -0
Dockerfile ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用golang官方镜像作为构建环境
2
+ FROM golang:1.21-alpine AS builder
3
+
4
+ # 安装git和必要的工具
5
+ RUN apk add --no-cache git
6
+
7
+ # 设置工作目录
8
+ WORKDIR /app
9
+
10
+ # 克隆项目代码(请替换为您的git仓库地址)
11
+ RUN git clone https://github.com/bohesocool/you2api.git .
12
+
13
+ # 下载依赖
14
+ RUN go mod download
15
+
16
+ # 构建应用
17
+ RUN CGO_ENABLED=0 GOOS=linux go build -o main ./api
18
+
19
+ # 使用轻量级的alpine作为运行环境
20
+ FROM alpine:latest
21
+
22
+ # 安装必要的CA证书(用于HTTPS请求)
23
+ RUN apk --no-cache add ca-certificates
24
+
25
+ WORKDIR /root/
26
+
27
+ # 从构建阶段复制编译好的程序
28
+ COPY --from=builder /app/main .
29
+
30
+ # 暴露端口(Hugging Face Spaces 使用 7860 端口)
31
+ EXPOSE 7860
32
+
33
+ # 设置环境变量
34
+ ENV PORT=7860
35
+
36
+ # 运行程序
37
+ CMD ["./main"]