diff --git a/Cargo.toml b/Cargo.toml index d1ebad4b..7e68914a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,7 +93,7 @@ toml = "0.8.19" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [features] -default = ["net4mqtt"] +webui = ["liveion/webui", "liveman/webui"] net4mqtt = ["liveion/net4mqtt", "liveman/net4mqtt"] # cargo install cargo-deb diff --git a/docker/Dockerfile.live777 b/docker/Dockerfile.live777 index 49463be1..aa0f1aa0 100644 --- a/docker/Dockerfile.live777 +++ b/docker/Dockerfile.live777 @@ -1,4 +1,4 @@ -FROM rust:slim-bookworm as builder +FROM rust:slim-bookworm AS builder WORKDIR /app @@ -10,15 +10,9 @@ RUN npm install && npm run build RUN cargo build --release -RUN cargo build --package=whipinto --release -RUN cargo build --package=whepfrom --release - FROM debian:bookworm-slim COPY --from=builder /app/conf/live777.toml /etc/live777/live777.toml COPY --from=builder /app/target/release/live777 /usr/local/bin/live777 -COPY --from=builder /app/target/release/whipinto /usr/local/bin/whipinto -COPY --from=builder /app/target/release/whepfrom /usr/local/bin/whepfrom - CMD ["live777"] diff --git a/docker/Dockerfile.live777-server b/docker/Dockerfile.live777-server index 5bd8721f..da37eb3d 100644 --- a/docker/Dockerfile.live777-server +++ b/docker/Dockerfile.live777-server @@ -1,4 +1,4 @@ -FROM rust:slim-bookworm as builder +FROM rust:slim-bookworm AS builder WORKDIR /app @@ -8,11 +8,7 @@ RUN apt update -y && apt install -y --no-install-recommends npm RUN npm install && npm run build -RUN cargo build --release -RUN cargo build --package=liveman --release - -RUN cargo build --package=whipinto --release -RUN cargo build --package=whepfrom --release +RUN cargo build --release --all-targets --all-features FROM debian:bookworm-slim @@ -25,4 +21,6 @@ COPY --from=builder /app/target/release/liveman /usr/local/bin/liveman COPY --from=builder /app/target/release/whipinto /usr/local/bin/whipinto COPY --from=builder /app/target/release/whepfrom /usr/local/bin/whepfrom +COPY --from=builder /app/target/release/net4mqtt /usr/local/bin/net4mqtt + CMD ["live777"] diff --git a/docker/Dockerfile.liveman b/docker/Dockerfile.liveman index 1c69ca50..efd3f847 100644 --- a/docker/Dockerfile.liveman +++ b/docker/Dockerfile.liveman @@ -1,4 +1,4 @@ -FROM rust:slim-bookworm as builder +FROM rust:slim-bookworm AS builder WORKDIR /app @@ -8,7 +8,7 @@ RUN apt update -y && apt install -y --no-install-recommends npm RUN npm install && npm run build -RUN cargo build --package=liveman --release +RUN cargo build --bin=liveman --release FROM debian:bookworm-slim diff --git a/docker/Dockerfile.whepfrom b/docker/Dockerfile.whepfrom index a1ca23e3..d7fba42f 100644 --- a/docker/Dockerfile.whepfrom +++ b/docker/Dockerfile.whepfrom @@ -1,10 +1,10 @@ -FROM rust:slim-bookworm as builder +FROM rust:slim-bookworm AS builder WORKDIR /app COPY . . -RUN cargo build --package=whepfrom --release +RUN cargo build --bin=whepfrom --release FROM debian:bookworm-slim diff --git a/docker/Dockerfile.whipinto b/docker/Dockerfile.whipinto index 00238325..822639ce 100644 --- a/docker/Dockerfile.whipinto +++ b/docker/Dockerfile.whipinto @@ -1,10 +1,10 @@ -FROM rust:slim-bookworm as builder +FROM rust:slim-bookworm AS builder WORKDIR /app COPY . . -RUN cargo build --package=whipinto --release +RUN cargo build --bin=whipinto --release FROM debian:bookworm-slim diff --git a/liveion/Cargo.toml b/liveion/Cargo.toml index d2fad1ee..1f7c1750 100644 --- a/liveion/Cargo.toml +++ b/liveion/Cargo.toml @@ -37,12 +37,14 @@ lazy_static = "1.4.0" md5 = "0.7.0" mime_guess = "2.0.4" prometheus = "0.13.3" -rust-embed = { version = "8.4", features = ["axum-ex"] } serde_json = "1.0.114" tower-http = { version = "0.5.2", features = ["fs", "auth", "trace", "cors"] } reqwest = { version = "0.12", features = [ "rustls-tls", ], default-features = false } +rust-embed = { version = "8.4", features = ["axum-ex"], optional = true } + [features] +webui = ["dep:rust-embed"] net4mqtt = ["dep:net4mqtt"] diff --git a/liveion/src/lib.rs b/liveion/src/lib.rs index 23db81ed..a97b34f2 100644 --- a/liveion/src/lib.rs +++ b/liveion/src/lib.rs @@ -1,8 +1,7 @@ use std::{future::Future, sync::Arc}; use axum::{extract::Request, middleware, response::IntoResponse, routing::get, Router}; -use http::{header, StatusCode, Uri}; -use rust_embed::RustEmbed; +use http::{StatusCode, Uri}; use tokio::net::TcpListener; use tower_http::{ cors::CorsLayer, trace::TraceLayer, validate_request::ValidateRequestHeaderLayer, @@ -17,7 +16,8 @@ use crate::route::{admin, session, whep, whip, AppState}; use stream::manager::Manager; -#[derive(RustEmbed)] +#[cfg(feature = "webui")] +#[derive(rust_embed::RustEmbed)] #[folder = "../assets/liveion/"] struct Assets; @@ -44,7 +44,7 @@ where }; let auth_layer = ValidateRequestHeaderLayer::custom(ManyValidate::new(cfg.auth.secret, cfg.auth.tokens)); - let mut app = Router::new() + let app = Router::new() .merge( whip::route() .merge(whep::route()) @@ -79,9 +79,8 @@ where }) .on_response(tower_http::trace::DefaultOnResponse::new().level(Level::INFO)) .on_failure(tower_http::trace::DefaultOnFailure::new().level(Level::INFO)), - ); - - app = app.fallback(static_handler); + ) + .fallback(static_handler); #[cfg(feature = "net4mqtt")] { @@ -120,6 +119,7 @@ where .unwrap_or_else(|e| error!("Application error: {e}")); } +#[cfg(feature = "webui")] async fn static_handler(uri: Uri) -> impl IntoResponse { let mut path = uri.path().trim_start_matches('/'); if path.is_empty() { @@ -128,12 +128,17 @@ async fn static_handler(uri: Uri) -> impl IntoResponse { match Assets::get(path) { Some(content) => { let mime = mime_guess::from_path(path).first_or_octet_stream(); - ([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response() + ([(http::header::CONTENT_TYPE, mime.as_ref())], content.data).into_response() } None => (StatusCode::NOT_FOUND, "not found").into_response(), } } +#[cfg(not(feature = "webui"))] +async fn static_handler(_: Uri) -> impl IntoResponse { + (StatusCode::NOT_FOUND, "feature webui not enable") +} + pub fn metrics_register() { metrics::REGISTRY .register(Box::new(metrics::STREAM.clone())) diff --git a/liveman/Cargo.toml b/liveman/Cargo.toml index 44d09b8d..3da93f63 100644 --- a/liveman/Cargo.toml +++ b/liveman/Cargo.toml @@ -34,11 +34,13 @@ reqwest = { version = "0.12", features = [ "rustls-tls", "socks", ], default-features = false } -rust-embed = { version = "8.4", features = ["axum-ex"] } serde_json = "1.0.114" tower-http = { version = "0.5.2", features = ["fs", "auth", "trace", "cors"] } url = "2.5" +rust-embed = { version = "8.4", features = ["axum-ex"], optional = true } + [features] +webui = ["dep:rust-embed"] net4mqtt = ["dep:net4mqtt"] diff --git a/liveman/src/lib.rs b/liveman/src/lib.rs index 46a1dccf..9178bed1 100644 --- a/liveman/src/lib.rs +++ b/liveman/src/lib.rs @@ -1,8 +1,7 @@ use std::{future::Future, time::Duration}; use axum::{extract::Request, middleware, response::IntoResponse, routing::post, Router}; -use http::{header, StatusCode, Uri}; -use rust_embed::RustEmbed; +use http::{StatusCode, Uri}; use tokio::net::TcpListener; use tower_http::{ cors::CorsLayer, trace::TraceLayer, validate_request::ValidateRequestHeaderLayer, @@ -14,7 +13,8 @@ use crate::config::Config; use crate::store::{Node, NodeKind, Storage}; use auth::{access::access_middleware, ManyValidate}; -#[derive(RustEmbed)] +#[cfg(feature = "webui")] +#[derive(rust_embed::RustEmbed)] #[folder = "../assets/liveman/"] struct Assets; @@ -138,7 +138,7 @@ where let auth_layer = ValidateRequestHeaderLayer::custom(ManyValidate::new(cfg.auth.secret, cfg.auth.tokens)); - let mut app = Router::new() + let app = Router::new() .merge( route::proxy::route() .route("/api/token", post(token)) @@ -168,9 +168,8 @@ where ); span }), - ); - - app = app.fallback(static_handler); + ) + .fallback(static_handler); tokio::spawn(tick::reforward_check(app_state.clone())); axum::serve(listener, app) @@ -179,6 +178,7 @@ where .unwrap_or_else(|e| error!("Application error: {e}")); } +#[cfg(feature = "webui")] async fn static_handler(uri: Uri) -> impl IntoResponse { let mut path = uri.path().trim_start_matches('/'); if path.is_empty() { @@ -187,12 +187,17 @@ async fn static_handler(uri: Uri) -> impl IntoResponse { match Assets::get(path) { Some(content) => { let mime = mime_guess::from_path(path).first_or_octet_stream(); - ([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response() + ([(http::header::CONTENT_TYPE, mime.as_ref())], content.data).into_response() } None => (StatusCode::NOT_FOUND, "not found").into_response(), } } +#[cfg(not(feature = "webui"))] +async fn static_handler(_: Uri) -> impl IntoResponse { + (StatusCode::NOT_FOUND, "feature webui not enable") +} + #[derive(Clone)] struct AppState { config: Config,