物联网软件

This commit is contained in:
BBIT-Kai
2026-02-04 14:02:57 +08:00
parent 646e312a4c
commit 1c11f3f06c
28 changed files with 4526 additions and 271 deletions
+8 -32
View File
@@ -1,36 +1,12 @@
# ==========================
# Stage 1: Build the Go binary
# ==========================
FROM golang:1.21-alpine AS builder
FROM scratch
# 设置工作目录
WORKDIR /build
# 复制 go.mod 和 go.sum,先做依赖缓存
COPY go.mod go.sum ./
# 下载依赖(缓存层)
RUN go mod download
# 复制源代码
COPY app/ ./app
# 编译可执行文件
RUN go build -o sentinel ./app/main.go
# ==========================
# Stage 2: 生成最终运行镜像
# ==========================
FROM alpine:3.18
# 安装 ca-certificates,如果程序需要访问 HTTPS
RUN apk add --no-cache ca-certificates
# 设置工作目录
WORKDIR /app
# 复制从 builder 构建好的二进制
COPY --from=builder /build/sentinel .
# buildx 自动注入
ARG TARGETOS
ARG TARGETARCH
# 设置默认执行命令
CMD ["./sentinel"]
COPY build/release/${TARGETOS}_${TARGETARCH} /app
COPY ca-certificates.crt /etc/ssl/certs/
CMD ["./main"]