use std::sync::OnceLock;
use anyhow::Result;
use wildfly_meta::{FeaturePackRegistry, WildFlyImageRegistry};
static IMAGES: OnceLock<WildFlyImageRegistry> = OnceLock::new();
static PACKS: OnceLock<FeaturePackRegistry> = OnceLock::new();
const RESOLUTION_HINT: &str = "Run 'mgt update' to download the configuration files";
pub async fn init_registries() -> Result<()> {
tokio::task::spawn_blocking(|| {
let images = WildFlyImageRegistry::load_or_update(RESOLUTION_HINT)?;
let packs = FeaturePackRegistry::load_or_update(RESOLUTION_HINT)?;
IMAGES.set(images).ok();
PACKS.set(packs).ok();
Ok(())
})
.await?
}
#[cfg(test)]
pub fn init_registries_sync() -> Result<()> {
let images = WildFlyImageRegistry::load_or_update(RESOLUTION_HINT)?;
let packs = FeaturePackRegistry::load_or_update(RESOLUTION_HINT)?;
IMAGES.set(images).ok();
PACKS.set(packs).ok();
Ok(())
}
pub fn images_registry() -> &'static WildFlyImageRegistry {
IMAGES.get().expect("WildFlyImageRegistry not initialized")
}
pub fn packs_registry() -> &'static FeaturePackRegistry {
PACKS.get().expect("FeaturePackRegistry not initialized")
}