use crate::commands::api::build_api_prod; use crate::commands::client::build_client_prod; use crate::commands::server::build_server_prod; use crate::ninja::exec; use std::error::Error; use std::path::PathBuf; use std::process::Command; fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box> { // compile the various thingies if img == "server" { build_server_prod(vec![], root.clone())?; } else if img == "api" { build_api_prod(vec![], root.clone())?; } else { build_client_prod(vec![], root.clone())? } let git_commit_id = String::from_utf8( Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .current_dir(root) .output() .unwrap() .stdout, ) .unwrap() .replace('\n', ""); exec( "docker", root, vec![ "buildx", "build", "-f", root.join(format!("{}.Dockerfile", img)).to_str().unwrap(), "-t", &format!( "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}", img, git_commit_id ), root.to_str().unwrap(), ] .iter() .map(|u| u.to_string()) .collect(), )?; exec( "docker", root, vec![ "buildx", "build", "-f", root.join(format!("{}.Dockerfile", img)).to_str().unwrap(), "-t", &format!( "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}", img, channel ), root.to_str().unwrap(), ] .iter() .map(|u| u.to_string()) .collect(), )?; exec( "docker", root, vec![ "push", &format!( "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}", img, git_commit_id ), ] .iter() .map(|u| u.to_string()) .collect(), )?; exec( "docker", root, vec![ "push", &format!( "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}", img, channel ), ] .iter() .map(|u| u.to_string()) .collect(), )?; Ok(()) } pub fn build_docker_api(_: Vec, root: PathBuf) -> Result<(), Box> { _build("api", "bleeding", &root) } pub fn build_docker_server(_: Vec, root: PathBuf) -> Result<(), Box> { _build("server", "bleeding", &root) } pub fn build_docker_web(_: Vec, root: PathBuf) -> Result<(), Box> { _build("web", "bleeding", &root) } pub fn build_docker(_a: Vec, root: PathBuf) -> Result<(), Box> { build_docker_api(_a.clone(), root.clone())?; build_docker_server(_a.clone(), root.clone())?; build_docker_web(_a, root) } pub fn build_docker_api_beta(_: Vec, root: PathBuf) -> Result<(), Box> { _build("api", "beta", &root) } pub fn build_docker_server_beta(_: Vec, root: PathBuf) -> Result<(), Box> { _build("server", "beta", &root) } pub fn build_docker_web_beta(_: Vec, root: PathBuf) -> Result<(), Box> { _build("web", "beta", &root) } pub fn build_docker_beta(_a: Vec, root: PathBuf) -> Result<(), Box> { build_docker_api_beta(_a.clone(), root.clone())?; build_docker_server_beta(_a.clone(), root.clone())?; build_docker_web_beta(_a, root) } pub fn build_docker_api_stable(_: Vec, root: PathBuf) -> Result<(), Box> { _build("api", "stable", &root) } pub fn build_docker_server_stable(_: Vec, root: PathBuf) -> Result<(), Box> { _build("server", "stable", &root) } pub fn build_docker_web_stable(_: Vec, root: PathBuf) -> Result<(), Box> { _build("web", "stable", &root) } pub fn build_docker_stable(_a: Vec, root: PathBuf) -> Result<(), Box> { build_docker_api_stable(_a.clone(), root.clone())?; build_docker_server_stable(_a.clone(), root.clone())?; build_docker_web_stable(_a, root) }