mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-26 00:32:45 +03:00
build: add packages.zip hash to runtime
This commit is contained in:
parent
cf71c9eb1f
commit
9532e381e5
41
Cargo.lock
generated
41
Cargo.lock
generated
@ -1409,7 +1409,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"fs-err",
|
"fs-err",
|
||||||
"kit",
|
"kit 0.7.7",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
@ -3784,6 +3784,43 @@ dependencies = [
|
|||||||
"zip 0.6.6",
|
"zip 0.6.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kit"
|
||||||
|
version = "0.7.7"
|
||||||
|
source = "git+https://github.com/kinode-dao/kit?rev=9c94b4b#9c94b4bd3f2a9dc2eabb2da9bc2ef5e6eb07af9d"
|
||||||
|
dependencies = [
|
||||||
|
"alloy 0.1.4",
|
||||||
|
"alloy-sol-macro",
|
||||||
|
"alloy-sol-types",
|
||||||
|
"anyhow",
|
||||||
|
"base64 0.21.7",
|
||||||
|
"cargo_metadata",
|
||||||
|
"clap",
|
||||||
|
"color-eyre",
|
||||||
|
"dirs 5.0.1",
|
||||||
|
"fs-err",
|
||||||
|
"git2",
|
||||||
|
"hex",
|
||||||
|
"kinode_process_lib 0.9.2",
|
||||||
|
"nix 0.27.1",
|
||||||
|
"regex",
|
||||||
|
"reqwest",
|
||||||
|
"rpassword",
|
||||||
|
"semver 1.0.23",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sha2",
|
||||||
|
"tokio",
|
||||||
|
"toml",
|
||||||
|
"tracing",
|
||||||
|
"tracing-appender",
|
||||||
|
"tracing-error",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"walkdir",
|
||||||
|
"wit-bindgen",
|
||||||
|
"zip 0.6.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kns_indexer"
|
name = "kns_indexer"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@ -3823,7 +3860,7 @@ name = "lib"
|
|||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy 0.2.1",
|
"alloy 0.2.1",
|
||||||
"kit",
|
"kit 0.7.6",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"ring",
|
"ring",
|
||||||
|
@ -14,6 +14,7 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.71"
|
||||||
|
sha2 = "0.10.8"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
simulation-mode = []
|
simulation-mode = []
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use std::path::PathBuf;
|
use std::io::Read;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use sha2::Digest;
|
||||||
|
|
||||||
const CANONICAL_PACKAGES_ZIP_PATH: &str = "../target/packages.zip";
|
const CANONICAL_PACKAGES_ZIP_PATH: &str = "../target/packages.zip";
|
||||||
|
|
||||||
@ -8,6 +11,23 @@ macro_rules! p {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compute_hash(file_path: &Path) -> anyhow::Result<String> {
|
||||||
|
let input_file = std::fs::File::open(file_path)?;
|
||||||
|
let mut reader = std::io::BufReader::new(input_file);
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
let mut buffer = [0; 1024]; // buffer for chunks of the file
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let count = reader.read(&mut buffer)?;
|
||||||
|
if count == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
hasher.update(&buffer[..count]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("{:x}", hasher.finalize()))
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let path_to_packages_zip = match std::env::var("PATH_TO_PACKAGES_ZIP") {
|
let path_to_packages_zip = match std::env::var("PATH_TO_PACKAGES_ZIP") {
|
||||||
Ok(env_var) => env_var,
|
Ok(env_var) => env_var,
|
||||||
@ -31,7 +51,24 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let path_to_packages_zip_path = PathBuf::from(&path_to_packages_zip).canonicalize()?;
|
let path_to_packages_zip_path = PathBuf::from(&path_to_packages_zip).canonicalize()?;
|
||||||
let canonical_packages_zip_path = PathBuf::from(CANONICAL_PACKAGES_ZIP_PATH).canonicalize()?;
|
let canonical_packages_zip_path = PathBuf::from(CANONICAL_PACKAGES_ZIP_PATH).canonicalize()?;
|
||||||
if path_to_packages_zip_path != canonical_packages_zip_path {
|
if path_to_packages_zip_path != canonical_packages_zip_path {
|
||||||
std::fs::copy(path_to_packages_zip_path, CANONICAL_PACKAGES_ZIP_PATH)?;
|
std::fs::copy(&path_to_packages_zip_path, &canonical_packages_zip_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build core frontends
|
||||||
|
let pwd = std::env::current_dir()?;
|
||||||
|
let core_frontends = vec![
|
||||||
|
"src/register-ui",
|
||||||
|
];
|
||||||
|
|
||||||
|
// for each frontend, execute build.sh
|
||||||
|
for frontend in core_frontends {
|
||||||
|
let status = std::process::Command::new("sh")
|
||||||
|
.current_dir(pwd.join(frontend))
|
||||||
|
.arg("./build.sh")
|
||||||
|
.status()?;
|
||||||
|
if !status.success() {
|
||||||
|
return Err(anyhow::anyhow!("Failed to build frontend: {}", frontend));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let version = if let Ok(version) = std::env::var("DOCKER_BUILD_IMAGE_VERSION") {
|
let version = if let Ok(version) = std::env::var("DOCKER_BUILD_IMAGE_VERSION") {
|
||||||
@ -42,5 +79,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
};
|
};
|
||||||
println!("cargo:rustc-env=DOCKER_BUILD_IMAGE_VERSION={version}");
|
println!("cargo:rustc-env=DOCKER_BUILD_IMAGE_VERSION={version}");
|
||||||
|
|
||||||
|
let packages_zip_hash = compute_hash(&canonical_packages_zip_path)?;
|
||||||
|
println!("cargo:rustc-env=PACKAGES_ZIP_HASH={packages_zip_hash}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,17 @@ pub const MULTICALL_ADDRESS: &str = "0xcA11bde05977b3631167028862bE2a173976CA11"
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
// embed values in binary for inspection without running & print on boot
|
||||||
|
// e.g., to inspect without running, use
|
||||||
|
// ```bash
|
||||||
|
// strings kinode | grep DOCKER_BUILD_IMAGE_VERSION
|
||||||
|
// ```
|
||||||
println!(
|
println!(
|
||||||
"\nDOCKER_BUILD_IMAGE_VERSION: {}\n",
|
"\nDOCKER_BUILD_IMAGE_VERSION: {}\nPACKAGES_ZIP_HASH: {}\n",
|
||||||
env!("DOCKER_BUILD_IMAGE_VERSION")
|
env!("DOCKER_BUILD_IMAGE_VERSION"),
|
||||||
|
env!("PACKAGES_ZIP_HASH"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let app = build_command();
|
let app = build_command();
|
||||||
|
|
||||||
let matches = app.get_matches();
|
let matches = app.get_matches();
|
||||||
|
@ -35,30 +35,23 @@ def build_and_move(feature, tmp_dir, architecture, os_name):
|
|||||||
subprocess.run(
|
subprocess.run(
|
||||||
["cargo", "run", "-p", "build_packages", "--", "--features", feature],
|
["cargo", "run", "-p", "build_packages", "--", "--features", feature],
|
||||||
check=True,
|
check=True,
|
||||||
stdout=subprocess.PIPE,
|
#stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
#stderr=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["cargo", "build", "--release", "-p", "kinode", "--features", feature],
|
["cargo", "build", "--release", "-p", "kinode", "--features", feature],
|
||||||
check=True,
|
check=True,
|
||||||
env=release_env,
|
env=release_env,
|
||||||
stdout=subprocess.PIPE,
|
#stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
#stderr=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
zip_name = f"{zip_prefix}-{feature}.zip"
|
zip_name = f"{zip_prefix}-{feature}.zip"
|
||||||
else:
|
else:
|
||||||
subprocess.run(
|
subprocess.run(["cargo", "run", "-p", "build_packages"], check=True)
|
||||||
["cargo", "run", "-p", "build_packages"],
|
|
||||||
check=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
)
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["cargo", "build", "--release", "-p", "kinode"],
|
["cargo", "build", "--release", "-p", "kinode"],
|
||||||
check=True,
|
check=True,
|
||||||
env=release_env,
|
env=release_env,
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
)
|
)
|
||||||
zip_name = f"{zip_prefix}.zip"
|
zip_name = f"{zip_prefix}.zip"
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
anyhow = "1.0.71"
|
anyhow = "1.0.71"
|
||||||
clap = "4"
|
clap = "4"
|
||||||
fs-err = "2.11"
|
fs-err = "2.11"
|
||||||
kit = { git = "https://github.com/kinode-dao/kit", tag = "v0.7.6" }
|
kit = { git = "https://github.com/kinode-dao/kit", rev = "9c94b4b" }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
tokio = "1.28"
|
tokio = "1.28"
|
||||||
walkdir = "2.4"
|
walkdir = "2.4"
|
||||||
|
@ -60,6 +60,7 @@ fn build_and_zip_package(
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow::anyhow!("{:?}", e))?;
|
.map_err(|e| anyhow::anyhow!("{:?}", e))?;
|
||||||
|
Loading…
Reference in New Issue
Block a user