-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): embedded assets into binary for release builds (#15656)
Signed-off-by: Bugen Zhao <[email protected]>
- Loading branch information
Showing
19 changed files
with
360 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,3 @@ jobs: | |
npm run lint | ||
npm run build | ||
npm run build-static |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "risingwave_meta_dashboard" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
keywords = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
axum = "0.6" | ||
bytes = "1" | ||
hyper = "0.14" | ||
mime_guess = "2" | ||
reqwest = "0.11" | ||
rust-embed = { version = "8", features = ["interpolate-folder-path", "mime-guess"] } | ||
thiserror-ext = { workspace = true } | ||
tracing = "0.1" | ||
url = "2" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", features = ["full"] } | ||
tracing-subscriber = "0.3" | ||
|
||
[build-dependencies] | ||
anyhow = "1" | ||
cargo-emit = "0.2" | ||
dircpy = "0.3" | ||
npm_rs = "1" | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::path::{Path, PathBuf}; | ||
|
||
use cargo_emit::{rerun_if_changed, rustc_cfg}; | ||
use npm_rs::{NodeEnv, NpmEnv}; | ||
|
||
fn env_var_is_true(key: &str) -> bool { | ||
cargo_emit::rerun_if_env_changed!(key); | ||
|
||
std::env::var(key) | ||
.map(|value| { | ||
["1", "t", "true"] | ||
.iter() | ||
.any(|&s| value.eq_ignore_ascii_case(s)) | ||
}) | ||
.unwrap_or(false) | ||
} | ||
|
||
const DASHBOARD_DIR: &str = "../../../dashboard"; | ||
|
||
fn dest_dir() -> PathBuf { | ||
let out_dir = std::env::var("OUT_DIR").unwrap(); | ||
Path::new(&out_dir).join("assets") | ||
} | ||
|
||
fn build() -> anyhow::Result<()> { | ||
// TODO(bugen): we should include all files and subdirectories under `DASHBOARD_DIR` | ||
// while excluding the `out` directory. There's no elegant way to do this. | ||
rerun_if_changed!(format!("{DASHBOARD_DIR}/components")); | ||
|
||
let exit_status = NpmEnv::default() | ||
.with_node_env(&NodeEnv::Production) | ||
.set_path(DASHBOARD_DIR) | ||
.init_env() | ||
.install(None) | ||
.run("build") | ||
.exec()?; | ||
|
||
if !exit_status.success() { | ||
anyhow::bail!("dashboard build failed with status: {}", exit_status); | ||
} | ||
|
||
let dest = dest_dir(); | ||
let src = Path::new(DASHBOARD_DIR).join("out"); | ||
dircpy::copy_dir(src, dest)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let should_build = env_var_is_true("ENABLE_BUILD_DASHBOARD"); | ||
|
||
if should_build { | ||
build()?; | ||
// Once build succeeded, set a cfg flag to indicate that the embedded assets | ||
// are ready to be used. | ||
rustc_cfg!("dashboard_built"); | ||
} else { | ||
// If we're not to build, create the destination directory but keep it empty. | ||
std::fs::create_dir_all(dest_dir())?; | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.