From bb79695e44d6e1f2a4d7a27b41d8c966ac9f0e76 Mon Sep 17 00:00:00 2001 From: Marin Postma Date: Tue, 20 Apr 2021 15:20:09 +0200 Subject: [PATCH] load mini-dashboard assets --- Cargo.lock | 163 ++++++++++++++++++++++++++++++++++-- meilisearch-http/Cargo.toml | 10 +++ meilisearch-http/build.rs | 44 +++++++++- 3 files changed, 210 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ae1cc8d4..f007a0179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -521,6 +521,38 @@ dependencies = [ "bytes 1.0.1", ] +[[package]] +name = "bzip2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.10+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17fa3d1ac1ca21c5c4e36a97f3c3eb25084576f6fc47bf0139c1123434216c6c" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "cargo_toml" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d94e66797729c3a52b74980ec7992a9399aace3044bbcde9ce6bb98926abb673" +dependencies = [ + "serde", + "serde_derive", + "toml", +] + [[package]] name = "cc" version = "1.0.67" @@ -1236,6 +1268,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "hostname" version = "0.3.1" @@ -1268,6 +1306,17 @@ dependencies = [ "http", ] +[[package]] +name = "http-body" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" +dependencies = [ + "bytes 1.0.1", + "http", + "pin-project-lite 0.2.6", +] + [[package]] name = "httparse" version = "1.4.0" @@ -1313,7 +1362,7 @@ dependencies = [ "futures-util", "h2 0.2.7", "http", - "http-body", + "http-body 0.3.1", "httparse", "httpdate", "itoa", @@ -1325,6 +1374,30 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" +dependencies = [ + "bytes 1.0.1", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.2", + "http", + "http-body 0.4.1", + "httparse", + "httpdate", + "itoa", + "pin-project", + "socket2 0.4.0", + "tokio 1.5.0", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper-rustls" version = "0.21.0" @@ -1333,7 +1406,7 @@ checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6" dependencies = [ "bytes 0.5.6", "futures-util", - "hyper", + "hyper 0.13.10", "log", "rustls 0.18.1", "tokio 0.2.25", @@ -1341,6 +1414,21 @@ dependencies = [ "webpki", ] +[[package]] +name = "hyper-rustls" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" +dependencies = [ + "futures-util", + "hyper 0.14.5", + "log", + "rustls 0.19.1", + "tokio 1.5.0", + "tokio-rustls 0.22.0", + "webpki", +] + [[package]] name = "idna" version = "0.2.3" @@ -1638,6 +1726,7 @@ dependencies = [ "async-trait", "byte-unit", "bytes 0.6.0", + "cargo_toml", "chrono", "crossbeam-channel", "dashmap", @@ -1649,6 +1738,7 @@ dependencies = [ "futures-util", "grenad", "heed", + "hex", "http", "indexmap", "itertools 0.10.0", @@ -1669,11 +1759,13 @@ dependencies = [ "rand 0.7.3", "rayon", "regex", + "reqwest 0.11.3", "rustls 0.19.1", "sentry", "serde", "serde_json", "serde_url_params", + "sha-1 0.9.4", "sha2", "siphasher", "slice-group-by", @@ -1687,6 +1779,7 @@ dependencies = [ "uuid", "vergen", "walkdir", + "zip", ] [[package]] @@ -2503,9 +2596,9 @@ dependencies = [ "futures-core", "futures-util", "http", - "http-body", - "hyper", - "hyper-rustls", + "http-body 0.3.1", + "hyper 0.13.10", + "hyper-rustls 0.21.0", "ipnet", "js-sys", "lazy_static", @@ -2528,6 +2621,41 @@ dependencies = [ "winreg", ] +[[package]] +name = "reqwest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" +dependencies = [ + "base64 0.13.0", + "bytes 1.0.1", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body 0.4.1", + "hyper 0.14.5", + "hyper-rustls 0.22.1", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "percent-encoding", + "pin-project-lite 0.2.6", + "rustls 0.19.1", + "serde", + "serde_urlencoded", + "tokio 1.5.0", + "tokio-rustls 0.22.0", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 0.21.1", + "winreg", +] + [[package]] name = "retain_mut" version = "0.1.2" @@ -2691,7 +2819,7 @@ dependencies = [ "log", "rand 0.7.3", "regex", - "reqwest", + "reqwest 0.10.10", "rustc_version 0.2.3", "sentry-types", "uname", @@ -3275,6 +3403,15 @@ dependencies = [ "tokio 1.5.0", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.1" @@ -3700,6 +3837,20 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zip" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c83dc9b784d252127720168abd71ea82bf8c3d96b17dc565b5e2a02854f2b27" +dependencies = [ + "byteorder", + "bzip2", + "crc32fast", + "flate2", + "thiserror", + "time 0.1.44", +] + [[package]] name = "zstd" version = "0.5.4+zstd.1.4.7" diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index e45311fa0..019a1a3f8 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -10,7 +10,13 @@ name = "meilisearch" path = "src/main.rs" [build-dependencies] +anyhow = "*" +cargo_toml = "0.9.0" +hex = "0.4.3" +reqwest = { version = "0.11.3", features = ["blocking", "rustls-tls"], default-features = false} +sha-1 = "0.9.4" vergen = "3.1.0" +zip = "0.5.12" [dependencies] actix-cors = "0.6.0-beta.1" @@ -96,3 +102,7 @@ default = ["sentry"] [target.'cfg(target_os = "linux")'.dependencies] jemallocator = "0.3.2" + +[package.metadata.mini-dashboard] +assets-url = "https://github.com/meilisearch/mini-dashboard/releases/download/v0.1.0/build.zip" +sha1 = "abb7bd8765b9fab38675958bc9d06088589c712c" diff --git a/meilisearch-http/build.rs b/meilisearch-http/build.rs index be4f4a1b6..542ae20e3 100644 --- a/meilisearch-http/build.rs +++ b/meilisearch-http/build.rs @@ -1,6 +1,14 @@ use std::env; +use std::fs::create_dir_all; +use std::io::Cursor; +use std::path::PathBuf; + +use anyhow::Context; +use sha1::{Sha1, Digest}; +use reqwest::blocking::get; use vergen::{generate_cargo_keys, ConstantsFlags}; +use cargo_toml::Manifest; fn main() { // Setup the flags, toggling off the 'SEMVER_FROM_CARGO_PKG' flag @@ -11,6 +19,40 @@ fn main() { generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate the cargo keys!"); if let Ok(_) = env::var("CARGO_FEATURE_MINI_DASHBOARD") { - todo!() + setup_mini_dashboard().expect("Could not load mini-dashboard assets"); } } + +fn setup_mini_dashboard() -> anyhow::Result<()> { + let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); + let cargo_toml = cargo_manifest_dir.join("Cargo.toml"); + + let manifest = Manifest::from_path(cargo_toml).unwrap(); + + let meta = &manifest + .package + .as_ref() + .context("package not specified in Cargo.toml")? + .metadata + .as_ref() + .context("no metadata specified in Cargo.toml")? + ["mini-dashboard"]; + + let url = meta["assets-url"].as_str().unwrap(); + + let dashboard_assets_bytes = get(url)? + .bytes()?; + + let mut hasher = Sha1::new(); + hasher.update(&dashboard_assets_bytes); + let sha1_dashboard = hex::encode(hasher.finalize()); + + assert_eq!(meta["sha1"].as_str().unwrap(), sha1_dashboard); + + let dashboard_dir = cargo_manifest_dir.join("mini-dashboard"); + create_dir_all(&dashboard_dir)?; + let cursor = Cursor::new(&dashboard_assets_bytes); + let mut zip = zip::read::ZipArchive::new(cursor)?; + zip.extract(&dashboard_dir)?; + Ok(()) +}