Files
tuliprox/docker/Dockerfile-cross
T
euzuandGitHub fc0f1f32aa Enhanced Metadata Resolution, Stream Analysis & Improved STRM-Output. Added connection priority management.
**Description:**
This PR introduces a major overhaul of how streams are analyzed and connections are managed. It integrates `ffprobe` for deep stream analysis, adds a background task queue for metadata resolution to prevent UI blocking, introduces a connection priority system, and adds support for Live TV probing.

### 🚀 Key Features

*   **FFprobe Integration & Live TV Probing**:
    *   Automatically probes streams (VOD/Series **and now Live TV**) to determine resolution, codecs (HEVC/AV1), dynamic range (HDR/DV), bit depth, and audio channels.
    *   **Safe Probing**: Probing strictly respects the provider's `max_connections` limit.
    *   Docker images now include static `ffmpeg/ffprobe` binaries.

*   **Smart Connection Management (Priority System)**:
    *   Introduced a priority system for connections to manage provider limits intelligently.
    *   **Preemption**: Users with higher priority can preempt (kick) lower priority connections when provider slots are full.
    *   **Background Queue**: Metadata resolution and stream analysis run as background tasks (Priority 0). They only run when connection slots are idle and yield immediately if a real user needs to stream.

*   **Enhanced Metadata Resolution**:
    *   **Fallback Logic**: If a provider is missing the TMDB ID or Release Date, the system resolves them via the TMDB API.
    *   **Smart Title Cleaning**: Implemented a centralized cleaner to strip common IPTV prefixes before attempting metadata matches or generating filenames, significantly improving match rates.

*   **Improved Output**:
    *   **Quality Tags**: Filenames in STRM files now include detailed tags (e.g., `Movie - [4K HEVC HDR].strm`).
    *   **Flat Grouping**: `flat: true` now correctly groups multi-version movies into single folders based on TMDB ID.
    *   **Global Series Date**: Ensures consistent series folder naming even if episodes have different years.
2026-02-12 15:06:57 +01:00

243 lines
8.6 KiB
Plaintext

