use std::{env, fs, sync::Mutex};
use crate::cargo_toml::CargoToml;
use lazy_static::lazy_static;
use tinyget;
pub const X64_TARGET: &str = "x86_64-unknown-linux-gnu";
pub const ARM64_TARGET: &str = "aarch64-unknown-linux-gnu";
pub const QEMU_IMAGE: &str = "hub.cloud.ctripcorp.com/devops/multiarch-qemu-user-static";
lazy_static! {
pub static ref IBUILD_TOML: Mutex<CargoToml> = {
let ibuild_toml = match tinyget::get(
"https://pages.ares.ctripcorp.com/rust/ibuild/ibuild.toml",
)
.send()
{
Ok(resp) => {
let file = env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("ibuild.toml");
fs::write(&file, resp.into_bytes()).expect("Write ibuild.toml Failed");
CargoToml::load(&file).expect("Load ibuild.toml Failed")
}
Err(_) => {
panic!("This is an internal enterprise application and needs to be on the company intranet to be used.")
}
};
Mutex::new(ibuild_toml)
};
pub static ref CENTOS_X64_IMAGE: String = IBUILD_TOML
.lock()
.unwrap()
.get_string(&vec!["target", X64_TARGET, "centos_image"], None)
.expect("Invalid Image");
pub static ref UBUNTU_X64_IMAGE: String = IBUILD_TOML
.lock()
.unwrap()
.get_string(&vec!["target", X64_TARGET, "ubuntu_image"], None)
.expect("Invalid Image");
pub static ref ALMA_X64_IMAGE: String = IBUILD_TOML
.lock()
.unwrap()
.get_string(&vec!["target", X64_TARGET, "alma_image"], None)
.expect("Invalid Image");
pub static ref CENTOS_ARM64_IMAGE: String = IBUILD_TOML
.lock()
.unwrap()
.get_string(&vec!["target", ARM64_TARGET, "centos_image"], None)
.expect("Invalid Image");
pub static ref ALMA_ARM64_IMAGE: String = IBUILD_TOML
.lock()
.unwrap()
.get_string(&vec!["target", ARM64_TARGET, "alma_image"], None)
.expect("Invalid Image");
}