diff --git a/infra/librespot/Dockerfile b/infra/librespot/Dockerfile index 47708f2..cea1edc 100644 --- a/infra/librespot/Dockerfile +++ b/infra/librespot/Dockerfile @@ -1,51 +1,43 @@ # Librespot (Spotify Connect) for ARM64 -# Multi-stage: cross-compile Rust app on x86_64 builder, ship slim runtime. -# Audio output: PulseAudio (connect to audio-bridge via TCP localhost:4713). +# Multi-stage Docker build. Run on ARM64 host (RPi 3B+ etc). +# Audio output: PulseAudio (connects to audio-bridge via TCP localhost:4713). FROM rust:1.85.1-bookworm AS builder -# Cross-compile toolchain for aarch64 -RUN rustup target add aarch64-unknown-linux-gnu -RUN dpkg --add-architecture arm64 \ - && apt-get update \ +RUN apt-get update \ && apt-get install -y --no-install-recommends \ - gcc-aarch64-linux-gnu \ - libpulse-dev:arm64 \ - libasound2-dev:arm64 \ - libssl-dev:arm64 \ + libpulse-dev \ + libasound2-dev \ && rm -rf /var/lib/apt/lists/* -# Build librespot. Pin to a known tag. ARG LIBRESPOT_VERSION=v0.8.0 RUN git clone --depth 1 --branch ${LIBRESPOT_VERSION} \ https://github.com/librespot-org/librespot.git /src WORKDIR /src -ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc -RUN cargo build --release --target aarch64-unknown-linux-gnu --no-default-features --features="pulseaudio-backend" + +# Limit parallelism to 2 (RPi 3B+ has 4 cores but only 1GB RAM). +# Lower = less memory pressure, slower build. Higher = OOM risk. +RUN cargo build --release --jobs 2 \ + --no-default-features \ + --features="pulseaudio-backend" FROM debian:bookworm-slim -RUN dpkg --add-architecture arm64 \ - && apt-get update \ +RUN apt-get update \ && apt-get install -y --no-install-recommends \ ca-certificates \ - libpulse0:arm64 \ - libasound2:arm64 \ - libssl3:arm64 \ + libpulse0 \ + libasound2 \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder /src/target/aarch64-unknown-linux-gnu/release/librespot /usr/local/bin/librespot +COPY --from=builder /src/target/release/librespot /usr/local/bin/librespot -# Cache dir for Spotify credentials VOLUME ["/var/cache/librespot"] - -# PulseAudio bridge is at localhost:4713 (audio-bridge) ENV PULSE_SERVER=tcp:127.0.0.1:4713 CMD ["librespot", \ "--name", "Klubhaus", \ "--backend", "pulseaudio", \ - "--device", "alsa_output.default", \ "--bitrate", "320", \ "--enable-audio-cache", \ "--cache", "/var/cache/librespot"]