enable build htmx in docker (#2893)

This commit is contained in:
Firstyear 2024-07-15 18:06:15 +10:00 committed by GitHub
parent 966e26f874
commit bf73332088
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 33 additions and 14 deletions

View file

@ -7,6 +7,7 @@ CONTAINER_BUILD_ARGS ?=
MARKDOWN_FORMAT_ARGS ?= --options-line-width=100 MARKDOWN_FORMAT_ARGS ?= --options-line-width=100
CONTAINER_TOOL ?= docker CONTAINER_TOOL ?= docker
BUILDKIT_PROGRESS ?= plain BUILDKIT_PROGRESS ?= plain
KANIDM_FEATURES ?= ""
TESTS ?= TESTS ?=
BOOK_VERSION ?= master BOOK_VERSION ?= master
GIT_COMMIT := $(shell git rev-parse HEAD) GIT_COMMIT := $(shell git rev-parse HEAD)
@ -48,7 +49,7 @@ buildx/kanidmd:
-t $(IMAGE_BASE)/server:$(IMAGE_EXT_VERSION) \ -t $(IMAGE_BASE)/server:$(IMAGE_EXT_VERSION) \
--progress $(BUILDKIT_PROGRESS) \ --progress $(BUILDKIT_PROGRESS) \
--build-arg "KANIDM_BUILD_PROFILE=container_generic" \ --build-arg "KANIDM_BUILD_PROFILE=container_generic" \
--build-arg "KANIDM_FEATURES=" \ --build-arg "KANIDM_FEATURES=$(KANIDM_FEATURES)" \
--compress \ --compress \
--label "com.kanidm.git-commit=$(GIT_COMMIT)" \ --label "com.kanidm.git-commit=$(GIT_COMMIT)" \
--label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \ --label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \
@ -64,7 +65,7 @@ buildx/kanidm_tools:
-t $(IMAGE_BASE)/tools:$(IMAGE_EXT_VERSION) \ -t $(IMAGE_BASE)/tools:$(IMAGE_EXT_VERSION) \
--progress $(BUILDKIT_PROGRESS) \ --progress $(BUILDKIT_PROGRESS) \
--build-arg "KANIDM_BUILD_PROFILE=container_generic" \ --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.git-commit=$(GIT_COMMIT)" \
--label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \ --label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \
$(CONTAINER_BUILD_ARGS) . $(CONTAINER_BUILD_ARGS) .
@ -101,7 +102,7 @@ build/orca:
@$(CONTAINER_TOOL) build $(CONTAINER_TOOL_ARGS) -f tools/orca/Dockerfile \ @$(CONTAINER_TOOL) build $(CONTAINER_TOOL_ARGS) -f tools/orca/Dockerfile \
-t $(IMAGE_BASE)/orca:$(IMAGE_VERSION) \ -t $(IMAGE_BASE)/orca:$(IMAGE_VERSION) \
--build-arg "KANIDM_BUILD_PROFILE=container_generic" \ --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.git-commit=$(GIT_COMMIT)" \
--label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \ --label "com.kanidm.version=$(IMAGE_EXT_VERSION)" \
$(CONTAINER_BUILD_ARGS) . $(CONTAINER_BUILD_ARGS) .

View file

@ -1,4 +1,5 @@
web_ui_pkg_path = "/pkg" web_ui_pkg_path = "/pkg"
htmx_ui_pkg_path = "/hpkg"
# Don't set the cpu_flags to autodetect for this platform # Don't set the cpu_flags to autodetect for this platform
# cpu_flags = "none" # cpu_flags = "none"
admin_bind_path = "/data/kanidmd.sock" admin_bind_path = "/data/kanidmd.sock"

View file

@ -1,4 +1,5 @@
web_ui_pkg_path = "../web_ui/pkg" web_ui_pkg_path = "../web_ui/pkg"
htmx_ui_pkg_path = "../core/static"
# Set to native for developer machines. # Set to native for developer machines.
cpu_flags = "native" cpu_flags = "native"
admin_bind_path = "/tmp/kanidmd.sock" admin_bind_path = "/tmp/kanidmd.sock"

View file

@ -1,4 +1,5 @@
web_ui_pkg_path = "/usr/share/kanidm/ui/pkg" 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 # Don't set the value for autodetect
# cpu_flags = "none" # cpu_flags = "none"
admin_bind_path = "/var/run/kanidmd/sock" admin_bind_path = "/var/run/kanidmd/sock"

View file

@ -53,6 +53,7 @@ impl std::fmt::Display for CpuOptLevel {
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
struct ProfileConfig { struct ProfileConfig {
web_ui_pkg_path: String, web_ui_pkg_path: String,
htmx_ui_pkg_path: String,
#[serde(default)] #[serde(default)]
cpu_flags: CpuOptLevel, cpu_flags: CpuOptLevel,
admin_bind_path: String, admin_bind_path: String,
@ -122,6 +123,10 @@ pub fn apply_profile() {
"cargo:rustc-env=KANIDM_WEB_UI_PKG_PATH={}", "cargo:rustc-env=KANIDM_WEB_UI_PKG_PATH={}",
profile_cfg.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!( println!(
"cargo:rustc-env=KANIDM_ADMIN_BIND_PATH={}", "cargo:rustc-env=KANIDM_ADMIN_BIND_PATH={}",
profile_cfg.admin_bind_path profile_cfg.admin_bind_path

View file

@ -73,6 +73,7 @@ RUN \
COPY --from=builder /usr/src/kanidm/target/release/kanidmd /sbin/ 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/web_ui/pkg /pkg
COPY --from=builder /usr/src/kanidm/server/core/static /hpkg
RUN chmod +x /sbin/kanidmd RUN chmod +x /sbin/kanidmd
EXPOSE 8443 3636 EXPOSE 8443 3636

View file

@ -129,7 +129,7 @@ pub fn get_js_files(role: ServerRole) -> Result<JavaScriptFiles, ()> {
if !matches!(role, ServerRole::WriteReplicaNoUI) { if !matches!(role, ServerRole::WriteReplicaNoUI) {
// let's set up the list of js module hashes // let's set up the list of js module hashes
let pkg_path = if cfg!(feature = "ui_htmx") { let pkg_path = if cfg!(feature = "ui_htmx") {
"../core/static".to_string() env!("KANIDM_HTMX_UI_PKG_PATH").to_owned()
} else { } else {
env!("KANIDM_WEB_UI_PKG_PATH").to_owned() env!("KANIDM_WEB_UI_PKG_PATH").to_owned()
}; };
@ -300,6 +300,19 @@ pub async fn create_https_server(
let app = match config.role { let app = match config.role {
ServerRole::WriteReplicaNoUI => app, ServerRole::WriteReplicaNoUI => app,
ServerRole::WriteReplica | ServerRole::ReadOnlyReplica => { ServerRole::WriteReplica | ServerRole::ReadOnlyReplica => {
let pkg_router = if cfg!(feature = "ui_htmx") {
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")); let pkg_path = PathBuf::from(env!("KANIDM_WEB_UI_PKG_PATH"));
if !pkg_path.exists() { if !pkg_path.exists() {
eprintln!( eprintln!(
@ -308,11 +321,7 @@ pub async fn create_https_server(
); );
std::process::exit(1); 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"))
// TODO: Add in the br precompress
} else {
Router::new() Router::new()
.nest_service("/pkg", ServeDir::new(pkg_path).precompressed_br()) .nest_service("/pkg", ServeDir::new(pkg_path).precompressed_br())
.layer(middleware::compression::new()) .layer(middleware::compression::new())