diff --git a/tugboat/src/route/container.rs b/tugboat/src/route/container.rs index 3cbdc30..ff1c54b 100644 --- a/tugboat/src/route/container.rs +++ b/tugboat/src/route/container.rs @@ -904,3 +904,27 @@ pub(in crate::route) async fn start_container( Ok(Redirect::to("/containers")) } + +#[derive(thiserror::Error, Debug)] +#[error("Error deleting container: {0}")] +pub(in crate::route) struct DeleteError(#[from] bollard::errors::Error); + +impl IntoResponse for DeleteError { + fn into_response(self) -> axum::response::Response { + tracing::error!("Error deleting container: {:?}", self); + StatusCode::INTERNAL_SERVER_ERROR.into_response() + } +} + +pub(in crate::route) async fn delete( + State(state): State, + Path(container_id): Path>, +) -> Result { + tracing::debug!("Deleting container {container_id}"); + state + .docker + .remove_container(&container_id, None::) + .await?; + + Ok(Redirect::to("/containers")) +} diff --git a/tugboat/src/route/mod.rs b/tugboat/src/route/mod.rs index 57af7a9..625bb3c 100644 --- a/tugboat/src/route/mod.rs +++ b/tugboat/src/route/mod.rs @@ -49,7 +49,8 @@ pub(super) fn get_for_humans() -> Router { get(container::environment::get_variables).post(container::environment::update), ) .route("/:container_id/stop", post(container::stop_container)) - .route("/:container_id/start", post(container::start_container)); + .route("/:container_id/start", post(container::start_container)) + .route("/:container_id/delete", post(container::delete)); Router::new() .route("/", get(|| async { Redirect::to("/containers") })) diff --git a/tugboat/templates/container/index.html b/tugboat/templates/container/index.html index 9eef0f2..11f3772 100644 --- a/tugboat/templates/container/index.html +++ b/tugboat/templates/container/index.html @@ -35,7 +35,6 @@ -