40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
use std::fs;
|
|
use std::path::PathBuf;
|
|
use serde::{Serialize, Deserialize};
|
|
use rust_util::util_file;
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct DockerBuildConfig {
|
|
pub image: Option<String>,
|
|
pub mirror: Option<String>,
|
|
}
|
|
|
|
pub fn load_docker_build_config_or_default() -> DockerBuildConfig {
|
|
load_docker_build_config().unwrap_or_else(|| {
|
|
DockerBuildConfig {
|
|
image: Some("rust".into()),
|
|
mirror: None,
|
|
}
|
|
})
|
|
}
|
|
|
|
pub fn load_docker_build_config() -> Option<DockerBuildConfig> {
|
|
let config = find_docker_build_config_file()?;
|
|
success!("Find config file: {:?}", config);
|
|
let config_content = fs::read_to_string(&config).map_err(|e| {
|
|
failure!("Read config file: {:?}, failed: {}", config, e);
|
|
e
|
|
}).ok()?;
|
|
serde_json::from_str(&config_content).map_err(|e| {
|
|
failure!("Parse config file: {:?}, failed: {}", config, e);
|
|
e
|
|
}).ok()
|
|
}
|
|
|
|
fn find_docker_build_config_file() -> Option<PathBuf> {
|
|
util_file::read_config(None, &vec![
|
|
// "dockerbuild.json".into(),
|
|
"~/.dockerbuild.json".into(),
|
|
"/etc/dockerbuild.json".into(),
|
|
])
|
|
} |