librespot schreibt die 'Browse to:'-URL mit println! auf stdout, das direkt in die ffmpeg-Pipe geht – die URL war dadurch nie im Log sichtbar, und ffmpeg erhielt Text statt PCM (Absturz-Schleife). Fix: println! → eprintln! im librespot-Quellcode-Patch, sodass die URL auf stderr landet und im HA-Log erscheint. Außerdem: Patch-Verifikation schlägt jetzt mit exit 1 fehl statt stillschweigend weiterzumachen (|| true → || exit 1). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83 lines
3.4 KiB
Docker
83 lines
3.4 KiB
Docker
ARG BUILD_FROM
|
|
|
|
# ============================================================
|
|
# Build stage: Librespot aus Rust-Quellcode kompilieren
|
|
# ============================================================
|
|
FROM rust:alpine AS librespot-builder
|
|
|
|
RUN apk add --no-cache \
|
|
musl-dev \
|
|
pkgconfig \
|
|
openssl-dev \
|
|
openssl-libs-static \
|
|
git
|
|
|
|
# Librespot aus dem Git-Tag klonen, patchen und kompilieren.
|
|
#
|
|
# Patch: OAuth-Server bindet an 0.0.0.0 statt 127.0.0.1.
|
|
# Standard: 127.0.0.1 → nur vom HA-Host selbst erreichbar.
|
|
# Mit 0.0.0.0 → der OAuth-Flow ist im Browser aus dem Heimnetz zugänglich.
|
|
#
|
|
# --locked: verwendet das originale Cargo.lock aus dem Tag (pinnt vergen-gitcl
|
|
# auf 0.x und vermeidet so den vergen_lib Versionskonflikt mit 9.x).
|
|
RUN git clone --depth 1 --branch v0.7.0 \
|
|
https://github.com/librespot-org/librespot.git /build && \
|
|
cd /build && \
|
|
# OAuth-Server auf allen Interfaces binden (statt nur 127.0.0.1).
|
|
# get_authcode_listener() bestimmt die Bind-Adresse aus dem redirect_uri-Parameter.
|
|
# Wir patchen den TcpListener::bind-Aufruf direkt, sodass er immer an 0.0.0.0
|
|
# bindet (mit dem gleichen Port wie im redirect_uri angegeben).
|
|
# Außerdem ersetzen wir die englische Browser-Meldung durch eine deutsche.
|
|
# Patch 1: "Browse to:"-URL auf stderr statt stdout.
|
|
# librespot schreibt die URL mit println! auf stdout, das in die ffmpeg-Pipe geht.
|
|
# eprintln! leitet auf stderr um → erscheint im HA-Log, nicht in ffmpeg.
|
|
sed -i \
|
|
-e 's/println!("Browse to: {auth_url}")/eprintln!("Browse to: {auth_url}")/' \
|
|
-e 's/println!("Provide redirect URL")/eprintln!("Provide redirect URL")/' \
|
|
oauth/src/lib.rs && \
|
|
grep -n "eprintln.*Browse to" oauth/src/lib.rs || { echo "FEHLER: println→eprintln Patch fehlgeschlagen!"; exit 1; } && \
|
|
# Patch 2: OAuth-Callback-Server auf 0.0.0.0 binden (statt nur 127.0.0.1).
|
|
# Damit ist der Callback aus dem Heimnetz erreichbar.
|
|
sed -i \
|
|
-e 's/TcpListener::bind(socket_address)/TcpListener::bind(std::net::SocketAddrV4::new(std::net::Ipv4Addr::UNSPECIFIED, socket_address.port()))/' \
|
|
-e 's/Go back to your terminal :)/Autorisierung erfolgreich! Du kannst diesen Tab schliessen./' \
|
|
oauth/src/lib.rs && \
|
|
grep -n "UNSPECIFIED" oauth/src/lib.rs || { echo "FEHLER: TcpListener-Patch fehlgeschlagen!"; exit 1; } && \
|
|
cargo build \
|
|
--release \
|
|
--locked \
|
|
--no-default-features \
|
|
--features "native-tls" && \
|
|
mkdir -p /install/bin && \
|
|
cp target/release/librespot /install/bin/librespot
|
|
|
|
# ============================================================
|
|
# Runtime stage: HA-Basis-Image + ffmpeg + icecast
|
|
# ============================================================
|
|
FROM ${BUILD_FROM}
|
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
|
|
# Abhängigkeiten installieren
|
|
# icecast liegt in Alpine's Community-Repository
|
|
RUN apk add --no-cache \
|
|
bash \
|
|
jq \
|
|
curl \
|
|
python3 \
|
|
ffmpeg \
|
|
&& apk add --no-cache \
|
|
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
|
|
icecast \
|
|
|| apk add --no-cache icecast
|
|
|
|
# Librespot-Binary aus dem Build-Stage übernehmen
|
|
COPY --from=librespot-builder /install/bin/librespot /usr/local/bin/librespot
|
|
RUN chmod +x /usr/local/bin/librespot
|
|
|
|
# Add-on Dateien kopieren
|
|
COPY run.sh /run.sh
|
|
RUN chmod a+x /run.sh
|
|
|
|
CMD ["/run.sh"]
|