diff --git a/.gitignore b/.gitignore index f4c03c999..3adae90e5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ target /flamegraph*.svg /perf.data* + +/static diff --git a/Cargo.lock b/Cargo.lock index 16dbd2eb6..9edb8d6e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6622,7 +6622,12 @@ version = "0.1.0" dependencies = [ "actix-web", "actix-web-static-files", + "base64 0.22.1", "log", + "serde", + "serde_json", + "static-files", + "tera", "trustify-ui", ] @@ -6701,6 +6706,7 @@ dependencies = [ "trustify-module-storage", "trustify-module-ui", "trustify-module-vulnerability", + "trustify-ui", "url", "urlencoding", "utoipa", @@ -6730,7 +6736,7 @@ dependencies = [ [[package]] name = "trustify-ui" version = "0.1.0" -source = "git+https://github.com/trustification/trustify-ui.git#453a50222a313dda2cc5ed534d44e27ef692d5e1" +source = "git+https://github.com/carlosthe19916/trustify-ui?branch=static-ui#505720e95fbb4bdc2bf72ee4c723f4b92966330b" dependencies = [ "base64 0.22.1", "serde", diff --git a/Cargo.toml b/Cargo.toml index 021244bfa..349fb9ee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -122,12 +122,12 @@ trustify-module-importer = { path = "modules/importer" } trustify-module-ingestor = { path = "modules/ingestor" } trustify-module-search = { path = "modules/search" } trustify-module-storage = { path = "modules/storage" } -trustify-module-ui = { path = "modules/ui", default-features = false } +trustify-module-ui = { path = "modules/ui" } trustify-module-advisory = { path = "modules/advisory" } trustify-module-organization = { path = "modules/organization" } trustify-module-vulnerability = { path = "modules/vulnerability" } trustify-server = { path = "server", default-features = false } -trustify-ui = { git = "https://github.com/trustification/trustify-ui.git" } +trustify-ui = { git = "https://github.com/carlosthe19916/trustify-ui", branch = "static-ui" } [patch.crates-io] #csaf-walker = { git = "https://github.com/ctron/csaf-walker", rev = "7b6e64dd56e4be79e184b053ef754a42e1496fe0" } diff --git a/README.md b/README.md index 0435fe445..347bbe329 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,19 @@ cargo run --bin trustd --no-default-features That will create its own database on your local filesystem. -* The first command also contains **UI** so point your browser at . -* The second runs without **UI** then you can go at to view the API. +* You can go at to view the UI. +* You can go at to view the API. + +### Running server with the latest version of the UI + +- The server renders the UI from the `./static-local` folder +- If the `./static` directory exists then it will be used for serving the UI + +Copy the UI static files executing: + +```shell +podman cp $(docker create --name ui-download ghcr.io/trustification/trustify-ui:latest):/opt/app-root/dist/client/dist static && podman rm ui-download +``` ### Running containerized UI diff --git a/modules/ui/Cargo.toml b/modules/ui/Cargo.toml index 7ab0a9089..00e021dc0 100644 --- a/modules/ui/Cargo.toml +++ b/modules/ui/Cargo.toml @@ -7,8 +7,13 @@ edition = "2021" actix-web = { workspace = true } log = { workspace = true } actix-web-static-files = { workspace = true } -trustify-ui = { workspace = true, optional = true } +trustify-ui = { workspace = true } -[features] -default = [ "ui" ] -ui = ["trustify-ui"] +static-files = "0.2.1" +serde_json = "1.0.117" +tera = "1.19.1" +base64 = "0.22.1" +serde = { version = "1.0.201", features = ["derive"] } + +[build-dependencies] +static-files = "0.2.1" \ No newline at end of file diff --git a/modules/ui/build.rs b/modules/ui/build.rs new file mode 100644 index 000000000..02849a6eb --- /dev/null +++ b/modules/ui/build.rs @@ -0,0 +1,13 @@ +use static_files::resource_dir; +use std::path::Path; + +static STATIC_DIR: &str = "../../static"; +static STATIC_LOCAL_DIR: &str = "../../static-local"; + +pub fn main() { + if Path::new(STATIC_DIR).exists() { + resource_dir(STATIC_DIR).build().unwrap(); + } else { + resource_dir(STATIC_LOCAL_DIR).build().unwrap(); + } +} diff --git a/modules/ui/src/endpoints.rs b/modules/ui/src/endpoints.rs index 545a3826f..d305980f7 100644 --- a/modules/ui/src/endpoints.rs +++ b/modules/ui/src/endpoints.rs @@ -1,7 +1,8 @@ +use crate::ui::ui_resources; use actix_web::web; use actix_web_static_files::ResourceFiles; -use trustify_ui::{trustify_ui, UI}; +use trustify_ui::UI; pub fn configure(config: &mut web::ServiceConfig, ui: &UI) { - config.service(ResourceFiles::new("/", trustify_ui(ui)).resolve_not_found_to("")); + config.service(ResourceFiles::new("/", ui_resources(ui)).resolve_not_found_to("")); } diff --git a/modules/ui/src/lib.rs b/modules/ui/src/lib.rs index 0473513fb..0821df211 100644 --- a/modules/ui/src/lib.rs +++ b/modules/ui/src/lib.rs @@ -1,5 +1,2 @@ -#[cfg(feature = "ui")] -pub use trustify_ui::UI; - -#[cfg(feature = "ui")] pub mod endpoints; +pub mod ui; diff --git a/modules/ui/src/ui.rs b/modules/ui/src/ui.rs new file mode 100644 index 000000000..19a5c4ea6 --- /dev/null +++ b/modules/ui/src/ui.rs @@ -0,0 +1,11 @@ +use std::collections::HashMap; + +use static_files::Resource; +use trustify_ui::{trustify_ui, UI}; + +include!(concat!(env!("OUT_DIR"), "/generated.rs")); + +pub fn ui_resources(ui: &UI) -> HashMap<&'static str, Resource> { + let resources = generate(); + trustify_ui(ui, resources) +} diff --git a/server/Cargo.toml b/server/Cargo.toml index 12ed4f4ff..e653cb47d 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -32,10 +32,7 @@ url = "2" utoipa = { workspace = true, features = ["actix_extras"] } utoipa-swagger-ui = { workspace = true, features = ["actix-web"] } walker-common = { workspace = true } +trustify-ui = { workspace = true } [dev-dependencies] urlencoding = { workspace = true } - -[features] -default = [ "ui" ] -ui = ["trustify-module-ui/ui"] diff --git a/server/src/lib.rs b/server/src/lib.rs index 78f86801f..77d79cf45 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -39,12 +39,10 @@ use trustify_module_importer::server::importer; use trustify_module_ingestor::graph::Graph; use trustify_module_storage::service::dispatch::DispatchBackend; use trustify_module_storage::service::fs::FileSystemBackend; +use trustify_ui::UI; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; -#[cfg(feature = "ui")] -use trustify_module_ui::UI; - /// Run the API server #[derive(clap::Args, Debug)] pub struct Run { @@ -82,7 +80,6 @@ struct InitData { http: HttpServerConfig, tracing: Tracing, swagger_oidc: Option>, - #[cfg(feature = "ui")] ui: UI, } @@ -152,7 +149,6 @@ impl InitData { let storage = DispatchBackend::Filesystem(FileSystemBackend::new(storage).await?); - #[cfg(feature = "ui")] let ui = UI { // TODO: where/how should we configure these details? version: env!("CARGO_PKG_VERSION").to_string(), @@ -173,7 +169,6 @@ impl InitData { tracing: run.infra.tracing, swagger_oidc, storage, - #[cfg(feature = "ui")] ui, }) } @@ -212,7 +207,6 @@ impl InitData { trustify_module_storage::endpoints::configure(svc, storage.clone()); // I think the UI must come last due to // its use of `resolve_not_found_to` - #[cfg(feature = "ui")] trustify_module_ui::endpoints::configure(svc, &self.ui); }); }) diff --git a/static-local/branding/strings.json b/static-local/branding/strings.json new file mode 100644 index 000000000..0d2e2f2cc --- /dev/null +++ b/static-local/branding/strings.json @@ -0,0 +1,21 @@ +{ + "application": { + "title": "Trustification", + "name": "Trustification UI", + "description": "Trustification UI" + }, + "about": { + "displayName": "Trustification", + "imageSrc": "<%= brandingRoot %>/images/masthead-logo.svg", + "documentationUrl": "https://trustification.io/" + }, + "masthead": { + "leftBrand": { + "src": "<%= brandingRoot %>/images/masthead-logo.svg", + "alt": "brand", + "height": "40px" + }, + "leftTitle": null, + "rightBrand": null + } +} diff --git a/static-local/index.html.ejs b/static-local/index.html.ejs new file mode 100644 index 000000000..d3d2c4e32 --- /dev/null +++ b/static-local/index.html.ejs @@ -0,0 +1,8 @@ + + + + Trustify + +

Welcome

+ + \ No newline at end of file diff --git a/trustd/Cargo.toml b/trustd/Cargo.toml index 009fdca1c..e55b1ad7b 100644 --- a/trustd/Cargo.toml +++ b/trustd/Cargo.toml @@ -22,7 +22,3 @@ serde_json = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["full"] } url = { workspace = true } - -[features] -default = ["ui"] -ui = ["trustify-server/ui"]