fix: Advanced server UI

This commit is contained in:
peaklabs-dev
2024-12-17 15:22:10 +01:00
parent 5fa636dd43
commit ed2ccaf8af
2 changed files with 42 additions and 29 deletions

View File

@@ -13,14 +13,11 @@ class Advanced extends Component
public array $parameters = []; public array $parameters = [];
#[Validate(['integer', 'min:1'])] #[Validate(['string'])]
public int $concurrentBuilds = 1; public string $serverDiskUsageCheckFrequency = '0 23 * * *';
#[Validate(['integer', 'min:1'])] #[Validate(['integer', 'min:1', 'max:99'])]
public int $dynamicTimeout = 1; public int $serverDiskUsageNotificationThreshold = 50;
#[Validate('boolean')]
public bool $forceDockerCleanup = false;
#[Validate(['string', 'required'])] #[Validate(['string', 'required'])]
public string $dockerCleanupFrequency = '*/10 * * * *'; public string $dockerCleanupFrequency = '*/10 * * * *';
@@ -28,8 +25,8 @@ class Advanced extends Component
#[Validate(['integer', 'min:1', 'max:99'])] #[Validate(['integer', 'min:1', 'max:99'])]
public int $dockerCleanupThreshold = 10; public int $dockerCleanupThreshold = 10;
#[Validate(['integer', 'min:1', 'max:99'])] #[Validate('boolean')]
public int $serverDiskUsageNotificationThreshold = 50; public bool $forceDockerCleanup = false;
#[Validate('boolean')] #[Validate('boolean')]
public bool $deleteUnusedVolumes = false; public bool $deleteUnusedVolumes = false;
@@ -37,6 +34,12 @@ class Advanced extends Component
#[Validate('boolean')] #[Validate('boolean')]
public bool $deleteUnusedNetworks = false; public bool $deleteUnusedNetworks = false;
#[Validate(['integer', 'min:1'])]
public int $concurrentBuilds = 1;
#[Validate(['integer', 'min:1'])]
public int $dynamicTimeout = 1;
public function mount(string $server_uuid) public function mount(string $server_uuid)
{ {
try { try {
@@ -60,6 +63,7 @@ class Advanced extends Component
$this->server->settings->server_disk_usage_notification_threshold = $this->serverDiskUsageNotificationThreshold; $this->server->settings->server_disk_usage_notification_threshold = $this->serverDiskUsageNotificationThreshold;
$this->server->settings->delete_unused_volumes = $this->deleteUnusedVolumes; $this->server->settings->delete_unused_volumes = $this->deleteUnusedVolumes;
$this->server->settings->delete_unused_networks = $this->deleteUnusedNetworks; $this->server->settings->delete_unused_networks = $this->deleteUnusedNetworks;
$this->server->settings->server_disk_usage_check_frequency = $this->serverDiskUsageCheckFrequency;
$this->server->settings->save(); $this->server->settings->save();
} else { } else {
$this->concurrentBuilds = $this->server->settings->concurrent_builds; $this->concurrentBuilds = $this->server->settings->concurrent_builds;
@@ -70,6 +74,7 @@ class Advanced extends Component
$this->serverDiskUsageNotificationThreshold = $this->server->settings->server_disk_usage_notification_threshold; $this->serverDiskUsageNotificationThreshold = $this->server->settings->server_disk_usage_notification_threshold;
$this->deleteUnusedVolumes = $this->server->settings->delete_unused_volumes; $this->deleteUnusedVolumes = $this->server->settings->delete_unused_volumes;
$this->deleteUnusedNetworks = $this->server->settings->delete_unused_networks; $this->deleteUnusedNetworks = $this->server->settings->delete_unused_networks;
$this->serverDiskUsageCheckFrequency = $this->server->settings->server_disk_usage_check_frequency;
} }
} }
@@ -100,6 +105,10 @@ class Advanced extends Component
$this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency'); $this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency');
throw new \Exception('Invalid Cron / Human expression for 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.');
}
$this->syncData(true); $this->syncData(true);
$this->dispatch('success', 'Server updated.'); $this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) { } catch (\Throwable $e) {

View File

@@ -10,6 +10,26 @@
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<h2>Advanced</h2> <h2>Advanced</h2>
<x-forms.button type="submit">Save</x-forms.button> <x-forms.button type="submit">Save</x-forms.button>
</div>
<div class="mt-3 mb-4">Advanced configuration for your server.</div>
</div>
<h3>Disk Usage</h3>
<div class="flex flex-col gap-6">
<div class="flex flex-col">
<div class="flex flex-wrap gap-2 sm:flex-nowrap pt-4">
<x-forms.input placeholder="0 23 * * *" id="serverDiskUsageCheckFrequency"
label="Disk usage check frequency" required
helper="Cron expression for disk usage check frequency.<br>You can use every_minute, hourly, daily, weekly, monthly, yearly.<br><br>Default is every night at 11:00 PM." />
<x-forms.input id="serverDiskUsageNotificationThreshold"
label="Server disk usage notification threshold (%)" required
helper="If the server disk usage exceeds this threshold, Coolify will send a notification to the team members." />
</div>
</div>
<div class="flex flex-col gap-2">
<div class="flex gap-4">
<h3>Docker Cleanup</h3>
<x-modal-confirmation title="Confirm Docker Cleanup?" buttonTitle="Trigger Manual Cleanup" <x-modal-confirmation title="Confirm Docker Cleanup?" buttonTitle="Trigger Manual Cleanup"
isHighlightedButton submitAction="manualCleanup" :actions="[ isHighlightedButton submitAction="manualCleanup" :actions="[
'Permanently deletes all stopped containers managed by Coolify (as containers are non-persistent, no data will be lost)', 'Permanently deletes all stopped containers managed by Coolify (as containers are non-persistent, no data will be lost)',
@@ -21,27 +41,11 @@
]" :confirmWithText="false" ]" :confirmWithText="false"
:confirmWithPassword="false" step2ButtonText="Trigger Docker Cleanup" /> :confirmWithPassword="false" step2ButtonText="Trigger Docker Cleanup" />
</div> </div>
<div>Advanced configuration for your server.</div>
</div>
<div class="flex flex-col gap-4">
<div class="flex flex-col">
<div class="flex flex-wrap gap-2 sm:flex-nowrap pt-4">
<x-forms.input id="serverDiskUsageNotificationThreshold"
label="Server disk usage notification threshold (%)" required
helper="If the server disk usage exceeds this threshold, Coolify will send a notification to the team members." />
</div>
</div>
<div class="flex flex-col gap-2">
<div class="flex items-center gap-2">
<h3>Docker Cleanup</h3>
</div>
<div class="flex flex-wrap items-center gap-4"> <div class="flex flex-wrap items-center gap-4">
@if ($forceDockerCleanup)
<x-forms.input placeholder="*/10 * * * *" id="dockerCleanupFrequency" <x-forms.input placeholder="*/10 * * * *" id="dockerCleanupFrequency"
label="Docker cleanup frequency" required label="Docker cleanup frequency" required
helper="Cron expression for Docker Cleanup.<br>You can use every_minute, hourly, daily, weekly, monthly, yearly.<br><br>Default is every night at midnight." /> helper="Cron expression for Docker Cleanup.<br>You can use every_minute, hourly, daily, weekly, monthly, yearly.<br><br>Default is every night at midnight." />
@else @if (!$forceDockerCleanup)
<x-forms.input id="dockerCleanupThreshold" label="Docker cleanup threshold (%)" required <x-forms.input id="dockerCleanupThreshold" label="Docker cleanup threshold (%)" required
helper="The Docker cleanup tasks will run when the disk usage exceeds this threshold." /> helper="The Docker cleanup tasks will run when the disk usage exceeds this threshold." />
@endif @endif