diff --git a/svc/Cargo.lock b/svc/Cargo.lock index cc06136de..7b490e005 100644 --- a/svc/Cargo.lock +++ b/svc/Cargo.lock @@ -898,6 +898,18 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-nats" version = "0.33.0" @@ -1436,6 +1448,19 @@ dependencies = [ "serde", ] +[[package]] +name = "blake3" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -1576,6 +1601,12 @@ dependencies = [ "either", ] +[[package]] +name = "camino" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" + [[package]] name = "captcha-hcaptcha-config-get" version = "0.0.1" @@ -2747,6 +2778,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + [[package]] name = "core-foundation" version = "0.9.4" @@ -2814,6 +2851,25 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" version = "0.3.11" @@ -5345,6 +5401,18 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "merkle_hash" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fad8dc52477aa6f1751748a5ee1c6d50db7092e8dab1d687840dfa23e2ae4e5" +dependencies = [ + "anyhow", + "blake3", + "camino", + "rayon", +] + [[package]] name = "mime" version = "0.3.17" @@ -6755,6 +6823,26 @@ dependencies = [ "bitflags 2.5.0", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redis" version = "0.23.3" @@ -7492,9 +7580,9 @@ version = "0.1.0" dependencies = [ "hex", "lazy_static", + "merkle_hash", "rivet-metrics", "rivet-util", - "sha2", "tokio", "types", "uuid", diff --git a/svc/pkg/cluster/util/Cargo.toml b/svc/pkg/cluster/util/Cargo.toml index f3bdbec3c..b1065186b 100644 --- a/svc/pkg/cluster/util/Cargo.toml +++ b/svc/pkg/cluster/util/Cargo.toml @@ -13,6 +13,6 @@ types = { path = "../../../../lib/types/core" } uuid = { version = "1", features = ["v4", "serde"] } [build-dependencies] +merkle_hash = "3.6" hex = "0.4" -sha2 = "0.10" tokio = { version = "1.29", features = ["full"] } diff --git a/svc/pkg/cluster/util/build.rs b/svc/pkg/cluster/util/build.rs index 2a81e73e8..eed68bebb 100644 --- a/svc/pkg/cluster/util/build.rs +++ b/svc/pkg/cluster/util/build.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; -use sha2::{Digest, Sha256}; -use tokio::{fs, process::Command}; +use tokio::fs; +use merkle_hash::MerkleTree; // NOTE: This only gets the hash of the folder. Any template variables changed in the install scripts // will not update the hash. @@ -23,57 +23,11 @@ async fn main() { // Add rereun statement println!("cargo:rerun-if-changed={}", server_install_path.display()); - let mut util_path = current_dir.clone(); - util_path.pop(); - let util_path = util_path - .join("worker") - .join("src") - .join("workers") - .join("server_install"); - - // Compute the git diff between the current branch and the local changes - let cmd = Command::new("git") - .arg("diff") - .arg("--minimal") - .arg("HEAD") - .arg("--") - .arg(util_path) - .output() - .await + let tree = MerkleTree::builder(server_install_path.display().to_string()) + .hash_names(true) + .build() .unwrap(); - - if !cmd.status.success() { - panic!( - "failed to get git diff ({}):\n{}", - cmd.status, - String::from_utf8(cmd.stderr).unwrap() - ); - } - - let source_diff = String::from_utf8(cmd.stdout).unwrap(); - - // If there is no diff, use the git commit hash - let source_hash = if source_diff.is_empty() { - let cmd = Command::new("git") - .arg("rev-parse") - .arg("HEAD:svc/pkg/cluster/worker/src/workers/server_install") - .output() - .await - .unwrap(); - - if !cmd.status.success() { - panic!( - "failed to get git diff ({}):\n{}", - cmd.status, - String::from_utf8(cmd.stderr).unwrap() - ); - } - - String::from_utf8(cmd.stdout).unwrap() - } else { - // Get hash of diff - hex::encode(Sha256::digest(source_diff.as_bytes())) - }; + let source_hash = hex::encode(tree.root.item.hash); fs::write(out_dir.join("hash.txt"), source_hash.trim()) .await