mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 19:59:46 -05:00
fix build and deploy
This commit is contained in:
@@ -367,7 +367,10 @@ impl State {
|
||||
|
||||
update.id = self.add_update(update.clone()).await?;
|
||||
|
||||
let deploy_log = self.periphery.deploy(&server, &deployment).await?;
|
||||
let deploy_log = match self.periphery.deploy(&server, &deployment).await {
|
||||
Ok(log) => log,
|
||||
Err(e) => Log::error("deploy container", format!("{e:#?}"))
|
||||
};
|
||||
|
||||
update.success = deploy_log.success;
|
||||
update.logs.push(deploy_log);
|
||||
|
||||
@@ -30,17 +30,13 @@ impl State {
|
||||
continue;
|
||||
}
|
||||
for (server, res) in servers.unwrap() {
|
||||
if let Err(e) = res {
|
||||
if e.to_string().contains("error trying to connect") {
|
||||
if let Some(slack) = &self.slack {
|
||||
let (header, info) = generate_unreachable_message(&server);
|
||||
let res = slack.send_message_with_header(&header, info.clone()).await;
|
||||
if let Err(e) = res {
|
||||
eprintln!("failed to send message to slack: {e} | header: {header} | info: {info:?}")
|
||||
}
|
||||
if let Err(_) = res {
|
||||
if let Some(slack) = &self.slack {
|
||||
let (header, info) = generate_unreachable_message(&server);
|
||||
let res = slack.send_message_with_header(&header, info.clone()).await;
|
||||
if let Err(e) = res {
|
||||
eprintln!("failed to send message to slack: {e} | header: {header} | info: {info:?}")
|
||||
}
|
||||
} else {
|
||||
println!("failed to get stats from {}: {e:?}", server.name);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use axum::{routing::post, Extension, Json, Router};
|
||||
use helpers::{docker, handle_anyhow_error};
|
||||
use helpers::docker;
|
||||
use tokio::sync::Mutex;
|
||||
use types::{Build, Log, PERIPHERY_BUILDER_BUSY};
|
||||
use types::{Build, Log};
|
||||
|
||||
use crate::{helpers::get_docker_token, PeripheryConfigExtension};
|
||||
|
||||
@@ -14,11 +13,7 @@ pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route(
|
||||
"/",
|
||||
post(|config, busy, build| async move {
|
||||
build_image(config, busy, build)
|
||||
.await
|
||||
.map_err(handle_anyhow_error)
|
||||
}),
|
||||
post(|config, busy, build| async move { build_image(config, busy, build).await }),
|
||||
)
|
||||
.layer(Extension(Arc::new(Mutex::new(false))))
|
||||
}
|
||||
@@ -27,7 +22,7 @@ async fn build_image(
|
||||
Extension(config): PeripheryConfigExtension,
|
||||
Extension(busy): BusyExtension,
|
||||
Json(build): Json<Build>,
|
||||
) -> anyhow::Result<Json<Vec<Log>>> {
|
||||
) -> Json<Vec<Log>> {
|
||||
let is_busy = {
|
||||
let mut lock = busy.lock().await;
|
||||
if *lock {
|
||||
@@ -38,15 +33,21 @@ async fn build_image(
|
||||
}
|
||||
};
|
||||
if is_busy {
|
||||
return Err(anyhow!("{PERIPHERY_BUILDER_BUSY}"));
|
||||
return Json(vec![Log::error(
|
||||
"build",
|
||||
"builder busy, try again when other build finishes".to_string(),
|
||||
)]);
|
||||
}
|
||||
let res = async {
|
||||
let docker_token = get_docker_token(&build.docker_account, &config)?;
|
||||
let logs = docker::build(&build, config.repo_dir.clone(), docker_token).await?;
|
||||
anyhow::Ok(logs)
|
||||
}
|
||||
.await;
|
||||
let logs = match get_docker_token(&build.docker_account, &config) {
|
||||
Ok(docker_token) => {
|
||||
match docker::build(&build, config.repo_dir.clone(), docker_token).await {
|
||||
Ok(logs) => logs,
|
||||
Err(e) => vec![Log::error("build", format!("{e:#?}"))],
|
||||
}
|
||||
}
|
||||
Err(e) => vec![Log::error("build", format!("{e:#?}"))],
|
||||
};
|
||||
let mut lock = busy.lock().await;
|
||||
*lock = false;
|
||||
res.map(|logs| Json(logs))
|
||||
Json(logs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user