mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 19:59:46 -05:00
delete repo when deleting build
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use anyhow::anyhow;
|
||||
use anyhow::{anyhow, Context};
|
||||
use async_timing_util::unix_timestamp_ms;
|
||||
use axum::{
|
||||
extract::Path,
|
||||
@@ -102,7 +102,10 @@ async fn delete_one(
|
||||
}
|
||||
let start_ts = unix_timestamp_ms() as i64;
|
||||
let server = db.get_server(&build.server_id).await?;
|
||||
// clean up anything left by the build (delete the repo)
|
||||
let delete_repo_log = periphery
|
||||
.delete_repo(&server, &build.name)
|
||||
.await
|
||||
.context("failed at deleting repo")?;
|
||||
db.builds.delete_one(&id).await?;
|
||||
let update = Update {
|
||||
target: UpdateTarget::System,
|
||||
@@ -111,7 +114,7 @@ async fn delete_one(
|
||||
end_ts: Some(unix_timestamp_ms() as i64),
|
||||
operator: user.id.clone(),
|
||||
log: vec![
|
||||
// log,
|
||||
delete_repo_log,
|
||||
Log::simple(format!(
|
||||
"deleted build {} on server {}",
|
||||
build.name, server.name
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use helpers::git::CloneArgs;
|
||||
use serde_json::json;
|
||||
use types::{Log, Server};
|
||||
|
||||
use crate::PeripheryClient;
|
||||
|
||||
impl PeripheryClient {
|
||||
pub async fn clone(
|
||||
pub async fn clone_repo(
|
||||
&self,
|
||||
server: &Server,
|
||||
clone_args: impl Into<CloneArgs>,
|
||||
@@ -12,4 +13,9 @@ impl PeripheryClient {
|
||||
let clone_args: CloneArgs = clone_args.into();
|
||||
self.post_json(server, "/git/clone", &clone_args).await
|
||||
}
|
||||
|
||||
pub async fn delete_repo(&self, server: &Server, build_name: &str) -> anyhow::Result<Log> {
|
||||
self.post_json(server, "/git/delete", &json!({ "name": build_name }))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,6 +250,17 @@ impl Log {
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(msg: String) -> Log {
|
||||
let ts = unix_timestamp_ms() as i64;
|
||||
Log {
|
||||
stderr: msg,
|
||||
start_ts: ts,
|
||||
end_ts: ts,
|
||||
success: false,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
||||
@@ -24,4 +24,4 @@ impl Permissioned for Server {
|
||||
fn permissions_map(&self) -> &PermissionsMap {
|
||||
&self.permissions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,30 +27,6 @@ pub fn router() -> Router {
|
||||
response!(Json(containers))
|
||||
}),
|
||||
)
|
||||
// .route(
|
||||
// "/stats/:name",
|
||||
// get(
|
||||
// |Extension(dc): DockerExtension, Path(Container { name }): Path<Container>| async move {
|
||||
// let stats = dc
|
||||
// .get_container_stats(&name)
|
||||
// .await
|
||||
// .map_err(handle_anyhow_error)?;
|
||||
// response!(Json(stats))
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .route(
|
||||
// "/stats/list",
|
||||
// get(
|
||||
// |Extension(dc): DockerExtension| async move {
|
||||
// let stats_list = dc
|
||||
// .get_container_stats_list()
|
||||
// .await
|
||||
// .map_err(handle_anyhow_error)?;
|
||||
// response!(Json(stats_list))
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
.route(
|
||||
"/stats/:name",
|
||||
get(|Path(c): Path<Container>| async move {
|
||||
@@ -100,5 +76,29 @@ pub fn router() -> Router {
|
||||
"/prune",
|
||||
post(|| async { Json(docker::prune_containers().await) }),
|
||||
)
|
||||
// .route(
|
||||
// "/stats/:name",
|
||||
// get(
|
||||
// |Extension(dc): DockerExtension, Path(Container { name }): Path<Container>| async move {
|
||||
// let stats = dc
|
||||
// .get_container_stats(&name)
|
||||
// .await
|
||||
// .map_err(handle_anyhow_error)?;
|
||||
// response!(Json(stats))
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .route(
|
||||
// "/stats/list",
|
||||
// get(
|
||||
// |Extension(dc): DockerExtension| async move {
|
||||
// let stats_list = dc
|
||||
// .get_container_stats_list()
|
||||
// .await
|
||||
// .map_err(handle_anyhow_error)?;
|
||||
// response!(Json(stats_list))
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
.layer(DockerClient::extension())
|
||||
}
|
||||
|
||||
@@ -1,23 +1,40 @@
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use axum::{routing::post, Extension, Json, Router};
|
||||
use helpers::{
|
||||
git::{self, CloneArgs},
|
||||
handle_anyhow_error,
|
||||
handle_anyhow_error, to_monitor_name,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use types::{GithubToken, Log, PeripheryConfig};
|
||||
|
||||
use crate::PeripheryConfigExtension;
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new().route(
|
||||
"/clone",
|
||||
post(|config, clone_args| async move {
|
||||
clone(config, clone_args).await.map_err(handle_anyhow_error)
|
||||
}),
|
||||
)
|
||||
#[derive(Deserialize)]
|
||||
pub struct DeleteRepoBody {
|
||||
name: String,
|
||||
}
|
||||
|
||||
async fn clone(
|
||||
pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route(
|
||||
"/clone",
|
||||
post(|config, clone_args| async move {
|
||||
clone_repo(config, clone_args)
|
||||
.await
|
||||
.map_err(handle_anyhow_error)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/delete",
|
||||
post(|config, body| async move {
|
||||
delete_repo(config, body).await.map_err(handle_anyhow_error)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async fn clone_repo(
|
||||
Extension(config): PeripheryConfigExtension,
|
||||
Json(clone_args): Json<CloneArgs>,
|
||||
) -> anyhow::Result<Json<Vec<Log>>> {
|
||||
@@ -26,6 +43,22 @@ async fn clone(
|
||||
Ok(Json(logs))
|
||||
}
|
||||
|
||||
async fn delete_repo(
|
||||
Extension(config): PeripheryConfigExtension,
|
||||
Json(DeleteRepoBody { name }): Json<DeleteRepoBody>,
|
||||
) -> anyhow::Result<Json<Log>> {
|
||||
let mut repo_dir = PathBuf::from_str(&config.repo_dir)?;
|
||||
let name = to_monitor_name(&name);
|
||||
repo_dir.push(&name);
|
||||
let destination = repo_dir.display().to_string();
|
||||
let deleted = std::fs::remove_dir_all(destination);
|
||||
let log = match deleted {
|
||||
Ok(_) => Log::simple(format!("deleted repo {name}")),
|
||||
Err(_) => Log::simple(format!("no repo at {name} to delete")),
|
||||
};
|
||||
Ok(Json(log))
|
||||
}
|
||||
|
||||
fn get_github_token(
|
||||
github_account: &Option<String>,
|
||||
config: &PeripheryConfig,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use std::{
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use axum::{routing::get, Extension, Json, Router};
|
||||
use sysinfo::{CpuExt, DiskExt, NetworkExt, ProcessExt, ProcessRefreshKind, SystemExt};
|
||||
|
||||
Reference in New Issue
Block a user