From 95f23defebf4b5fbf51321f517ef9deba6b61cf6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:15:21 +0000 Subject: [PATCH] Use streaming overlay-log for system prune, move button to stopped-containers section Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com> --- php/src/Controller/DockerController.php | 23 +++++++++---- php/src/Docker/DockerActionManager.php | 46 +++++++++++-------------- php/templates/containers.twig | 12 ++++--- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 21076129..c4625564 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -286,12 +286,23 @@ readonly class DockerController { } public function SystemPrune(Request $request, Response $response, array $args) : Response { - $results = $this->dockerActionManager->SystemPrune(); - $body = $response->getBody(); - $body->write(json_encode($results)); - return $response - ->withStatus(200) - ->withHeader('Content-Type', 'application/json; charset=utf-8'); + $nonbufResp = $response + ->withBody(new NonBufferedBody()) + ->withHeader('Content-Type', 'text/html; charset=utf-8') + ->withHeader('X-Accel-Buffering', 'no') + ->withHeader('Cache-Control', 'no-cache'); + + $streamingResponseBody = $nonbufResp->getBody(); + $streamingResponseBody->write($this->getStreamingResponseHtmlStart()); + + $addToStreamingResponseBody = function (string $message) use ($streamingResponseBody) : void { + $streamingResponseBody->write("
{$message}
"); + }; + + $this->dockerActionManager->SystemPrune($addToStreamingResponseBody); + + $streamingResponseBody->write($this->getStreamingResponseHtmlEnd()); + return $nonbufResp; } public function stopTopContainer() : void { diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index af10a9b8..b4f9d406 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -984,22 +984,20 @@ readonly class DockerActionManager { } } - public function SystemPrune(): array { - $endpoints = [ - // Remove stopped containers - 'containers/prune', - // Remove unused images - 'images/prune', - // Remove unused volumes - 'volumes/prune', - // Remove unused networks - 'networks/prune', - // Prune build cache - 'build/prune', + public function SystemPrune(?\Closure $addToStreamingResponseBody = null): void { + $steps = [ + 'containers/prune' => 'Pruning stopped containers...', + 'images/prune' => 'Pruning unused images...', + 'volumes/prune' => 'Pruning unused volumes...', + 'networks/prune' => 'Pruning unused networks...', + 'build/prune' => 'Pruning build cache...', ]; - $results = []; - foreach ($endpoints as $endpoint) { + foreach ($steps as $endpoint => $label) { + if ($addToStreamingResponseBody !== null) { + $addToStreamingResponseBody($label); + } + // Special-case images prune to include the dangling filter as requested if ($endpoint === 'images/prune') { $filters = json_encode(['dangling' => ['false']]); @@ -1009,21 +1007,17 @@ readonly class DockerActionManager { } try { - $resp = $this->guzzleClient->post($url); - $body = (string)$resp->getBody(); - $json = null; - try { - $json = json_decode($body, true, 512, JSON_THROW_ON_ERROR); - } catch (\Throwable $e) { - // Non-JSON body, keep raw - $json = $body; - } - $results[$endpoint] = $json; + $this->guzzleClient->post($url); } catch (RequestException $e) { error_log(sprintf('Docker prune (%s) failed: %s', $endpoint, $e->getMessage())); - $results[$endpoint] = ['error' => $e->getMessage()]; + if ($addToStreamingResponseBody !== null) { + $addToStreamingResponseBody(sprintf('Warning: %s failed: %s', $endpoint, $e->getMessage())); + } // continue with next prune step } } - return $results; + + if ($addToStreamingResponseBody !== null) { + $addToStreamingResponseBody('Docker system prune done.'); + } } diff --git a/php/templates/containers.twig b/php/templates/containers.twig index a2a5198d..426407ce 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -322,11 +322,6 @@ -
- - - -
{% endif %} {% else %} {% if isBackupOrRestoreRunning == true %} @@ -372,6 +367,13 @@ {% endif %} {% endif %} + {% if was_start_button_clicked == true %} +
+ + + +
+ {% endif %} {% endif %} {% endif %}