物联网软件

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"]
+4
View File
@@ -30,6 +30,10 @@ func main() {
uploadFile(record.LicensePlateImage, record.VehicleImage)
// 2. 调用分析请求
analytics(record)
<-make(chan struct{})
//fatal error: all goroutines are asleep - deadlock!
}
func loadData(deviceID string) model.Record {
+40
View File
@@ -0,0 +1,40 @@
# build_all.ps1
# 一键打包 main 和 updater,三平台: Windows 64, Linux amd64, Linux arm64
# -------------------------
# 项目根目录
$RootDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
Set-Location $RootDir
# -------------------------
# 定义要打包的平台
$targets = @(
@{ OS="windows"; ARCH="amd64"; Dir="build/release/win"; MainOut="main.exe"; },
@{ OS="linux"; ARCH="amd64"; Dir="build/release/linux_amd64"; MainOut="main"; },
@{ OS="linux"; ARCH="arm64"; Dir="build/release/linux_arm64"; MainOut="main"; }
)
# -------------------------
# 循环打包
foreach ($t in $targets) {
Write-Host "=== Build $($t.OS)-$($t.ARCH) Version ==="
# 设置环境变量
$env:GOOS = $t.OS
$env:GOARCH = $t.ARCH
$env:CGO_ENABLED = "0"
# 创建输出目录
if (!(Test-Path $t.Dir)) {
New-Item -ItemType Directory -Path $t.Dir | Out-Null
}
# 编译 main
Write-Host "Building main..."
go build -ldflags="-s -w" -o "$($t.Dir)/$($t.MainOut)" ./app
Write-Host "$($t.OS)-$($t.ARCH) Build complete, Output dir: $($t.Dir)"
Write-Host ""
}
Write-Host "All builds finished."
File diff suppressed because it is too large Load Diff
+27
View File
@@ -0,0 +1,27 @@
# -----------------------------
# 版本号
# -----------------------------
$env:VERSION = "0.0.1"
# 仓库与镜像名
$IMAGE = "ai.ronsunny.cn:13011/bbit_iot/ce_sentinel"
# -----------------------------
# 确保 buildx builder 存在
# -----------------------------
docker buildx inspect multiarch-builder > $null 2>&1
if ($LASTEXITCODE -ne 0) {
docker buildx create --name multiarch-builder --use
} else {
docker buildx use multiarch-builder
}
# -----------------------------
# 构建 + 推送 多架构镜像
# -----------------------------
docker buildx build `
--platform linux/amd64,linux/arm64 `
-t ${IMAGE}:$env:VERSION `
-t ${IMAGE}:latest `
--push `
.