Files
media/Dockerfile
T

58 lines
2.0 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 阶段1: 构建
FROM golang:alpine AS builder
RUN 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 重复安装
RUN pip3 install --break-system-packages --no-deps -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com scenedetect \
&& pip3 install --break-system-packages -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com click platformdirs tqdm
# 验证 PySceneDetect 安装
RUN python3 -c "import scenedetect; print(f'scenedetect {scenedetect.__version__} installed')"
# 预装 HyperFrames(全局安装)
# 使用 npmmirror 镜像加速
RUN npm install -g hyperframes --registry=https://registry.npmmirror.com/ --ignore-scripts
WORKDIR /app
# 复制二进制和运行时必需的文件
COPY --from=builder /build/main .
COPY --from=builder /build/config.yml .
EXPOSE 3010
CMD ["./main"]