Update Dockerfile

This commit is contained in:
xugo
2026-01-14 00:02:35 +08:00
parent c040dcf3d2
commit 4755fef630
3 changed files with 54 additions and 37 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
__pycache__/
*.yaml
*.pt
*.pt
webhook_openapi.yaml
+50 -36
View File
@@ -1,22 +1,51 @@
# 使用 Debian Bullseye 作为基础镜像,因为 ZLMediaKit 需要 libssl1.1
# ============================================
# 阶段 1: 构建 Python 依赖
# ============================================
FROM debian:trixie-slim AS python-builder
RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
pip3 config set global.trusted-host mirrors.aliyun.com
# 安装 Python 依赖到指定目录
# --no-deps: 避免安装 sympy 等可选依赖
# --only-binary :all:: 强制只安装预编译包
RUN pip3 install --no-cache-dir --break-system-packages --target=/python-packages --no-deps --only-binary :all: onnxruntime && \
pip3 install --no-cache-dir --break-system-packages --target=/python-packages --only-binary :all: \
grpcio \
opencv-python-headless \
numpy \
requests \
protobuf \
packaging \
coloredlogs \
flatbuffers
# ============================================
# 阶段 2: 最终运行镜像
# ============================================
FROM debian:trixie-slim
ENV TZ=Asia/Shanghai
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/opt/media/bin/analysis
ENV PYTHONPATH=/opt/media/bin/analysis:/python-packages
WORKDIR /opt/media/bin/
# 配置 apt 源使用阿里云镜像 (Trixie 使用新格式 sources.list.d/debian.sources)
# 配置 apt 源使用阿里云镜像加速
RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \
sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g; \
s|http://security.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list 2>/dev/null || true
# 安装运行时依赖
# - python3/pip: AI 分析模块
# - libgl1/libglib2.0-0: OpenCV 需要
# 注意:Trixie 没有 libssl1.1,需要从 Bullseye 仓库安装
# 安装运行时依赖(极简版)
# 注意:opencv-python-headless 不需要 libgl1,移除可节省 ~160MB
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
@@ -24,35 +53,23 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libgcc-s1 \
libssl3 \
python3 \
python3-pip \
libgl1 \
libglib2.0-0 \
wget \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# 从 Debian Bullseye 下载并安装 libssl1.1ZLMediaKit 需要)
RUN wget -q http://mirrors.aliyun.com/debian/pool/main/o/openssl/libssl1.1_1.1.1w-0+deb11u1_amd64.deb -O /tmp/libssl1.1_amd64.deb \
&& wget -q http://mirrors.aliyun.com/debian/pool/main/o/openssl/libssl1.1_1.1.1w-0+deb11u1_arm64.deb -O /tmp/libssl1.1_arm64.deb \
&& dpkg -i /tmp/libssl1.1_$(dpkg --print-architecture).deb || true \
&& rm -f /tmp/libssl1.1_*.deb
RUN ARCH=$(dpkg --print-architecture) && \
wget -q http://mirrors.aliyun.com/debian/pool/main/o/openssl/libssl1.1_1.1.1w-0+deb11u1_${ARCH}.deb -O /tmp/libssl1.1.deb && \
dpkg -i /tmp/libssl1.1.deb || true && \
rm -f /tmp/libssl1.1.deb && \
# 移除 wget(不再需要)
apt-get purge -y wget && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
# 配置 pip 使用阿里云镜像
RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ \
&& pip3 config set global.trusted-host mirrors.aliyun.com
# 安装 Python 依赖
# --break-system-packages: Debian Trixie 使用 PEP 668 保护系统 Python
# TFLite 支持:优先尝试 tflite-runtime,失败则用 ai-edge-litertGoogle 新包名)
COPY ./analysis/requirements.txt /tmp/requirements.txt
RUN pip3 install --no-cache-dir --break-system-packages -r /tmp/requirements.txt \
&& (pip3 install --no-cache-dir --break-system-packages \
-i https://pypi.org/simple/ tflite-runtime 2>/dev/null \
|| pip3 install --no-cache-dir --break-system-packages \
-i https://pypi.org/simple/ ai-edge-litert 2>/dev/null \
|| echo "TFLite runtime not available, will use ONNX only") \
&& rm /tmp/requirements.txt \
&& rm -rf /root/.cache/pip
# 从构建阶段复制 Python 包
COPY --from=python-builder /python-packages /python-packages
# 从外部镜像复制 ZLMediaKit 和 ffmpeg
COPY --from=zlmediakit/zlmediakit:master /opt/media/bin /opt/media/bin
@@ -60,18 +77,15 @@ COPY --from=mwader/static-ffmpeg:6.1 /ffmpeg /usr/local/bin/ffmpeg
COPY --from=mwader/static-ffmpeg:6.1 /ffprobe /usr/local/bin/ffprobe
# 复制应用文件
# 使用 TARGETARCH 自动识别目标架构(amd64 或 arm64
ARG TARGETARCH
ADD ./build/linux_${TARGETARCH}/bin ./gowvp
ADD ./www ./www
ADD ./analysis ./analysis
RUN mkdir -p configs
RUN ln -sf /usr/local/bin/ffmpeg /usr/bin/ffmpeg && \
chmod +x /usr/local/bin/ffmpeg
RUN ln -sf /usr/local/bin/ffmpeg /opt/media/bin/ffmpeg
RUN mkdir -p configs && \
ln -sf /usr/local/bin/ffmpeg /usr/bin/ffmpeg && \
chmod +x /usr/local/bin/ffmpeg && \
ln -sf /usr/local/bin/ffmpeg /opt/media/bin/ffmpeg
LABEL Name=gowvp \
Version=0.1.0 \
+2
View File
@@ -177,11 +177,13 @@ build/linux:
$(eval GOOS := linux)
$(eval dir := $(BUILD_DIR_ROOT)/$(GOOS)_$(GOARCH))
@make build/local GOOS=$(GOOS) GOARCH=$(GOARCH)
@upx $(dir)/bin
$(eval GOARCH := arm64)
$(eval GOOS := linux)
$(eval dir := $(BUILD_DIR_ROOT)/$(GOOS)_$(GOARCH))
@make build/local GOOS=$(GOOS) GOARCH=$(GOARCH)
@upx $(dir)/bin
## build/windows: 构建 windows 应用
.PHONY: build/windows