use crate::bootstrap::state::AppState;
use bollard::{
container::RemoveContainerOptions, image::RemoveImageOptions, volume::RemoveVolumeOptions,
};
use shared::Response as RpResponse;
pub async fn remove_container(state: AppState, id: String) -> RpResponse {
let opts = RemoveContainerOptions {
v: true,
..Default::default()
};
match state.docker.inner.remove_container(&id, Some(opts)).await {
Ok(()) => {
state.docker_cache.df.invalidate().await;
state.docker_cache.networks.invalidate().await;
RpResponse::Ok
}
Err(e) => RpResponse::err("DockerError", e.to_string()),
}
}
pub async fn remove_image(state: AppState, id: String) -> RpResponse {
let opts = RemoveImageOptions {
force: false,
noprune: false,
};
match state.docker.inner.remove_image(&id, Some(opts), None).await {
Ok(_) => {
state.docker_cache.df.invalidate().await;
RpResponse::Ok
}
Err(e) => RpResponse::err("DockerError", e.to_string()),
}
}
pub async fn remove_volume(state: AppState, name: String) -> RpResponse {
match state
.docker
.inner
.remove_volume(&name, Some(RemoveVolumeOptions { force: false }))
.await
{
Ok(()) => {
state.docker_cache.df.invalidate().await;
RpResponse::Ok
}
Err(e) => RpResponse::err("DockerError", e.to_string()),
}
}
pub async fn remove_network(state: AppState, id: String) -> RpResponse {
match state.docker.inner.remove_network(&id).await {
Ok(()) => {
state.docker_cache.networks.invalidate().await;
RpResponse::Ok
}
Err(e) => RpResponse::err("DockerError", e.to_string()),
}
}