FROM debian:bookworm-slim AS builder MAINTAINER Wizardry and Steamworks (wizardry.steamworks@outlook.com) # Install build dependencies + Clang & LLVM Polly RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl jq git cmake autoconf autogen automake bison build-essential \ flex libcppunit-dev libcurl4-openssl-dev libelf-dev libncurses-dev \ libsigc++-2.0-dev libssl-dev libtool zlib1g-dev pkg-config \ pkgconf libxmlrpc-c++8-dev nlohmann-json3-dev lld \ clang-14 llvm-14 libpolly-14-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /tmp/kitchen # Build jesec/libtorrent with ARM Cortex-A76/A55 target profiles # CXXFLAGS optimization lowers background memory footprint for the Orange Pi 5 SoC RUN git clone --depth 1 https://github.com/jesec/libtorrent.git && \ cd libtorrent && \ export CC=clang-14 CXX=clang++-14 && \ cmake . -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_FLAGS="-O3 -march=armv8.2-a+crypto+fp16+rcpc+dotprod -mtune=cortex-a76 -flto=thin -fno-plt -mllvm -polly -mllvm -polly-vectorizer=polly" \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld" && \ make -j$(nproc) && \ make install # Build jesec/rtorrent with link-time optimization (LTO) RUN git clone --depth 1 https://github.com/jesec/rtorrent.git && \ cd rtorrent && \ export CC=clang-14 CXX=clang++-14 && \ cmake . -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_FLAGS="-O3 -march=armv8.2-a+crypto+fp16+rcpc+dotprod -mtune=cortex-a76 -flto=thin -fno-plt -mllvm -polly -mllvm -polly-vectorizer=polly" \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld" && \ make -j$(nproc) && \ make install # Strip binaries to minimize internal footprint and save memory pages RUN strip /usr/local/bin/rtorrent # Platform-aware download logic for ttyd ARG TARGETARCH RUN ARCH_PATTERN=$([ "$TARGETARCH" = "arm64" ] || [ "$(uname -m)" = "aarch64" ] && echo "aarch64" || echo "x86_64") && \ curl -sL "https://api.github.com/repos/tsl0922/ttyd/releases/latest" | \ jq -r --arg arch "$ARCH_PATTERN" '.assets[] | select (.name | contains($arch)) | .browser_download_url' | \ xargs curl -sLo /usr/local/bin/ttyd && chmod +x /usr/local/bin/ttyd # ============================================================================== # STAGE 2: Hardened Runtime (Minimal Footprint) # ============================================================================== FROM debian:bookworm-slim # Install only the slim runtime packages (Includes libjemalloc2) RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ tini \ tmux \ nginx \ locales \ libcurl4 \ libsigc++-2.0-0v5 \ libssl3 \ libxmlrpc-c++8v5 \ ncurses-base \ zlib1g \ libncursesw6 \ curl \ libjemalloc2 \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Clean system language profiles RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ locale-gen ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 # Copy optimized binaries and dependencies from builder stage COPY --from=builder /usr/local/bin/rtorrent /usr/local/bin/rtorrent COPY --from=builder /usr/local/bin/ttyd /usr/local/bin/ttyd COPY --from=builder /usr/local/lib/libtorrent* /usr/local/lib/ RUN ldconfig # Initialize app architecture paths RUN mkdir -p /var/lib/rtorrent/downloads /var/lib/rtorrent/watch /var/lib/rtorrent/.session # Persistent storage mapping to protect tracking structures across restarts VOLUME ["/var/lib/rtorrent/downloads", "/var/lib/rtorrent/watch", "/var/lib/rtorrent/.session"] EXPOSE 62296 62298 7681 ADD rootfs / RUN chmod +x /usr/local/bin/run # Use tini to monitor processes natively ENTRYPOINT [ "tini", "-g", "--" ] CMD [ "/bin/sh", "-c", "/usr/local/bin/run" ]