diff --git a/app/Livewire/Server/Advanced.php b/app/Livewire/Server/Advanced.php index 577730f24..6d9d1010f 100644 --- a/app/Livewire/Server/Advanced.php +++ b/app/Livewire/Server/Advanced.php @@ -2,7 +2,6 @@ namespace App\Livewire\Server; -use App\Jobs\DockerCleanupJob; use App\Models\Server; use Livewire\Attributes\Validate; use Livewire\Component; @@ -19,21 +18,6 @@ class Advanced extends Component #[Validate(['integer', 'min:1', 'max:99'])] public int $serverDiskUsageNotificationThreshold = 50; - #[Validate(['string', 'required'])] - public string $dockerCleanupFrequency = '*/10 * * * *'; - - #[Validate(['integer', 'min:1', 'max:99'])] - public int $dockerCleanupThreshold = 10; - - #[Validate('boolean')] - public bool $forceDockerCleanup = false; - - #[Validate('boolean')] - public bool $deleteUnusedVolumes = false; - - #[Validate('boolean')] - public bool $deleteUnusedNetworks = false; - #[Validate(['integer', 'min:1'])] public int $concurrentBuilds = 1; @@ -57,23 +41,13 @@ class Advanced extends Component $this->validate(); $this->server->settings->concurrent_builds = $this->concurrentBuilds; $this->server->settings->dynamic_timeout = $this->dynamicTimeout; - $this->server->settings->force_docker_cleanup = $this->forceDockerCleanup; - $this->server->settings->docker_cleanup_frequency = $this->dockerCleanupFrequency; - $this->server->settings->docker_cleanup_threshold = $this->dockerCleanupThreshold; $this->server->settings->server_disk_usage_notification_threshold = $this->serverDiskUsageNotificationThreshold; - $this->server->settings->delete_unused_volumes = $this->deleteUnusedVolumes; - $this->server->settings->delete_unused_networks = $this->deleteUnusedNetworks; $this->server->settings->server_disk_usage_check_frequency = $this->serverDiskUsageCheckFrequency; $this->server->settings->save(); } else { $this->concurrentBuilds = $this->server->settings->concurrent_builds; $this->dynamicTimeout = $this->server->settings->dynamic_timeout; - $this->forceDockerCleanup = $this->server->settings->force_docker_cleanup; - $this->dockerCleanupFrequency = $this->server->settings->docker_cleanup_frequency; - $this->dockerCleanupThreshold = $this->server->settings->docker_cleanup_threshold; $this->serverDiskUsageNotificationThreshold = $this->server->settings->server_disk_usage_notification_threshold; - $this->deleteUnusedVolumes = $this->server->settings->delete_unused_volumes; - $this->deleteUnusedNetworks = $this->server->settings->delete_unused_networks; $this->serverDiskUsageCheckFrequency = $this->server->settings->server_disk_usage_check_frequency; } } @@ -88,23 +62,9 @@ class Advanced extends Component } } - public function manualCleanup() - { - try { - DockerCleanupJob::dispatch($this->server, true); - $this->dispatch('success', 'Manual cleanup job started. Depending on the amount of data, this might take a while.'); - } catch (\Throwable $e) { - return handleError($e, $this); - } - } - public function submit() { try { - if (! validate_cron_expression($this->dockerCleanupFrequency)) { - $this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency'); - throw new \Exception('Invalid Cron / Human expression for Docker Cleanup Frequency.'); - } if (! validate_cron_expression($this->serverDiskUsageCheckFrequency)) { $this->serverDiskUsageCheckFrequency = $this->server->settings->getOriginal('server_disk_usage_check_frequency'); throw new \Exception('Invalid Cron / Human expression for Disk Usage Check Frequency.'); diff --git a/app/Livewire/Server/DockerCleanup.php b/app/Livewire/Server/DockerCleanup.php new file mode 100644 index 000000000..8ece7ccc2 --- /dev/null +++ b/app/Livewire/Server/DockerCleanup.php @@ -0,0 +1,99 @@ +server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail(); + $this->parameters = get_route_parameters(); + $this->syncData(); + } catch (\Throwable) { + return redirect()->route('server.show'); + } + } + + public function syncData(bool $toModel = false) + { + if ($toModel) { + $this->validate(); + $this->server->settings->force_docker_cleanup = $this->forceDockerCleanup; + $this->server->settings->docker_cleanup_frequency = $this->dockerCleanupFrequency; + $this->server->settings->docker_cleanup_threshold = $this->dockerCleanupThreshold; + $this->server->settings->delete_unused_volumes = $this->deleteUnusedVolumes; + $this->server->settings->delete_unused_networks = $this->deleteUnusedNetworks; + $this->server->settings->save(); + } else { + $this->forceDockerCleanup = $this->server->settings->force_docker_cleanup; + $this->dockerCleanupFrequency = $this->server->settings->docker_cleanup_frequency; + $this->dockerCleanupThreshold = $this->server->settings->docker_cleanup_threshold; + $this->deleteUnusedVolumes = $this->server->settings->delete_unused_volumes; + $this->deleteUnusedNetworks = $this->server->settings->delete_unused_networks; + } + } + + public function instantSave() + { + try { + $this->syncData(true); + $this->dispatch('success', 'Server updated.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + + public function manualCleanup() + { + try { + DockerCleanupJob::dispatch($this->server, true); + $this->dispatch('success', 'Manual cleanup job started. Depending on the amount of data, this might take a while.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + + public function submit() + { + try { + if (! validate_cron_expression($this->dockerCleanupFrequency)) { + $this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency'); + throw new \Exception('Invalid Cron / Human expression for Docker Cleanup Frequency.'); + } + $this->syncData(true); + $this->dispatch('success', 'Server updated.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + + public function render() + { + return view('livewire.server.docker-cleanup'); + } +} diff --git a/resources/views/components/server/sidebar.blade.php b/resources/views/components/server/sidebar.blade.php index f86e0ef8c..e3ed98450 100644 --- a/resources/views/components/server/sidebar.blade.php +++ b/resources/views/components/server/sidebar.blade.php @@ -5,6 +5,9 @@ Advanced + Docker Cleanup + @endif Private Key diff --git a/resources/views/livewire/server/advanced.blade.php b/resources/views/livewire/server/advanced.blade.php index 40ff6c8b5..b6dcf0ea0 100644 --- a/resources/views/livewire/server/advanced.blade.php +++ b/resources/views/livewire/server/advanced.blade.php @@ -27,67 +27,6 @@ -
-
-

