Spaces:
Running
Running
Create Dockerfile
Browse files- Dockerfile +38 -0
Dockerfile
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 构建阶段
|
2 |
+
FROM golang:1.24-alpine AS builder
|
3 |
+
|
4 |
+
# 设置Go环境变量
|
5 |
+
ENV GOPROXY=https://goproxy.cn,direct
|
6 |
+
ENV GO111MODULE=on
|
7 |
+
ENV CGO_ENABLED=0
|
8 |
+
|
9 |
+
# 安装 git
|
10 |
+
RUN apk add --no-cache git
|
11 |
+
|
12 |
+
WORKDIR /app
|
13 |
+
|
14 |
+
# 克隆源代码
|
15 |
+
RUN git clone --depth 1 https://github.com/coderZoe/scira2api.git .
|
16 |
+
|
17 |
+
# 下载 Go 模块依赖
|
18 |
+
RUN go mod download
|
19 |
+
|
20 |
+
# 编译应用
|
21 |
+
RUN GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o scira2api .
|
22 |
+
|
23 |
+
# --- 运行阶段 ---
|
24 |
+
FROM alpine:3.18
|
25 |
+
|
26 |
+
# 安装核心运行时依赖
|
27 |
+
RUN apk --no-cache add ca-certificates
|
28 |
+
|
29 |
+
WORKDIR /app
|
30 |
+
|
31 |
+
# 从构建阶段复制编译好的二进制文件
|
32 |
+
COPY --from=builder /app/scira2api .
|
33 |
+
|
34 |
+
# 暴露端口
|
35 |
+
EXPOSE 8080
|
36 |
+
|
37 |
+
# 启动命令
|
38 |
+
CMD ["./scira2api"]
|