feat(maintenance): add Docker build-cache prune action
Add an admin-only POST /api/docker/prune-build-cache endpoint plus a Settings > Maintenance danger-zone button to reclaim disk used by the Docker build cache (image + static-site builds), which previously grew unbounded with no UI lever. Prunes unused-only (all=false) so a warm cache is preserved for apps redeploying soon. Mirrors the existing prune-images vertical slice; full en/ru i18n parity.
This commit is contained in:
@@ -348,3 +348,32 @@ func (s *Server) pruneImages(w http.ResponseWriter, r *http.Request) {
|
||||
"space_reclaimed_mb": reclaimedBytes / (1024 * 1024),
|
||||
})
|
||||
}
|
||||
|
||||
// pruneBuildCache handles POST /api/docker/prune-build-cache. It removes
|
||||
// unused Docker build-cache records daemon-wide (all=false), so an app's next
|
||||
// rebuild still hits its warm cache. The build cache is regenerable by
|
||||
// definition — pruning only forces slower rebuilds, never data loss — and the
|
||||
// dockerfile/static deploy paths never reclaim it on teardown, so it grows
|
||||
// monotonically until pruned here.
|
||||
func (s *Server) pruneBuildCache(w http.ResponseWriter, r *http.Request) {
|
||||
if s.docker == nil {
|
||||
respondError(w, http.StatusServiceUnavailable, "Docker is not available")
|
||||
return
|
||||
}
|
||||
|
||||
result, err := s.docker.PruneBuildCache(r.Context(), false)
|
||||
if err != nil {
|
||||
slog.Error("prune: build cache", "error", err)
|
||||
respondError(w, http.StatusInternalServerError, "internal server error")
|
||||
return
|
||||
}
|
||||
|
||||
slog.Info("prune: build cache",
|
||||
"caches_deleted", result.CachesDeleted,
|
||||
"space_reclaimed_mb", result.SpaceReclaimed/(1024*1024))
|
||||
|
||||
respondJSON(w, http.StatusOK, map[string]any{
|
||||
"caches_deleted": result.CachesDeleted,
|
||||
"space_reclaimed_mb": result.SpaceReclaimed / (1024 * 1024),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user