# =================================================================
#
# Part 1: Prerequisite Build Stages
#
# These stages are used as building blocks for the final images.
# They prepare the Rust binary and other resources.
#
# =================================================================
# -----------------------------------------------------------------
# Stage 0: Fetch static FFmpeg binaries
# -----------------------------------------------------------------
# We use a static build to ensure it works in the scratch image without libraries
# Static ffmpeg image is multi-arch, so it pulls correct arch automatically
FROM mwader/static-ffmpeg:7.1 AS ffmpeg-static
# -----------------------------------------------------------------
# Stage 1: Build the Rust binary for production
# -----------------------------------------------------------------
FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:main AS rust-build
# Get target architecture
ARG RUST_TARGET
RUN apt-get update && apt-get install -y --no-install-recommends pkg-config musl-tools libssl-dev
# Update Rust toolchain and add necessary target
RUN rustup update && rustup target add $RUST_TARGET
# Set Rust compiler flags for better optimization and reproducibility
ENV RUSTFLAGS='--remap-path-prefix $HOME=~ -C target-feature=+crt-static'
# Copy dependency files first for better layer caching
WORKDIR /src
COPY Cargo.toml Cargo.lock ./
COPY backend/Cargo.toml ./backend/
COPY frontend/Cargo.toml ./frontend/
COPY shared/Cargo.toml ./shared/
# Create dummy source files to build dependencies only
RUN mkdir -p src backend/src frontend/src shared/src && \
echo "fn main() {}" > src/main.rs && \
echo "fn main() {}" > backend/src/main.rs && \
echo "fn main() {}" > frontend/src/main.rs && \
echo "pub fn dummy() {}" > shared/src/lib.rs
# Build dependencies (this layer will be cached unless dependencies change)
RUN cargo build -p tuliprox --target $RUST_TARGET --release || true
RUN cargo build -p shared --target $RUST_TARGET --release || true
# Now copy the actual source code and build the project
COPY . .
RUN cargo build -p tuliprox --target $RUST_TARGET --release
# -----------------------------------------------------------------
# Stage 2: Build the rust frontend
# -----------------------------------------------------------------
FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:main AS trunk-build
ARG RUST_TARGET=wasm32-unknown-unknown
# Set working directory
WORKDIR /src
# Install dependencies for Trunk and WebAssembly
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl-dev curl libclang-dev binaryen
# Add wasm target & install trunk
RUN rustup target add wasm32-unknown-unknown
RUN cargo install --locked trunk wasm-bindgen-cli
# Copy dependency files first for better layer caching
COPY Cargo.toml Cargo.lock ./
COPY frontend/Cargo.toml frontend/Trunk.toml ./frontend/
COPY shared/Cargo.toml ./shared/
# Create dummy source files
RUN mkdir -p frontend/src shared/src && \
echo "fn main() {}" > frontend/src/main.rs && \
echo "pub fn dummy() {}" > shared/src/lib.rs
# Pre-build dependencies
WORKDIR /src/frontend
RUN cargo build --target wasm32-unknown-unknown --release || true
# Now copy the actual source code and build the project
WORKDIR /src
COPY . .
WORKDIR /src/frontend
# Run Trunk build
RUN trunk build --release
# -----------------------------------------------------------------
# Stage 3: Build video resources with ffmpeg
# -----------------------------------------------------------------
FROM linuxserver/ffmpeg:latest AS resource-build
WORKDIR /src
COPY resources ./resources
# Combine ffmpeg commands into a single layer to reduce image size
RUN ffmpeg -loop 1 -i ./resources/channel_unavailable.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/channel_unavailable.ts && \
ffmpeg -loop 1 -i ./resources/user_connections_exhausted.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/user_connections_exhausted.ts && \
ffmpeg -loop 1 -i ./resources/provider_connections_exhausted.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/provider_connections_exhausted.ts && \
ffmpeg -loop 1 -i ./resources/user_account_expired.jpg -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/user_account_expired.ts && \
ffmpeg -loop 1 -i ./resources/panel_api_provisioning.ppm -t 10 -r 1 -an \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
./resources/panel_api_provisioning.ts
# -----------------------------------------------------------------
# Stage 4: Prepare timezone data
# -----------------------------------------------------------------
FROM alpine:latest AS tz-prep
ARG TZ=UTC
ENV TZ=${TZ}
RUN apk add --no-cache tzdata \
&& mkdir -p /output/etc \
&& mkdir -p /output/usr/share \
&& cp -r /usr/share/zoneinfo /output/usr/share/zoneinfo \
&& ln -sf /usr/share/zoneinfo/${TZ} /output/etc/localtime
# =================================================================
#
# Part 2: Final Image Stages
#
# These stages build the final, runnable images by assembling
# the artifacts from the prerequisite stages above.
#
# =================================================================
# -----------------------------------------------------------------
# Final Image #1: Debugging Environment (Alpine-based)
# -----------------------------------------------------------------
FROM rust:alpine AS debug
# For Alpine, the correct target architecture uses 'musl'
ARG RUST_TARGET=x86_64-unknown-linux-musl
ARG TZ=UTC
# Make the build-time argument available as a run-time environment variable
ENV RUST_TARGET=${RUST_TARGET}
ENV TZ=${TZ}
# Install build dependencies and the lldb debugger for Alpine
# Added 'perl' which is required to build the native OpenSSL library.
# Added ffmpeg for probing
RUN apk add --no-cache bash build-base openssl-dev lldb gdb perl ffmpeg
# Update Rust toolchain and add the necessary target
RUN rustup update && rustup target add $RUST_TARGET
# Create the final application layout to mimic production
WORKDIR /app
COPY --from=trunk-build /src/frontend/dist ./web
COPY --from=resource-build /src/resources ./resources
# Create a separate directory for the source code
WORKDIR /usr/src/tuliprox
COPY . .
# Copy the entrypoint script and set it as the entrypoint for the container.
COPY ./docker/debug/debug-entrypoint.sh /usr/local/bin/entrypoint.sh
# Ensure the script is executable
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# The CMD will be passed as arguments to the entrypoint script.
CMD ["tail", "-f", "/dev/null"]
# -----------------------------------------------------------------
# Final Image #2: Production image based on scratch
# -----------------------------------------------------------------
FROM scratch AS scratch-final
ARG RUST_TARGET
# Copy timezone data and localtime from tz-prep
COPY --from=tz-prep /output/usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=tz-prep /output/etc/localtime /etc/localtime
# Certificates
COPY --from=rust-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy static ffmpeg/ffprobe binaries
COPY --from=ffmpeg-static /ffmpeg /usr/local/bin/
COPY --from=ffmpeg-static /ffprobe /usr/local/bin/
# RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
# App
WORKDIR /app
COPY --from=rust-build /src/target/${RUST_TARGET}/release/tuliprox ./tuliprox
COPY --from=trunk-build /src/frontend/dist ./web
COPY --from=resource-build /src/resources ./resources
ENTRYPOINT ["/app/tuliprox"]
CMD ["-s", "-p", "/app/config"]
# -----------------------------------------------------------------
# Final Image #3: Production image based on Alpine
# -----------------------------------------------------------------
FROM alpine:latest AS alpine-final
ARG RUST_TARGET
ARG TZ=UTC
ENV TZ=${TZ}
# Install dependencies including ffmpeg
RUN apk add --no-cache bash curl ca-certificates tini ffmpeg
COPY --from=rust-build /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=rust-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Default timezone fallback
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
WORKDIR /app
COPY --from=rust-build /src/target/${RUST_TARGET}/release/tuliprox ./tuliprox
COPY --from=trunk-build /src/frontend/dist ./web
COPY --from=resource-build /src/resources ./resources
ENTRYPOINT ["/sbin/tini", "--", "/app/tuliprox"]
CMD ["-s", "-p", "/app/config"]