修改依赖安装逻辑
This commit is contained in:
+34
@@ -19,6 +19,40 @@ 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.19
|
||||
|
||||
# 启用 community 仓库(nodejs/npm 在其中)
|
||||
RUN echo "https://dl-cdn.alpinelinux.org/alpine/v3.19/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
|
||||
|
||||
# 预装 PySceneDetect(opencv-headless 无需 GUI 依赖)
|
||||
RUN pip3 install --break-system-packages scenedetect[opencv-headless,ffmpeg]
|
||||
|
||||
# 预装 HyperFrames(全局安装)
|
||||
RUN npm install -g hyperframes
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制二进制和运行时必需的文件
|
||||
COPY --from=builder /build/main .
|
||||
COPY --from=builder /build/config.yml .
|
||||
COPY --from=builder /build/scripts ./scripts
|
||||
|
||||
EXPOSE 3010
|
||||
|
||||
CMD ["./main"]
|
||||
|
||||
@@ -59,6 +59,11 @@ func ensureFFmpeg(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if inContainer {
|
||||
g.Log().Fatalf(ctx, "[ffmpeg] ❌ 容器中未找到 ffmpeg,请在 Dockerfile 中预装: RUN apk add --no-cache ffmpeg")
|
||||
return
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "[ffmpeg] 未找到,尝试自动安装...")
|
||||
|
||||
switch runtime.GOOS {
|
||||
@@ -233,6 +238,11 @@ func ensureHyperFrames(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if inContainer {
|
||||
g.Log().Fatalf(ctx, "[hyperframes] ❌ 容器中未找到 hyperframes,请在 Dockerfile 中预装: RUN npm install -g hyperframes")
|
||||
return
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "[hyperframes] 未找到,尝试自动安装 (npm install -g hyperframes)...")
|
||||
installCmd := exec.Command("npm", "install", "-g", "hyperframes")
|
||||
output, err := installCmd.CombinedOutput()
|
||||
@@ -280,6 +290,10 @@ func ensurePython3(ctx context.Context) {
|
||||
// Python 2,不满足需求
|
||||
g.Log().Infof(ctx, "[python3] 检测到 python=%s, 需要 Python 3,尝试自动安装...", version)
|
||||
} else {
|
||||
if inContainer {
|
||||
g.Log().Fatalf(ctx, "[python3] ❌ 容器中未找到 python3,请在 Dockerfile 中预装: RUN apk add --no-cache python3 py3-pip")
|
||||
return
|
||||
}
|
||||
g.Log().Infof(ctx, "[python3] 未找到,尝试自动安装...")
|
||||
}
|
||||
|
||||
@@ -302,6 +316,11 @@ func ensureSceneDetect(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if inContainer {
|
||||
g.Log().Fatalf(ctx, "[scenedetect] ❌ 容器中未找到 scenedetect,请在 Dockerfile 中预装: RUN pip3 install --break-system-packages scenedetect[opencv-headless,ffmpeg]")
|
||||
return
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "[scenedetect] 未找到,尝试自动安装 (pip install scenedetect[opencv,ffmpeg])...")
|
||||
installCmd := exec.Command("pip3", "install", "scenedetect[opencv,ffmpeg]")
|
||||
output, err := installCmd.CombinedOutput()
|
||||
|
||||
Reference in New Issue
Block a user