Skip to content

Commit

Permalink
Add clear images build cache button
Browse files Browse the repository at this point in the history
Closes: #47
  • Loading branch information
vv9k committed Dec 4, 2021
1 parent 18103cb commit 14ea11d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- Add containers prune button to remove all stopped containers
- Add a way to follow container logs, the logs are now paginated
- Make container and image ids open their respective page with details
- Add a button to clear images build cache
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/app/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ impl App {
"Are you sure you want to prune unused images? This will delete all images not in use by a container.",
));
}
if ui.button("clear cache").clicked() {
self.popups.push_back(ui::ActionPopup::new(
EventRequest::Image(ImageEvent::ClearCache),
"Clear images cache",
"Are you sure you want to clear image build cache?",
));
}
});
}

Expand Down
24 changes: 24 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,30 @@ impl App {
}
Err(e) => self.add_error(e),
},
ClearCache(res) => match res {
Ok(info) => {
let deleted = info
.caches_deleted
.map(|caches| {
caches
.into_iter()
.fold("Deleted:\n".to_string(), |mut acc, c| {
acc.push_str(" - ");
acc.push_str(&c);
acc.push('\n');
acc
})
})
.unwrap_or_default();
self.add_notification(format!(
"Space reclaimed: {}\n\n{}",
crate::conv_b(info.space_reclaimed as u64),
deleted
));
self.send_event_notify(EventRequest::SystemDataUsage);
}
Err(e) => self.add_error(e),
},
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::worker::{Logs, RunningContainerStats};

use docker_api::api::{
ContainerCreateOpts, ContainerDetails, ContainerId, ContainerInfo, ContainerListOpts,
ContainersPruneInfo, DataUsage, DeleteStatus, DistributionInspectInfo, History,
ImageBuildChunk, ImageDetails, ImageId, ImageInfo, ImageListOpts, ImagesPruneInfo, Info,
RegistryAuth, SearchResult, Version,
ClearCacheInfo, ContainerCreateOpts, ContainerDetails, ContainerId, ContainerInfo,
ContainerListOpts, ContainersPruneInfo, DataUsage, DeleteStatus, DistributionInspectInfo,
History, ImageBuildChunk, ImageDetails, ImageId, ImageInfo, ImageListOpts, ImagesPruneInfo,
Info, RegistryAuth, SearchResult, Version,
};
use docker_api::Error;
use std::path::PathBuf;
Expand Down Expand Up @@ -68,6 +68,7 @@ pub enum ImageEvent {
},
PullChunks,
Prune,
ClearCache,
}

#[derive(Debug)]
Expand Down Expand Up @@ -110,6 +111,7 @@ pub enum ImageEventResponse {
ForceDelete(anyhow::Result<DeleteStatus>),
Import(anyhow::Result<String>),
Prune(anyhow::Result<ImagesPruneInfo>),
ClearCache(anyhow::Result<ClearCacheInfo>),
}

#[derive(Debug)]
Expand Down
20 changes: 19 additions & 1 deletion src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ pub use stats::{RunningContainerStats, StatsWorker, StatsWorkerEvent};

use anyhow::{Context, Result};
use docker_api::{
api::{ImageListOpts, ImagePruneOpts, ImagesPruneFilter, RmContainerOpts, RmImageOpts},
api::{
ClearCacheOpts, ImageListOpts, ImagePruneOpts, ImagesPruneFilter, RmContainerOpts,
RmImageOpts,
},
Docker,
};
use log::{debug, error, trace};
Expand Down Expand Up @@ -466,6 +469,21 @@ impl DockerWorker {
}
}
}
ImageEvent::ClearCache => {
match docker
.images()
.clear_cache(&ClearCacheOpts::builder().all(true).build())
.await
.context("clearing image cache failed")
{
Ok(info) => EventResponse::Image(
ImageEventResponse::ClearCache(Ok(info)),
),
Err(e) => {
EventResponse::Image(ImageEventResponse::ClearCache(Err(e)))
}
}
}
},
EventRequest::DockerUriChange { uri } => {
if uri == current_uri {
Expand Down

0 comments on commit 14ea11d

Please sign in to comment.