82 lines
3.4 KiB
Docker
82 lines
3.4 KiB
Docker
# 阶段1: 构建
|
||
FROM golang:alpine AS builder
|
||
|
||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||
apk add --no-cache git ca-certificates tzdata
|
||
|
||
ENV TZ=Asia/Shanghai
|
||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||
|
||
ENV GO111MODULE=on
|
||
ENV GOPROXY=https://goproxy.cn,direct
|
||
ENV CGO_ENABLED=0
|
||
ENV GOTOOLCHAIN=auto
|
||
WORKDIR /build
|
||
|
||
COPY . .
|
||
|
||
RUN go mod download && go mod tidy
|
||
|
||
RUN go build -ldflags="-s -w" -o main ./main.go
|
||
|
||
|
||
# 阶段2: 运行时(预装 FFmpeg + Python3 + PySceneDetect + Node.js + HyperFrames)
|
||
FROM alpine:3.21
|
||
|
||
# nodejs/npm 在 community 仓库,需启用
|
||
# 使用阿里云镜像加速
|
||
RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories \
|
||
&& echo "https://mirrors.aliyun.com/alpine/v3.21/community" >> /etc/apk/repositories \
|
||
&& apk add --no-cache ca-certificates tzdata ffmpeg python3 py3-pip nodejs npm \
|
||
gcc musl-dev python3-dev linux-headers
|
||
|
||
ENV TZ=Asia/Shanghai
|
||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||
|
||
# opencv-python 无 Alpine musllinux 预编译 wheel,改用 apk 的 py3-opencv
|
||
RUN apk add --no-cache py3-opencv
|
||
|
||
# 预装 PySceneDetect(--no-deps: scenedetect 强依赖 opencv-python 会触发源码编译)
|
||
# opencv 已由 apk 的 py3-opencv 提供,无需 pip 重复安装
|
||
# pip 24+ 扫描系统包元数据时崩溃(python-4.10.0 版本号无效)
|
||
# 用虚拟环境隔离
|
||
RUN python3 -m venv --system-site-packages /opt/venv \
|
||
&& /opt/venv/bin/pip install --no-deps -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com scenedetect \
|
||
&& /opt/venv/bin/pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com click platformdirs tqdm
|
||
ENV PATH=/opt/venv/bin:$PATH
|
||
|
||
# 验证 PySceneDetect 安装
|
||
RUN python3 -c "import scenedetect; print(f'scenedetect {scenedetect.__version__} installed')"
|
||
|
||
# 预装 HyperFrames(全局安装)
|
||
# 使用 npmmirror 镜像加速
|
||
# 禁用 hyperframes 自动更新:其后台 npm install 的 postinstall 会连 GitHub 下载二进制,
|
||
# 国内网络下挂死并阻塞后续 browser ensure(曾卡 1 小时+)
|
||
ENV HYPERFRAMES_NO_UPDATE_CHECK=1 \
|
||
HYPERFRAMES_NO_AUTO_INSTALL=1
|
||
RUN npm install -g hyperframes --ignore-scripts
|
||
|
||
# HyperFrames 渲染需要 Chromium/Chrome
|
||
# 安装 Chromium(提供系统级共享库依赖)和中文字体
|
||
RUN apk add --no-cache chromium font-noto-cjk fontconfig \
|
||
&& fc-cache -f
|
||
# HyperFrames 直接使用 Alpine 的系统 Chromium(musl 版),而不是下载 chrome-headless-shell。
|
||
# 原因:hyperframes 默认会下载 Google 官方 chrome-headless-shell(glibc 构建),
|
||
# 在 Alpine(musl libc)上无法加载:Error loading shared library
|
||
# ld-linux-x86-64.so.2: No such file or directory + symbol not found,
|
||
# 上层 puppeteer 表现为 spawn ENOENT,渲染直接失败。
|
||
# HYPERFRAMES_BROWSER_PATH 在 hyperframes 浏览器解析中优先级最高(env > 缓存 > 系统)。
|
||
# 注意:系统 Chromium 捕获会回退到 screenshot 模式(比 beginFrame 略慢,但功能正常)。
|
||
# hyperframes 升级若改变浏览器解析逻辑,需同步检查此配置。
|
||
ENV HYPERFRAMES_BROWSER_PATH=/usr/bin/chromium-browser
|
||
|
||
WORKDIR /app
|
||
|
||
# 复制二进制和运行时必需的文件
|
||
COPY --from=builder /build/main .
|
||
COPY --from=builder /build/config.yml .
|
||
COPY --from=builder /build/scripts ./scripts
|
||
EXPOSE 3010
|
||
|
||
CMD ["./main"]
|