Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt feature webui #241

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions docker/Dockerfile.live777
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:slim-bookworm as builder
FROM rust:slim-bookworm AS builder

WORKDIR /app

Expand All @@ -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"]
10 changes: 4 additions & 6 deletions docker/Dockerfile.live777-server
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:slim-bookworm as builder
FROM rust:slim-bookworm AS builder

WORKDIR /app

Expand All @@ -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

Expand All @@ -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"]
4 changes: 2 additions & 2 deletions docker/Dockerfile.liveman
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:slim-bookworm as builder
FROM rust:slim-bookworm AS builder

WORKDIR /app

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.whepfrom
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.whipinto
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion liveion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
21 changes: 13 additions & 8 deletions liveion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,7 +16,8 @@

use stream::manager::Manager;

#[derive(RustEmbed)]
#[cfg(feature = "webui")]
#[derive(rust_embed::RustEmbed)]
#[folder = "../assets/liveion/"]
struct Assets;

Expand All @@ -44,7 +44,7 @@
};
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())
Expand Down Expand Up @@ -79,9 +79,8 @@
})
.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")]
{
Expand Down Expand Up @@ -120,6 +119,7 @@
.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() {
Expand All @@ -128,12 +128,17 @@
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()

Check warning on line 131 in liveion/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

liveion/src/lib.rs#L131

Added line #L131 was not covered by tests
}
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()))
Expand Down
4 changes: 3 additions & 1 deletion liveman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

21 changes: 13 additions & 8 deletions liveman/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,7 +13,8 @@
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;

Expand Down Expand Up @@ -138,7 +138,7 @@

let auth_layer =
ValidateRequestHeaderLayer::custom(ManyValidate::new(cfg.auth.secret, cfg.auth.tokens));
let mut app = Router::new()
let app = Router::new()

Check warning on line 141 in liveman/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

liveman/src/lib.rs#L141

Added line #L141 was not covered by tests
.merge(
route::proxy::route()
.route("/api/token", post(token))
Expand Down Expand Up @@ -168,9 +168,8 @@
);
span
}),
);

app = app.fallback(static_handler);
)
.fallback(static_handler);

tokio::spawn(tick::reforward_check(app_state.clone()));
axum::serve(listener, app)
Expand All @@ -179,6 +178,7 @@
.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() {
Expand All @@ -187,12 +187,17 @@
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()

Check warning on line 190 in liveman/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

liveman/src/lib.rs#L190

Added line #L190 was not covered by tests
}
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,
Expand Down
Loading