| 2483 | } |
| 2484 | |
| 2485 | fn split_initdb_binary_package( |
| 2486 | initdb_module: &Path, |
| 2487 | postgres_module: &Path, |
| 2488 | ) -> Result<BinaryPackage> { |
| 2489 | let initdb_wasm = |
| 2490 | fs::read(initdb_module).with_context(|| format!("read {}", initdb_module.display()))?; |
| 2491 | let postgres_wasm = |
| 2492 | fs::read(postgres_module).with_context(|| format!("read {}", postgres_module.display()))?; |
| 2493 | |
| 2494 | let mut package_hash = Sha256::new(); |
| 2495 | package_hash.update(b"pglite-oxide-split-initdb-package-v1\n"); |
| 2496 | package_hash.update(&initdb_wasm); |
| 2497 | package_hash.update(&postgres_wasm); |
| 2498 | let package_hash: [u8; 32] = package_hash.finalize().into(); |
| 2499 | let package_id = PackageId::Hash(PackageHash::from_sha256_bytes(package_hash)); |
| 2500 | |
| 2501 | Ok(BinaryPackage { |
| 2502 | id: package_id.clone(), |
| 2503 | package_ids: vec![package_id.clone()], |
| 2504 | when_cached: None, |
| 2505 | entrypoint_cmd: Some("initdb".to_owned()), |
| 2506 | hash: Default::default(), |
| 2507 | package_mounts: None, |
| 2508 | commands: vec![ |
| 2509 | split_initdb_command("initdb", initdb_wasm, &package_id), |
| 2510 | split_initdb_command("postgres", postgres_wasm, &package_id), |
| 2511 | ], |
| 2512 | uses: Vec::new(), |
| 2513 | file_system_memory_footprint: 0, |
| 2514 | additional_host_mapped_directories: Vec::new(), |
| 2515 | }) |
| 2516 | } |
| 2517 | |
| 2518 | fn split_initdb_command(name: &str, wasm: Vec<u8>, package_id: &PackageId) -> BinaryPackageCommand { |
| 2519 | let hash = ModuleHash::new(&wasm); |