diff --git a/Cargo.toml b/Cargo.toml index e0dd615..5b6d060 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,13 @@ tokio-util = { version = "0.7", features = ["io"] } [package.metadata.deb] depends = "$auto" +# plays suggested songs from YouTube. Distribution packages may be too old to work with YouTube, +# so it's only recommended: a current yt-dlp from elsewhere (e.g. pip) works too +recommends = "yt-dlp" assets = [ ["target/release/playlistd", "usr/bin/playlistd", "755"], + # the web UI; build it first with `npm --prefix discover ci && npm --prefix discover run build` + ["discover/dist/**/*", "usr/share/playlistd/discover/", "644"], ["etc/playlistd/playlistd.toml", "etc/playlistd/playlistd.toml", "600"], ["etc/playlistd/Rocket.toml", "etc/playlistd/Rocket.toml", "600"], ] diff --git a/Containerfile b/Containerfile index 6779759..a623f90 100644 --- a/Containerfile +++ b/Containerfile @@ -4,6 +4,17 @@ ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH -RUN apt update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y gcc gcc-multilib cmake pkg-config libssl-dev curl dpkg-dev +RUN apt update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y gcc gcc-multilib cmake pkg-config libssl-dev curl dpkg-dev xz-utils RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain nightly RUN cargo install cargo-deb + +# Node.js, to build the web UI (Ubuntu 22.04's is too old for Vite) +ARG NODE_VERSION=22.23.4 +RUN arch="$(dpkg --print-architecture | sed 's/amd64/x64/')" \ + && file="node-v${NODE_VERSION}-linux-${arch}.tar.xz" \ + && cd /tmp \ + && curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/${file}" \ + && curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/SHASUMS256.txt" | grep " ${file}\$" | sha256sum -c - \ + && tar -xJf "${file}" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "${file}" \ + && node --version diff --git a/README.md b/README.md index 04a482b..aef99b3 100644 --- a/README.md +++ b/README.md @@ -26,19 +26,25 @@ Build the image: podman build -t playlistd-22 -f Containerfile . ``` -Then build the `.deb`. The `sqlx` query macros check queries against a live, migrated database at -compile time, so the host's Postgres socket is mounted into the container. With rootless podman, the -container's root maps to your host user, so local peer authentication works without a password: +Then build the web UI and the `.deb`. The `sqlx` query macros check queries against a live, +migrated database at compile time, so the host's Postgres socket is mounted into the container. With +rootless podman, the container's root maps to your host user, so local peer authentication works +without a password: ```sh podman run --rm \ -v "$PWD":/mnt -w /mnt \ -v /var/run/postgresql:/var/run/postgresql \ -e DATABASE_URL='postgres://jude@%2Fvar%2Frun%2Fpostgresql/playlistd' \ - playlistd-22 cargo deb + playlistd-22 sh -c 'npm --prefix discover ci && npm --prefix discover run build && cargo deb' ``` -The package is written to `target/debian/`. +The package is written to `target/debian/`. It installs the web UI to `/usr/share/playlistd/discover`, +which the default config serves at `/`. `cargo deb` refuses to build the package if the UI hasn't been +built. + +The package recommends `yt-dlp`, for playing suggested songs from YouTube. Distribution packages of +yt-dlp are often too old to work with YouTube, so you may want a current one instead, e.g. from pip. ### Logging @@ -149,11 +155,12 @@ like a new song to keep it in "Liked new songs", or hide it so it isn't suggeste mix you've played recently) mixed in evenly, so that `familiar_ratio` of what you hear is familiar. If a mix has too few known songs to keep that ratio, all of them are used. -Build it with: +The `.deb` includes it (see [Container build](#container-build-ubuntu-2204)). To run it from a +checkout, build it with: ```sh cd discover -npm install +npm ci npm run build ``` diff --git a/etc/playlistd/playlistd.toml b/etc/playlistd/playlistd.toml index e12c5b3..94bfc6a 100644 --- a/etc/playlistd/playlistd.toml +++ b/etc/playlistd/playlistd.toml @@ -26,7 +26,7 @@ url = "postgres:///navidrome-playlists" [discover] # Directory with the built discover UI (discover/dist) to serve at / -# ui = "/usr/share/playlistd/discover" +ui = "/usr/share/playlistd/discover" # yt-dlp binary used to play suggested songs that aren't in your library # ytdlp = "yt-dlp" # Format to ask Subsonic to stream in ("raw" = no transcoding), e.g. "mp3" if your diff --git a/src/main.rs b/src/main.rs index dd4adef..f9c531d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,15 @@ async fn main() -> Result<(), Box> { // the discover UI's built files (discover/dist) if let Ok(ui) = CONFIG.get().unwrap().get::("discover.ui") { - server = server.mount("/", rocket::fs::FileServer::from(ui)); + // Rocket panics if the directory doesn't exist + if std::path::Path::new(&ui).is_dir() { + server = server.mount("/", rocket::fs::FileServer::from(ui)); + } else { + log::warn!( + "Not serving the web UI: {} doesn't exist. Build it with `npm run build` in discover/", + ui + ); + } } server.launch().await?;