feat: 实现 ONNX Runtime CGO 绑定和 OCR/Math 推理逻辑
Build and Deploy / build (push) Failing after 2m23s
Build and Deploy / deploy (push) Has been skipped

This commit is contained in:
2026-07-16 21:14:34 +00:00
parent 5dacb61122
commit 7afefe5e9f
6 changed files with 1094 additions and 85 deletions
+22 -5
View File
@@ -1,22 +1,35 @@
# 构建阶段 - 使用 Debian 基础镜像
FROM golang:1.22-bookworm AS builder
# 安装 OpenCV 和编译工具
# 安装 OpenCV、ONNX Runtime 和编译工具
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libopencv-dev \
pkg-config \
wget \
&& rm -rf /var/lib/apt/lists/*
# 安装 ONNX Runtime
RUN wget -q https://github.com/microsoft/onnxruntime/releases/download/v1.16.3/onnxruntime-linux-x64-1.16.3.tgz \
&& tar -xzf onnxruntime-linux-x64-1.16.3.tgz \
&& mv onnxruntime-linux-x64-1.16.3 /usr/local/onnxruntime \
&& rm onnxruntime-linux-x64-1.16.3.tgz
ENV ONNXRUNTIME_DIR=/usr/local/onnxruntime
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
ENV CGO_ENABLED=1
WORKDIR /app
# 复制源代码
COPY . .
# 使用 pkg-config 获取 OpenCV 编译标志
RUN go mod download || true
RUN PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig CGO_ENABLED=1 go build -ldflags="-s -w" -o anticaptcha ./cmd/server
# 下载依赖
RUN go mod download
# 构建
RUN go build -ldflags="-s -w" -o anticaptcha ./cmd/server
# 运行阶段
FROM debian:bookworm-slim
@@ -31,6 +44,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libstdc++6 \
&& rm -rf /var/lib/apt/lists/*
# 复制 ONNX Runtime
COPY --from=builder /usr/local/onnxruntime/lib/libonnxruntime.so* /usr/lib/
WORKDIR /app
# 复制二进制文件和前端
@@ -42,7 +58,8 @@ RUN mkdir -p /app/data /app/models
ENV GIN_MODE=release
ENV TZ=Asia/Shanghai
ENV LD_LIBRARY_PATH=/usr/lib
EXPOSE 6688
CMD ["./anticaptcha"]
CMD ["./anticaptcha"]