diff --git a/crates/bin/pd/build.rs b/crates/bin/pd/build.rs index 9cb12b66c3..14a1312230 100644 --- a/crates/bin/pd/build.rs +++ b/crates/bin/pd/build.rs @@ -1,12 +1,50 @@ +use std::io::Read; use std::path::Path; use anyhow::Context; fn main() -> anyhow::Result<()> { + check_frontend_asset_zipfiles()?; setup_testnet_config()?; Ok(()) } +// Check that the zip files for bundled frontend code are functional. +// If git-lfs is not configured on the build host, the zip files will +// be plaintext lfs pointer files. +fn check_frontend_asset_zipfiles() -> anyhow::Result<()> { + // Declare a minimum filesize, below which we'll assume the zip file is + // actually a git-lfs pointer. + const MINIMUM_FILESIZE_BYTES: usize = 500; + // Build paths to the zip files in the local build env. + let zipfiles = vec![ + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../assets/minifront.zip"), + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../assets/node-status.zip"), + ]; + for zipfile in zipfiles { + let mut bytes = Vec::new(); + let f = std::fs::File::open(&zipfile).context(format!( + "failed to open zip file of frontend code: {}", + &zipfile.display() + ))?; + let mut reader = std::io::BufReader::new(f); + reader.read_to_end(&mut bytes).context(format!( + "failed to read zip file of frontend code: {}", + zipfile.display() + ))?; + if bytes.len() < MINIMUM_FILESIZE_BYTES { + anyhow::bail!( + format!( + "asset zip file {} is smaller than {} bytes; install git-lfs, run 'git lfs pull', and retry the build", + zipfile.display(), + MINIMUM_FILESIZE_BYTES + ) + ); + } + } + Ok(()) +} + // Set build-time environment variables to point to the latest testnet's config files. fn setup_testnet_config() -> anyhow::Result<()> { // Get the path to the testnets directory, in a platform-agnostic manner