Docker Cleanup

- -
-
- - @if (!$forceDockerCleanup) - - @endif -
- -
- -
-

- Warning: Enable these - options only if you fully understand their implications and - consequences!
Improper use will result in data loss and could cause - functional issues. -

-
- - -
-
-

Builds

Customize the build process.
diff --git a/resources/views/livewire/server/docker-cleanup.blade.php b/resources/views/livewire/server/docker-cleanup.blade.php new file mode 100644 index 000000000..70bbb5db7 --- /dev/null +++ b/resources/views/livewire/server/docker-cleanup.blade.php @@ -0,0 +1,77 @@ +
+ + {{ data_get_str($server, 'name')->limit(10) }} > Docker Cleanup | Coolify + + +
+ +
+
+
+

Docker Cleanup

+
+
Configure Docker cleanup settings for your server.
+
+ +
+
+

Docker Cleanup

+ +
+
+ + @if (!$forceDockerCleanup) + + @endif +
+ +
+
+

+ Warning: Enable these + options only if you fully understand their implications and + consequences!
Improper use will result in data loss and could cause + functional issues. +

+
+ + +
+
+
+
+
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index ec4923941..618e4e090 100644 --- a/routes/web.php +++ b/routes/web.php @@ -42,6 +42,7 @@ use App\Livewire\Server\Charts as ServerCharts; use App\Livewire\Server\CloudflareTunnels; use App\Livewire\Server\Delete as DeleteServer; use App\Livewire\Server\Destinations as ServerDestinations; +use App\Livewire\Server\DockerCleanup; use App\Livewire\Server\Index as ServerIndex; use App\Livewire\Server\LogDrains; use App\Livewire\Server\PrivateKey\Show as PrivateKeyShow; @@ -256,6 +257,7 @@ Route::middleware(['auth', 'verified'])->group(function () { Route::get('/proxy/dynamic', ProxyDynamicConfigurations::class)->name('server.proxy.dynamic-confs'); Route::get('/proxy/logs', ProxyLogs::class)->name('server.proxy.logs'); Route::get('/terminal', ExecuteContainerCommand::class)->name('server.command'); + Route::get('/docker-cleanup', DockerCleanup::class)->name('server.docker-cleanup'); }); Route::get('/destinations', DestinationIndex::class)->name('destination.index'); Route::get('/destination/{destination_uuid}', DestinationShow::class)->name('destination.show');