aio-interface: offer system prune button

Signed-off-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
Simon L.
2026-02-27 14:48:21 +01:00
parent c1faa785b3
commit 4f7ccdedb5
4 changed files with 43 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ $app->post('/api/docker/backup-check-repair', AIO\Controller\DockerController::c
$app->post('/api/docker/backup-test', AIO\Controller\DockerController::class . ':StartBackupContainerTest');
$app->post('/api/docker/restore', AIO\Controller\DockerController::class . ':StartBackupContainerRestore');
$app->post('/api/docker/stop', AIO\Controller\DockerController::class . ':StopContainer');
$app->post('/api/docker/prune', AIO\Controller\DockerController::class . ':SystemPrune');
$app->get('/api/docker/logs', AIO\Controller\DockerController::class . ':GetLogs');
$app->post('/api/auth/login', AIO\Controller\LoginController::class . ':TryLogin');
$app->get('/api/auth/getlogin', AIO\Controller\LoginController::class . ':GetTryLogin');

View File

@@ -285,6 +285,11 @@ readonly class DockerController {
return $response->withStatus(201)->withHeader('Location', '.');
}
public function SystemPrune(Request $request, Response $response, array $args) : Response {
$this->dockerActionManager->SystemPrune();
return $response->withStatus(201)->withHeader('Location', '.');
}
public function stopTopContainer() : void {
$id = self::TOP_CONTAINER;
$this->PerformRecursiveContainerStop($id);

View File

@@ -983,4 +983,36 @@ readonly class DockerActionManager {
return $this->dockerHubManager->GetLatestDigestOfTag($imageName, $tag);
}
}
public function SystemPrune(): void {
$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',
];
foreach ($endpoints as $endpoint) {
// Special-case images prune to include the dangling filter as requested
if ($endpoint === 'images/prune') {
$filters = json_encode(['dangling' => ['false']]);
$url = $this->BuildApiUrl($endpoint . '?filters=' . urlencode($filters));
} else {
$url = $this->BuildApiUrl($endpoint);
}
try {
$this->guzzleClient->post($url);
} catch (RequestException $e) {
error_log(sprintf('Docker prune (%s) failed: %s', $endpoint, $e->getMessage()));
// continue with next prune step
}
}
}
}

View File

@@ -322,6 +322,11 @@
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input type="submit" value="Stop containers" />
</form>
<form method="POST" action="api/docker/prune" class="xhr">
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input type="submit" value="Run docker system prune" onclick="return confirm('Run docker system prune? This will remove unused images, containers and volumes. Continue?')" />
</form>
{% endif %}
{% else %}
{% if isBackupOrRestoreRunning == true %}