From bf7333208893d5886a11f03a5274166e02f8a102 Mon Sep 17 00:00:00 2001 From: Firstyear Date: Mon, 15 Jul 2024 18:06:15 +1000 Subject: [PATCH] enable build htmx in docker (#2893) --- Makefile | 7 +++--- libs/profiles/container_generic.toml | 1 + libs/profiles/developer.toml | 1 + libs/profiles/release_suse_generic.toml | 1 + libs/profiles/src/lib.rs | 5 ++++ server/Dockerfile | 1 + server/core/src/https/mod.rs | 31 ++++++++++++++++--------- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index ad033e79f..e116e56e0 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ CONTAINER_BUILD_ARGS ?= MARKDOWN_FORMAT_ARGS ?= --options-line-width=100 CONTAINER_TOOL ?= docker BUILDKIT_PROGRESS ?= plain +KANIDM_FEATURES ?= "" TESTS ?= BOOK_VERSION ?= master GIT_COMMIT := $(shell git rev-parse HEAD) @@ -48,7 +49,7 @@ buildx/kanidmd: -t $(IMAGE_BASE)/server:$(IMAGE_EXT_VERSION) \ --progress $(BUILDKIT_PROGRESS) \ --build-arg "KANIDM_BUILD_PROFILE=container_generic" \ - --build-arg "KANIDM_FEATURES=" \ + --build-arg "KANIDM_FEATURES=$(KANIDM_FEATURES)" \ --compress \ --label "com.kanidm.git-commit=$(GIT_COMMIT)" \ --label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \ @@ -64,7 +65,7 @@ buildx/kanidm_tools: -t $(IMAGE_BASE)/tools:$(IMAGE_EXT_VERSION) \ --progress $(BUILDKIT_PROGRESS) \ --build-arg "KANIDM_BUILD_PROFILE=container_generic" \ - --build-arg "KANIDM_FEATURES=" \ + --build-arg "KANIDM_FEATURES=$(KANIDM_FEATURES)" \ --label "com.kanidm.git-commit=$(GIT_COMMIT)" \ --label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \ $(CONTAINER_BUILD_ARGS) . @@ -101,7 +102,7 @@ build/orca: @$(CONTAINER_TOOL) build $(CONTAINER_TOOL_ARGS) -f tools/orca/Dockerfile \ -t $(IMAGE_BASE)/orca:$(IMAGE_VERSION) \ --build-arg "KANIDM_BUILD_PROFILE=container_generic" \ - --build-arg "KANIDM_FEATURES=" \ + --build-arg "KANIDM_FEATURES=$(KANIDM_FEATURES)" \ --label "com.kanidm.git-commit=$(GIT_COMMIT)" \ --label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \ $(CONTAINER_BUILD_ARGS) . diff --git a/libs/profiles/container_generic.toml b/libs/profiles/container_generic.toml index 1a09762bd..dcbe79770 100644 --- a/libs/profiles/container_generic.toml +++ b/libs/profiles/container_generic.toml @@ -1,4 +1,5 @@ web_ui_pkg_path = "/pkg" +htmx_ui_pkg_path = "/hpkg" # Don't set the cpu_flags to autodetect for this platform # cpu_flags = "none" admin_bind_path = "/data/kanidmd.sock" diff --git a/libs/profiles/developer.toml b/libs/profiles/developer.toml index a8edafe2e..5e66d3091 100644 --- a/libs/profiles/developer.toml +++ b/libs/profiles/developer.toml @@ -1,4 +1,5 @@ web_ui_pkg_path = "../web_ui/pkg" +htmx_ui_pkg_path = "../core/static" # Set to native for developer machines. cpu_flags = "native" admin_bind_path = "/tmp/kanidmd.sock" diff --git a/libs/profiles/release_suse_generic.toml b/libs/profiles/release_suse_generic.toml index afe21fd28..a95283fb7 100644 --- a/libs/profiles/release_suse_generic.toml +++ b/libs/profiles/release_suse_generic.toml @@ -1,4 +1,5 @@ web_ui_pkg_path = "/usr/share/kanidm/ui/pkg" +web_ui_pkg_path = "/usr/share/kanidm/ui/hpkg" # Don't set the value for autodetect # cpu_flags = "none" admin_bind_path = "/var/run/kanidmd/sock" diff --git a/libs/profiles/src/lib.rs b/libs/profiles/src/lib.rs index a4dc9acab..3b2ba2234 100644 --- a/libs/profiles/src/lib.rs +++ b/libs/profiles/src/lib.rs @@ -53,6 +53,7 @@ impl std::fmt::Display for CpuOptLevel { #[serde(deny_unknown_fields)] struct ProfileConfig { web_ui_pkg_path: String, + htmx_ui_pkg_path: String, #[serde(default)] cpu_flags: CpuOptLevel, admin_bind_path: String, @@ -122,6 +123,10 @@ pub fn apply_profile() { "cargo:rustc-env=KANIDM_WEB_UI_PKG_PATH={}", profile_cfg.web_ui_pkg_path ); + println!( + "cargo:rustc-env=KANIDM_HTMX_UI_PKG_PATH={}", + profile_cfg.htmx_ui_pkg_path + ); println!( "cargo:rustc-env=KANIDM_ADMIN_BIND_PATH={}", profile_cfg.admin_bind_path diff --git a/server/Dockerfile b/server/Dockerfile index 7a21e0e65..2dbc890b8 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -73,6 +73,7 @@ RUN \ COPY --from=builder /usr/src/kanidm/target/release/kanidmd /sbin/ COPY --from=builder /usr/src/kanidm/server/web_ui/pkg /pkg +COPY --from=builder /usr/src/kanidm/server/core/static /hpkg RUN chmod +x /sbin/kanidmd EXPOSE 8443 3636 diff --git a/server/core/src/https/mod.rs b/server/core/src/https/mod.rs index d67c9f218..f66e219e2 100644 --- a/server/core/src/https/mod.rs +++ b/server/core/src/https/mod.rs @@ -129,7 +129,7 @@ pub fn get_js_files(role: ServerRole) -> Result { if !matches!(role, ServerRole::WriteReplicaNoUI) { // let's set up the list of js module hashes let pkg_path = if cfg!(feature = "ui_htmx") { - "../core/static".to_string() + env!("KANIDM_HTMX_UI_PKG_PATH").to_owned() } else { env!("KANIDM_WEB_UI_PKG_PATH").to_owned() }; @@ -300,19 +300,28 @@ pub async fn create_https_server( let app = match config.role { ServerRole::WriteReplicaNoUI => app, ServerRole::WriteReplica | ServerRole::ReadOnlyReplica => { - let pkg_path = PathBuf::from(env!("KANIDM_WEB_UI_PKG_PATH")); - if !pkg_path.exists() { - eprintln!( - "Couldn't find Web UI package path: ({}), quitting.", - env!("KANIDM_WEB_UI_PKG_PATH") - ); - std::process::exit(1); - } let pkg_router = if cfg!(feature = "ui_htmx") { - // TODO! This should be from webui pkg path in future!!! - Router::new().nest_service("/pkg", ServeDir::new("../core/static")) + let pkg_path = PathBuf::from(env!("KANIDM_HTMX_UI_PKG_PATH")); + if !pkg_path.exists() { + eprintln!( + "Couldn't find htmx UI package path: ({}), quitting.", + env!("KANIDM_HTMX_UI_PKG_PATH") + ); + std::process::exit(1); + } + Router::new().nest_service("/pkg", ServeDir::new(pkg_path)) // TODO: Add in the br precompress } else { + + let pkg_path = PathBuf::from(env!("KANIDM_WEB_UI_PKG_PATH")); + if !pkg_path.exists() { + eprintln!( + "Couldn't find Web UI package path: ({}), quitting.", + env!("KANIDM_WEB_UI_PKG_PATH") + ); + std::process::exit(1); + } + Router::new() .nest_service("/pkg", ServeDir::new(pkg_path).precompressed_br()) .layer(middleware::compression::new())