mirror of
https://github.com/moghtech/komodo.git
synced 2026-07-29 04:03:51 -05:00
rename deployment func
This commit is contained in:
@@ -4,7 +4,7 @@ use axum::{
|
||||
routing::{get, post},
|
||||
Extension, Json, Router,
|
||||
};
|
||||
use helpers::{handle_anyhow_error, to_monitor_name};
|
||||
use helpers::handle_anyhow_error;
|
||||
use serde::Deserialize;
|
||||
use types::{Deployment, Log};
|
||||
|
||||
@@ -21,6 +21,12 @@ struct Container {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct RenameContainerBody {
|
||||
curr_name: String,
|
||||
new_name: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct GetLogQuery {
|
||||
tail: Option<u64>, // default is 1000 if not passed
|
||||
@@ -67,20 +73,26 @@ pub fn router() -> Router {
|
||||
)
|
||||
.route(
|
||||
"/start",
|
||||
post(|Json(container): Json<Container>| async move {
|
||||
Json(docker::start_container(&to_monitor_name(&container.name)).await)
|
||||
post(|container: Json<Container>| async move {
|
||||
Json(docker::start_container(&container.name).await)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/stop",
|
||||
post(|Json(container): Json<Container>| async move {
|
||||
Json(docker::stop_container(&to_monitor_name(&container.name)).await)
|
||||
post(|container: Json<Container>| async move {
|
||||
Json(docker::stop_container(&container.name).await)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/remove",
|
||||
post(|Json(container): Json<Container>| async move {
|
||||
Json(docker::stop_and_remove_container(&to_monitor_name(&container.name)).await)
|
||||
post(|container: Json<Container>| async move {
|
||||
Json(docker::stop_and_remove_container(&container.name).await)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/rename",
|
||||
post(|body: Json<RenameContainerBody>| async move {
|
||||
Json(docker::rename_container(&body.curr_name, &body.new_name).await)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
|
||||
@@ -69,6 +69,13 @@ pub async fn stop_and_remove_container(container_name: &str) -> Log {
|
||||
run_monitor_command("docker stop and remove", command).await
|
||||
}
|
||||
|
||||
pub async fn rename_container(curr_name: &str, new_name: &str) -> Log {
|
||||
let curr = to_monitor_name(curr_name);
|
||||
let new = to_monitor_name(new_name);
|
||||
let command = format!("docker rename {curr} {new}");
|
||||
run_monitor_command("docker rename", command).await
|
||||
}
|
||||
|
||||
pub async fn pull_image(image: &str) -> Log {
|
||||
let command = format!("docker pull {image}");
|
||||
run_monitor_command("docker pull", command).await
|
||||
|
||||
Reference in New Issue
Block a user