- @foreach ($resource->fileStorages()->get()->sort() as $fileStorage)
+ @foreach ($fileStorage->sort() as $fileStorage)
@endforeach
@@ -48,9 +48,9 @@
@if ($resource->persistentStorages()->get()->count() > 0)
@endif
- @if ($resource->fileStorages()->get()->count() > 0)
+ @if ($fileStorage->count() > 0)
- @foreach ($resource->fileStorages()->get()->sort() as $fileStorage)
+ @foreach ($fileStorage->sort() as $fileStorage)
@endforeach
From 38976dac12a6a6b312fa787c4ef50696c998fd02 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Mon, 5 Aug 2024 20:05:38 +0200
Subject: [PATCH 066/122] fixes and check for valid cron expressions
---
app/Actions/Server/UpdateCoolify.php | 2 -
app/Console/Kernel.php | 45 ++++++++----
app/Jobs/CheckForUpdatesJob.php | 4 +-
app/Jobs/PullCoolifyImageJob.php | 1 -
app/Jobs/UpdateCoolifyJob.php | 19 +++--
app/Livewire/Settings/Configuration.php | 69 ++++++++++++++++++-
app/Models/InstanceSettings.php | 3 +
...n_available_to_instance_settings_table.php | 4 +-
.../livewire/settings/configuration.blade.php | 4 +-
9 files changed, 124 insertions(+), 27 deletions(-)
diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.php
index a945670d4..72ce80b6b 100644
--- a/app/Actions/Server/UpdateCoolify.php
+++ b/app/Actions/Server/UpdateCoolify.php
@@ -20,7 +20,6 @@ class UpdateCoolify
{
try {
$settings = InstanceSettings::get();
- ray('Running InstanceAutoUpdateJob');
$this->server = Server::find(0);
if (! $this->server) {
return;
@@ -48,7 +47,6 @@ class UpdateCoolify
private function update()
{
if (isDev()) {
- ray('Running in dev mode');
remote_process([
'sleep 10',
], $this->server);
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index fdfbc8aff..41d821e8a 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -13,6 +13,8 @@ use App\Jobs\PullSentinelImageJob;
use App\Jobs\PullTemplatesFromCDN;
use App\Jobs\ScheduledTaskJob;
use App\Jobs\ServerStatusJob;
+use App\Jobs\UpdateCoolifyJob;
+use App\Jobs\CheckForUpdatesJob;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ScheduledTask;
@@ -31,10 +33,6 @@ class Kernel extends ConsoleKernel
$settings = InstanceSettings::get();
if (isDev()) {
- // Instance Jobs
- $schedule->command('horizon:snapshot')->everyMinute();
- $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
- $schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer();
// Server Jobs
$this->check_scheduled_backups($schedule);
$this->check_resources($schedule);
@@ -45,10 +43,16 @@ class Kernel extends ConsoleKernel
// Instance Jobs
$schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->command('cleanup:unreachable-servers')->daily();
- $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
- $schedule->job(new PullTemplatesFromCDN)->everyThirtyMinutes()->onOneServer();
- $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
-
+ $schedule->job(new PullTemplatesFromCDN)->daily()->onOneServer();
+ $schedule->job(new CleanupInstanceStuffsJob)->everyFiveMinutes()->onOneServer();
+
+ if ($settings->update_check_frequency && $this->isValidCronExpression($settings->update_check_frequency)) {
+ $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
+ } else {
+ // Default to every 12 hours if not set or invalid
+ $schedule->job(new PullCoolifyImageJob)->twiceDaily()->onOneServer();
+ }
+
// Server Jobs
$this->scheduleUpdates($schedule);
$this->pull_images($schedule);
@@ -56,7 +60,6 @@ class Kernel extends ConsoleKernel
$this->check_scheduled_tasks($schedule);
$this->check_scheduled_backups($schedule);
-
$schedule->command('cleanup:database --yes')->daily();
$schedule->command('uploads:clear')->everyTwoMinutes();
}
@@ -79,13 +82,31 @@ class Kernel extends ConsoleKernel
$settings = InstanceSettings::get();
// Schedule update check
- if ($settings->update_check_frequency) {
+ if ($settings->update_check_frequency && $this->isValidCronExpression($settings->update_check_frequency)) {
$schedule->job(new CheckForUpdatesJob())->cron($settings->update_check_frequency)->onOneServer();
+ } else {
+ // Default to every 12 hours if not set or invalid
+ $schedule->job(new CheckForUpdatesJob())->twiceDaily()->onOneServer();
}
// Schedule auto-update
- if ($settings->is_auto_update_enabled && $settings->auto_update_frequency) {
- $schedule->job(new UpdateCoolifyJob())->cron($settings->auto_update_frequency)->onOneServer();
+ if ($settings->is_auto_update_enabled) {
+ if ($settings->auto_update_frequency && $this->isValidCronExpression($settings->auto_update_frequency)) {
+ $schedule->job(new UpdateCoolifyJob())->cron($settings->auto_update_frequency)->onOneServer();
+ } else {
+ // Default to every 24 hours if not set or invalid
+ $schedule->job(new UpdateCoolifyJob())->daily()->onOneServer();
+ }
+ }
+ }
+
+ private function isValidCronExpression($expression)
+ {
+ try {
+ new \Cron\CronExpression($expression);
+ return true;
+ } catch (\Exception $e) {
+ return false;
}
}
diff --git a/app/Jobs/CheckForUpdatesJob.php b/app/Jobs/CheckForUpdatesJob.php
index 8141dd3fa..e18e37ed6 100644
--- a/app/Jobs/CheckForUpdatesJob.php
+++ b/app/Jobs/CheckForUpdatesJob.php
@@ -33,14 +33,12 @@ class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
if (version_compare($latest_version, $current_version, '>')) {
// New version available
$settings->update(['new_version_available' => true]);
- // Optionally, you can trigger a notification here
} else {
$settings->update(['new_version_available' => false]);
}
}
} catch (\Throwable $e) {
- // Log the error or send a notification
- ray('CheckForUpdatesJob failed: ' . $e->getMessage());
+ // Consider implementing a notification to administrators
}
}
}
\ No newline at end of file
diff --git a/app/Jobs/PullCoolifyImageJob.php b/app/Jobs/PullCoolifyImageJob.php
index 9c8145b70..624dc4414 100644
--- a/app/Jobs/PullCoolifyImageJob.php
+++ b/app/Jobs/PullCoolifyImageJob.php
@@ -43,7 +43,6 @@ class PullCoolifyImageJob implements ShouldBeEncrypted, ShouldQueue
if (version_compare($latest_version, $current_version, '<')) {
return;
}
- // The actual update process will be handled by the UpdateCoolifyJob
} catch (\Throwable $e) {
throw $e;
}
diff --git a/app/Jobs/UpdateCoolifyJob.php b/app/Jobs/UpdateCoolifyJob.php
index 243e3934f..5c8e8e679 100644
--- a/app/Jobs/UpdateCoolifyJob.php
+++ b/app/Jobs/UpdateCoolifyJob.php
@@ -2,7 +2,6 @@
namespace App\Jobs;
-use App\Actions\Server\UpdateCoolify;
use App\Models\InstanceSettings;
use App\Models\Server;
use Illuminate\Bus\Queueable;
@@ -11,6 +10,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
+use App\Actions\Server\UpdateCoolify;
+use Illuminate\Support\Facades\Log;
class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
{
@@ -22,23 +23,31 @@ class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
{
try {
$settings = InstanceSettings::get();
- if (!$settings->is_auto_update_enabled || !$settings->new_version_available) {
+ if (!$settings->is_auto_update_enabled) {
+ Log::info('Auto-update is disabled. Skipping update check.');
+ return;
+ }
+
+ if (!$settings->new_version_available) {
+ Log::info('No new version available. Skipping update.');
return;
}
$server = Server::findOrFail(0);
if (!$server) {
+ Log::error('Server not found. Cannot proceed with update.');
return;
}
+ Log::info('Starting Coolify update process...');
UpdateCoolify::run(false); // false means it's not a manual update
- // After successful update, reset the new_version_available flag
$settings->update(['new_version_available' => false]);
+ Log::info('Coolify update completed successfully.');
} catch (\Throwable $e) {
- // Log the error or send a notification
- ray('UpdateCoolifyJob failed: ' . $e->getMessage());
+ Log::error('UpdateCoolifyJob failed: ' . $e->getMessage());
+ // Consider implementing a notification to administrators
}
}
}
\ No newline at end of file
diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php
index 7439e112f..0d0b110b6 100644
--- a/app/Livewire/Settings/Configuration.php
+++ b/app/Livewire/Settings/Configuration.php
@@ -5,6 +5,7 @@ namespace App\Livewire\Settings;
use App\Models\InstanceSettings as ModelsInstanceSettings;
use App\Models\Server;
use Livewire\Component;
+use Cron\CronExpression;
class Configuration extends Component
{
@@ -20,6 +21,10 @@ class Configuration extends Component
public bool $is_api_enabled;
+ public ?string $auto_update_frequency;
+
+ public ?string $update_check_frequency;
+
protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
protected Server $server;
@@ -32,6 +37,9 @@ class Configuration extends Component
'settings.custom_dns_servers' => 'nullable',
'settings.instance_name' => 'nullable',
'settings.allowed_ips' => 'nullable',
+ 'settings.is_auto_update_enabled' => 'boolean',
+ 'auto_update_frequency' => 'nullable|string',
+ 'update_check_frequency' => 'required|string',
];
protected $validationAttributes = [
@@ -41,6 +49,9 @@ class Configuration extends Component
'settings.public_port_max' => 'Public port max',
'settings.custom_dns_servers' => 'Custom DNS servers',
'settings.allowed_ips' => 'Allowed IPs',
+ 'settings.is_auto_update_enabled' => 'Auto Update Enabled',
+ 'auto_update_frequency' => 'Auto Update Frequency',
+ 'update_check_frequency' => 'Update Check Frequency',
];
public function mount()
@@ -50,6 +61,8 @@ class Configuration extends Component
$this->is_registration_enabled = $this->settings->is_registration_enabled;
$this->is_dns_validation_enabled = $this->settings->is_dns_validation_enabled;
$this->is_api_enabled = $this->settings->is_api_enabled;
+ $this->auto_update_frequency = $this->settings->auto_update_frequency;
+ $this->update_check_frequency = $this->settings->update_check_frequency;
}
public function instantSave()
@@ -59,6 +72,8 @@ class Configuration extends Component
$this->settings->is_registration_enabled = $this->is_registration_enabled;
$this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
$this->settings->is_api_enabled = $this->is_api_enabled;
+ $this->settings->auto_update_frequency = $this->auto_update_frequency;
+ $this->settings->update_check_frequency = $this->update_check_frequency;
$this->settings->save();
$this->dispatch('success', 'Settings updated!');
}
@@ -76,6 +91,16 @@ class Configuration extends Component
}
$this->validate();
+ if ($this->is_auto_update_enabled && !$this->validateCronExpression($this->auto_update_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
+ return;
+ }
+
+ if (!$this->validateCronExpression($this->update_check_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
+ return;
+ }
+
if ($this->settings->is_dns_validation_enabled && $this->settings->fqdn) {
if (! validate_dns_entry($this->settings->fqdn, $this->server)) {
$this->dispatch('error', "Validating DNS failed.
Make sure you have added the DNS records correctly.
{$this->settings->fqdn}->{$this->server->ip}
Check this
documentation for further help.");
@@ -99,6 +124,14 @@ class Configuration extends Component
$this->settings->allowed_ips = $this->settings->allowed_ips->unique();
$this->settings->allowed_ips = $this->settings->allowed_ips->implode(',');
+ $this->settings->do_not_track = $this->do_not_track;
+ $this->settings->is_auto_update_enabled = $this->is_auto_update_enabled;
+ $this->settings->is_registration_enabled = $this->is_registration_enabled;
+ $this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
+ $this->settings->is_api_enabled = $this->is_api_enabled;
+ $this->settings->auto_update_frequency = $this->auto_update_frequency;
+ $this->settings->update_check_frequency = $this->update_check_frequency;
+
$this->settings->save();
$this->server->setupDynamicProxyConfiguration();
if (! $error_show) {
@@ -108,4 +141,38 @@ class Configuration extends Component
return handleError($e, $this);
}
}
-}
+
+ private function validateCronExpression($expression): bool
+ {
+ if (empty($expression)) {
+ return false;
+ }
+ $isValid = false;
+ try {
+ $cronExpression = new CronExpression($expression);
+ $isValid = $cronExpression->getNextRunDate() !== false;
+ } catch (\Exception $e) {
+ $isValid = false;
+ }
+
+ if (isset(VALID_CRON_STRINGS[$expression])) {
+ $isValid = true;
+ }
+
+ return $isValid;
+ }
+
+ public function updatedAutoUpdateFrequency()
+ {
+ if (!$this->validateCronExpression($this->auto_update_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression.');
+ }
+ }
+
+ public function updatedUpdateCheckFrequency()
+ {
+ if (!$this->validateCronExpression($this->update_check_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression.');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php
index bd3c41a1f..5bd421956 100644
--- a/app/Models/InstanceSettings.php
+++ b/app/Models/InstanceSettings.php
@@ -18,6 +18,9 @@ class InstanceSettings extends Model implements SendsEmail
'resale_license' => 'encrypted',
'smtp_password' => 'encrypted',
'allowed_ip_ranges' => 'array',
+ 'is_auto_update_enabled' => 'boolean',
+ 'auto_update_frequency' => 'string',
+ 'update_check_frequency' => 'string',
];
public function fqdn(): Attribute
diff --git a/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php b/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
index 37cd93dc4..25c5666b8 100644
--- a/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
+++ b/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
@@ -12,8 +12,8 @@ return new class extends Migration
public function up(): void
{
Schema::table('instance_settings', function (Blueprint $table) {
- $table->string('update_check_frequency')->nullable();
- $table->string('auto_update_frequency')->nullable();
+ $table->string('update_check_frequency')->default('0 */12 * * *')->nullable();
+ $table->string('auto_update_frequency')->default('0 0 * * *')->nullable();
});
}
diff --git a/resources/views/livewire/settings/configuration.blade.php b/resources/views/livewire/settings/configuration.blade.php
index e2f375037..e9cb7267d 100644
--- a/resources/views/livewire/settings/configuration.blade.php
+++ b/resources/views/livewire/settings/configuration.blade.php
@@ -46,8 +46,10 @@
@if($is_auto_update_enabled)
+ @error('settings.auto_update_frequency')
{{ $message }} @enderror
@endif
-
+
+ @error('settings.update_check_frequency')
{{ $message }} @enderror
@endif
From 3e0821e47142d1ab0b13b737c40d98169e8a46d6 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 20:07:08 +0200
Subject: [PATCH 067/122] refactor
---
app/Livewire/Project/Service/Storage.php | 3 ++-
.../views/livewire/project/service/file-storage.blade.php | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/app/Livewire/Project/Service/Storage.php b/app/Livewire/Project/Service/Storage.php
index beccb2677..4b64a8b5e 100644
--- a/app/Livewire/Project/Service/Storage.php
+++ b/app/Livewire/Project/Service/Storage.php
@@ -17,7 +17,7 @@ class Storage extends Component
return [
"echo-private:team.{$teamId},FileStorageChanged" => 'refreshStoragesFromEvent',
- 'refreshStorages' => '$refresh',
+ 'refreshStorages',
'addNewVolume',
];
}
@@ -36,6 +36,7 @@ class Storage extends Component
public function refreshStorages()
{
$this->fileStorage = $this->resource->fileStorages()->get();
+ $this->dispatch('$refresh');
}
public function addNewVolume($data)
diff --git a/resources/views/livewire/project/service/file-storage.blade.php b/resources/views/livewire/project/service/file-storage.blade.php
index 5680c94b3..96590cada 100644
--- a/resources/views/livewire/project/service/file-storage.blade.php
+++ b/resources/views/livewire/project/service/file-storage.blade.php
@@ -27,8 +27,9 @@
@endif
- This resource will be deleted. It is not reversible.
Please think
+ This storage will be deleted. It is not reversible. Please
+ think
again.
Actions
@if ($fileStorage->is_directory)
From 92ebc3f0c60c1e91a3e170e564091a556022e98a Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 20:08:37 +0200
Subject: [PATCH 068/122] refactor
---
app/Livewire/Project/Service/Configuration.php | 4 +---
app/Livewire/Server/Proxy/DynamicConfigurations.php | 3 +--
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.php
index 47534ded1..c82012aaa 100644
--- a/app/Livewire/Project/Service/Configuration.php
+++ b/app/Livewire/Project/Service/Configuration.php
@@ -25,7 +25,6 @@ class Configuration extends Component
return [
"echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',
'check_status',
- 'refresh' => '$refresh',
];
}
@@ -76,8 +75,7 @@ class Configuration extends Component
{
try {
GetContainersStatus::run($this->service->server);
- // dispatch_sync(new ContainerStatusJob($this->service->server));
- $this->dispatch('refresh')->self();
+ $this->dispatch('$refresh');
} catch (\Exception $e) {
return handleError($e, $this);
}
diff --git a/app/Livewire/Server/Proxy/DynamicConfigurations.php b/app/Livewire/Server/Proxy/DynamicConfigurations.php
index c858481db..6277a24bd 100644
--- a/app/Livewire/Server/Proxy/DynamicConfigurations.php
+++ b/app/Livewire/Server/Proxy/DynamicConfigurations.php
@@ -21,7 +21,6 @@ class DynamicConfigurations extends Component
return [
"echo-private:team.{$teamId},ProxyStatusChanged" => 'loadDynamicConfigurations',
'loadDynamicConfigurations',
- 'refresh' => '$refresh',
];
}
@@ -42,7 +41,7 @@ class DynamicConfigurations extends Component
$contents[$without_extension] = instant_remote_process(["cat {$proxy_path}/dynamic/{$file}"], $this->server);
}
$this->contents = $contents;
- $this->dispatch('refresh');
+ $this->dispatch('$refresh');
}
public function mount()
From 4dfec6771c2b02de7029190db1220a99049bf7c1 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Mon, 5 Aug 2024 20:31:06 +0200
Subject: [PATCH 069/122] added defaults, remove duplicated cron validation
---
app/Console/Kernel.php | 39 ++++---------------
app/Livewire/Settings/Configuration.php | 14 +++----
...n_available_to_instance_settings_table.php | 2 +-
.../livewire/settings/configuration.blade.php | 6 +--
4 files changed, 17 insertions(+), 44 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 41d821e8a..92a1b1618 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -45,14 +45,9 @@ class Kernel extends ConsoleKernel
$schedule->command('cleanup:unreachable-servers')->daily();
$schedule->job(new PullTemplatesFromCDN)->daily()->onOneServer();
$schedule->job(new CleanupInstanceStuffsJob)->everyFiveMinutes()->onOneServer();
-
- if ($settings->update_check_frequency && $this->isValidCronExpression($settings->update_check_frequency)) {
- $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
- } else {
- // Default to every 12 hours if not set or invalid
- $schedule->job(new PullCoolifyImageJob)->twiceDaily()->onOneServer();
- }
-
+ $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency ?? '0 0 * * *')->onOneServer();
+ $schedule->job(new CheckForUpdatesJob())->cron($settings->auto_update_frequency ?? '0 11,23 * * *')->onOneServer();
+
// Server Jobs
$this->scheduleUpdates($schedule);
$this->pull_images($schedule);
@@ -81,32 +76,12 @@ class Kernel extends ConsoleKernel
{
$settings = InstanceSettings::get();
- // Schedule update check
- if ($settings->update_check_frequency && $this->isValidCronExpression($settings->update_check_frequency)) {
- $schedule->job(new CheckForUpdatesJob())->cron($settings->update_check_frequency)->onOneServer();
- } else {
- // Default to every 12 hours if not set or invalid
- $schedule->job(new CheckForUpdatesJob())->twiceDaily()->onOneServer();
- }
+ $updateCheckFrequency = $settings->update_check_frequency ?? '0 0 * * *'; // Default to daily at 00:00
+ $schedule->job(new CheckForUpdatesJob())->cron($updateCheckFrequency)->onOneServer();
- // Schedule auto-update
if ($settings->is_auto_update_enabled) {
- if ($settings->auto_update_frequency && $this->isValidCronExpression($settings->auto_update_frequency)) {
- $schedule->job(new UpdateCoolifyJob())->cron($settings->auto_update_frequency)->onOneServer();
- } else {
- // Default to every 24 hours if not set or invalid
- $schedule->job(new UpdateCoolifyJob())->daily()->onOneServer();
- }
- }
- }
-
- private function isValidCronExpression($expression)
- {
- try {
- new \Cron\CronExpression($expression);
- return true;
- } catch (\Exception $e) {
- return false;
+ $autoUpdateFrequency = $settings->auto_update_frequency ?? '0 11,23 * * *'; // Default to twice daily at 11:00 and 23:00
+ $schedule->job(new UpdateCoolifyJob())->cron($autoUpdateFrequency)->onOneServer();
}
}
diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php
index 0d0b110b6..2f4c77535 100644
--- a/app/Livewire/Settings/Configuration.php
+++ b/app/Livewire/Settings/Configuration.php
@@ -21,9 +21,9 @@ class Configuration extends Component
public bool $is_api_enabled;
- public ?string $auto_update_frequency;
+ public string $auto_update_frequency;
- public ?string $update_check_frequency;
+ public string $update_check_frequency;
protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
@@ -39,7 +39,7 @@ class Configuration extends Component
'settings.allowed_ips' => 'nullable',
'settings.is_auto_update_enabled' => 'boolean',
'auto_update_frequency' => 'nullable|string',
- 'update_check_frequency' => 'required|string',
+ 'update_check_frequency' => 'nullable|string',
];
protected $validationAttributes = [
@@ -91,6 +91,7 @@ class Configuration extends Component
}
$this->validate();
+ // Allow empty values and set defaults
if ($this->is_auto_update_enabled && !$this->validateCronExpression($this->auto_update_frequency)) {
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
return;
@@ -131,7 +132,6 @@ class Configuration extends Component
$this->settings->is_api_enabled = $this->is_api_enabled;
$this->settings->auto_update_frequency = $this->auto_update_frequency;
$this->settings->update_check_frequency = $this->update_check_frequency;
-
$this->settings->save();
$this->server->setupDynamicProxyConfiguration();
if (! $error_show) {
@@ -145,7 +145,7 @@ class Configuration extends Component
private function validateCronExpression($expression): bool
{
if (empty($expression)) {
- return false;
+ return true;
}
$isValid = false;
try {
@@ -165,14 +165,14 @@ class Configuration extends Component
public function updatedAutoUpdateFrequency()
{
if (!$this->validateCronExpression($this->auto_update_frequency)) {
- $this->dispatch('error', 'Invalid Cron / Human expression.');
+ $this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
}
}
public function updatedUpdateCheckFrequency()
{
if (!$this->validateCronExpression($this->update_check_frequency)) {
- $this->dispatch('error', 'Invalid Cron / Human expression.');
+ $this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
}
}
}
\ No newline at end of file
diff --git a/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php b/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
index 25c5666b8..85dafc4b7 100644
--- a/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
+++ b/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
@@ -12,8 +12,8 @@ return new class extends Migration
public function up(): void
{
Schema::table('instance_settings', function (Blueprint $table) {
- $table->string('update_check_frequency')->default('0 */12 * * *')->nullable();
$table->string('auto_update_frequency')->default('0 0 * * *')->nullable();
+ $table->string('update_check_frequency')->default('0 */11 * * *')->nullable();
});
}
diff --git a/resources/views/livewire/settings/configuration.blade.php b/resources/views/livewire/settings/configuration.blade.php
index e9cb7267d..f92e9d79d 100644
--- a/resources/views/livewire/settings/configuration.blade.php
+++ b/resources/views/livewire/settings/configuration.blade.php
@@ -45,11 +45,9 @@
@else
@if($is_auto_update_enabled)
-
- @error('settings.auto_update_frequency') {{ $message }} @enderror
+
@endif
-
- @error('settings.update_check_frequency') {{ $message }} @enderror
+
@endif
From b64d4881cb4f724424b4d774e07e8197e7ad11e4 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Mon, 5 Aug 2024 20:33:20 +0200
Subject: [PATCH 070/122] made helper more clear
---
resources/views/livewire/settings/configuration.blade.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/resources/views/livewire/settings/configuration.blade.php b/resources/views/livewire/settings/configuration.blade.php
index f92e9d79d..08e39adbd 100644
--- a/resources/views/livewire/settings/configuration.blade.php
+++ b/resources/views/livewire/settings/configuration.blade.php
@@ -45,9 +45,9 @@
@else
@if($is_auto_update_enabled)
-
+
@endif
-
+
@endif
From 50ede5cab9105a956eed748a4d68d13356031c1f Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Mon, 5 Aug 2024 20:57:27 +0200
Subject: [PATCH 071/122] remove comments and remove duplicated scheduling
---
app/Console/Kernel.php | 8 ++------
app/Livewire/Settings/Configuration.php | 1 -
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 92a1b1618..735b75de1 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -45,10 +45,6 @@ class Kernel extends ConsoleKernel
$schedule->command('cleanup:unreachable-servers')->daily();
$schedule->job(new PullTemplatesFromCDN)->daily()->onOneServer();
$schedule->job(new CleanupInstanceStuffsJob)->everyFiveMinutes()->onOneServer();
- $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency ?? '0 0 * * *')->onOneServer();
- $schedule->job(new CheckForUpdatesJob())->cron($settings->auto_update_frequency ?? '0 11,23 * * *')->onOneServer();
-
- // Server Jobs
$this->scheduleUpdates($schedule);
$this->pull_images($schedule);
$this->check_resources($schedule);
@@ -76,11 +72,11 @@ class Kernel extends ConsoleKernel
{
$settings = InstanceSettings::get();
- $updateCheckFrequency = $settings->update_check_frequency ?? '0 0 * * *'; // Default to daily at 00:00
+ $updateCheckFrequency = $settings->update_check_frequency ?? '0 0 * * *';
$schedule->job(new CheckForUpdatesJob())->cron($updateCheckFrequency)->onOneServer();
if ($settings->is_auto_update_enabled) {
- $autoUpdateFrequency = $settings->auto_update_frequency ?? '0 11,23 * * *'; // Default to twice daily at 11:00 and 23:00
+ $autoUpdateFrequency = $settings->auto_update_frequency ?? '0 11,23 * * *';
$schedule->job(new UpdateCoolifyJob())->cron($autoUpdateFrequency)->onOneServer();
}
}
diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php
index 2f4c77535..60cd46907 100644
--- a/app/Livewire/Settings/Configuration.php
+++ b/app/Livewire/Settings/Configuration.php
@@ -91,7 +91,6 @@ class Configuration extends Component
}
$this->validate();
- // Allow empty values and set defaults
if ($this->is_auto_update_enabled && !$this->validateCronExpression($this->auto_update_frequency)) {
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
return;
From d4cb7e25dcb9d3525bb228c8f0d7b7c5bcdef429 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Mon, 5 Aug 2024 21:04:47 +0200
Subject: [PATCH 072/122] renamed database migration file
---
...2659_add_auto_update_frequency_and_update_check_frequency.php} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename database/migrations/{2024_08_05_142659_add_new_version_available_to_instance_settings_table.php => 2024_08_05_142659_add_auto_update_frequency_and_update_check_frequency.php} (100%)
diff --git a/database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php b/database/migrations/2024_08_05_142659_add_auto_update_frequency_and_update_check_frequency.php
similarity index 100%
rename from database/migrations/2024_08_05_142659_add_new_version_available_to_instance_settings_table.php
rename to database/migrations/2024_08_05_142659_add_auto_update_frequency_and_update_check_frequency.php
From c5de1a25c35bfa96ab3b4eed89b67b504e84ace2 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 09:45:48 +0200
Subject: [PATCH 073/122] refactor: Remove unnecessary debug statement in
ServerCheckJob
---
app/Jobs/ServerCheckJob.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index d78642a3f..88caaacc4 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -72,7 +72,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
return 'Server is not ready.';
}
if (! $this->server->isSwarmWorker() && ! $this->server->isBuildServer()) {
- ray('Server is not a worker or build server.');
['containers' => $this->containers, 'containerReplicates' => $containerReplicates] = $this->server->getContainers();
if (is_null($this->containers)) {
return 'No containers found.';
From 74e8a4a70368979c4647beb82fb4f106b3a4f269 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 10:52:47 +0200
Subject: [PATCH 074/122] refactor: Simplify log drain installation and stop
log drain if necessary
---
app/Actions/Server/InstallLogDrain.php | 7 +------
app/Actions/Server/StopLogDrain.php | 20 ++++++++++++++++++++
app/Livewire/Server/LogDrains.php | 4 ++++
3 files changed, 25 insertions(+), 6 deletions(-)
create mode 100644 app/Actions/Server/StopLogDrain.php
diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php
index 6f74e020b..034d89fe7 100644
--- a/app/Actions/Server/InstallLogDrain.php
+++ b/app/Actions/Server/InstallLogDrain.php
@@ -24,12 +24,7 @@ class InstallLogDrain
}
try {
if ($type === 'none') {
- $command = [
- "echo 'Stopping old Fluent Bit'",
- 'docker rm -f coolify-log-drain || true',
- ];
-
- return instant_remote_process($command, $server);
+ return 'No log drain is enabled.';
} elseif ($type === 'newrelic') {
if (! $server->settings->is_logdrain_newrelic_enabled) {
throw new \Exception('New Relic log drain is not enabled.');
diff --git a/app/Actions/Server/StopLogDrain.php b/app/Actions/Server/StopLogDrain.php
new file mode 100644
index 000000000..a5bce94a5
--- /dev/null
+++ b/app/Actions/Server/StopLogDrain.php
@@ -0,0 +1,20 @@
+ false,
]);
}
+ if (! $this->server->isLogDrainEnabled()) {
+ StopLogDrain::dispatch($this->server);
+ }
$this->server->settings->save();
$this->dispatch('success', 'Settings saved.');
From e3c7c615c67d18df0bf1d18a494f2c88aa7ff6c2 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 10:53:13 +0200
Subject: [PATCH 075/122] refactor: Cleanup unnecessary dynamic proxy
configuration in Init command
---
app/Console/Commands/Init.php | 37 +++++++++++++++++++++++++++--------
app/Jobs/ServerCheckJob.php | 13 ------------
2 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index 5789d32fc..f5d5a892e 100644
--- a/app/Console/Commands/Init.php
+++ b/app/Console/Commands/Init.php
@@ -21,13 +21,15 @@ class Init extends Command
protected $description = 'Cleanup instance related stuffs';
+ public $servers = null;
+
public function handle()
{
+ $this->servers = Server::all();
$this->alive();
get_public_ips();
if (version_compare('4.0.0-beta.312', config('version'), '<=')) {
- $servers = Server::all();
- foreach ($servers as $server) {
+ foreach ($this->servers as $server) {
if ($server->settings->is_metrics_enabled === true) {
$server->settings->update(['is_metrics_enabled' => false]);
}
@@ -57,14 +59,15 @@ class Init extends Command
// Required for falsely deleted coolify db
$this->restore_coolify_db_backup();
$this->cleanup_unused_network_from_coolify_proxy();
+ $this->cleanup_unnecessary_dynamic_proxy_configuration();
$this->cleanup_in_progress_application_deployments();
$this->cleanup_stucked_helper_containers();
$this->call('cleanup:queue');
$this->call('cleanup:stucked-resources');
if (! isCloud()) {
try {
- $server = Server::find(0)->first();
- $server->setupDynamicProxyConfiguration();
+ $localhost = $this->servers->where('id', 0)->first();
+ $localhost->setupDynamicProxyConfiguration();
} catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
}
@@ -85,11 +88,30 @@ class Init extends Command
$this->call('cleanup:stucked-resources');
}
+ private function cleanup_unnecessary_dynamic_proxy_configuration()
+ {
+ if (isCloud()) {
+ foreach ($this->servers as $server) {
+ if (! $server->isFunctional()) {
+ continue;
+ }
+ if ($server->id === 0) {
+ continue;
+ }
+ $file = $server->proxyPath().'/dynamic/coolify.yaml';
+
+ return instant_remote_process([
+ "rm -f $file",
+ ], $server, false);
+
+ }
+ }
+ }
+
private function cleanup_unused_network_from_coolify_proxy()
{
ray()->clearAll();
- $servers = Server::all();
- foreach ($servers as $server) {
+ foreach ($this->servers as $server) {
if (! $server->isFunctional()) {
continue;
}
@@ -150,8 +172,7 @@ class Init extends Command
private function cleanup_stucked_helper_containers()
{
- $servers = Server::all();
- foreach ($servers as $server) {
+ foreach ($this->servers as $server) {
if ($server->isFunctional()) {
CleanupHelperContainersJob::dispatch($server);
}
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index 88caaacc4..6a2233726 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -106,7 +106,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
private function serverStatus()
{
- $this->removeUnnevessaryCoolifyYaml();
['uptime' => $uptime] = $this->server->validateConnection();
if ($uptime) {
if ($this->server->unreachable_notification_sent === true) {
@@ -138,18 +137,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
}
- private function removeUnnevessaryCoolifyYaml()
- {
- // This will remote the coolify.yaml file from the server as it is not needed on cloud servers
- if (isCloud() && $this->server->id !== 0) {
- $file = $this->server->proxyPath().'/dynamic/coolify.yaml';
-
- return instant_remote_process([
- "rm -f $file",
- ], $this->server, false);
- }
- }
-
private function checkLogDrainContainer()
{
$foundLogDrainContainer = $this->containers->filter(function ($value, $key) {
From 3c98b558f6818b00f84f1a4e64d69f93651744fc Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 11:16:49 +0200
Subject: [PATCH 076/122] fix: do not use port exposes on docker compose
buildpacks
---
app/Jobs/ApplicationDeploymentJob.php | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index d7b1a57da..d4d4ee1fb 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -871,8 +871,10 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$envs->push($env->key.'='.$real_value);
}
// Add PORT if not exists, use the first port as default
- if ($this->application->environment_variables_preview->where('key', 'PORT')->isEmpty()) {
- $envs->push("PORT={$ports[0]}");
+ if ($this->build_pack !== 'dockercompose') {
+ if ($this->application->environment_variables_preview->where('key', 'PORT')->isEmpty()) {
+ $envs->push("PORT={$ports[0]}");
+ }
}
// Add HOST if not exists
if ($this->application->environment_variables_preview->where('key', 'HOST')->isEmpty()) {
@@ -915,15 +917,17 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$envs->push($env->key.'='.$real_value);
}
// Add PORT if not exists, use the first port as default
- if ($this->application->environment_variables->where('key', 'PORT')->isEmpty()) {
- $envs->push("PORT={$ports[0]}");
+ if ($this->build_pack !== 'dockercompose') {
+ if ($this->application->environment_variables->where('key', 'PORT')->isEmpty()) {
+ $envs->push("PORT={$ports[0]}");
+ }
}
// Add HOST if not exists
if ($this->application->environment_variables->where('key', 'HOST')->isEmpty()) {
$envs->push('HOST=0.0.0.0');
}
}
-
+ ray($envs);
if ($envs->isEmpty()) {
$this->env_filename = null;
if ($this->use_build_server) {
@@ -1514,6 +1518,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
{
$this->create_workdir();
$ports = $this->application->main_port();
+ ray('generate_compose_file: ', $ports);
$onlyPort = null;
if (count($ports) > 0) {
$onlyPort = $ports[0];
From d9a079c28912b80889eca7e05629ad49f521d46c Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Tue, 6 Aug 2024 11:25:57 +0200
Subject: [PATCH 077/122] fix conflict in kernel.php
---
app/Console/Kernel.php | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 735b75de1..314205c60 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -12,6 +12,7 @@ use App\Jobs\PullHelperImageJob;
use App\Jobs\PullSentinelImageJob;
use App\Jobs\PullTemplatesFromCDN;
use App\Jobs\ScheduledTaskJob;
+use App\Jobs\ServerCheckJob;
use App\Jobs\ServerStatusJob;
use App\Jobs\UpdateCoolifyJob;
use App\Jobs\CheckForUpdatesJob;
@@ -33,23 +34,29 @@ class Kernel extends ConsoleKernel
$settings = InstanceSettings::get();
if (isDev()) {
+ // Instance Jobs
+ $schedule->command('horizon:snapshot')->everyMinute();
+ $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
+ $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer();
// Server Jobs
$this->check_scheduled_backups($schedule);
- $this->check_resources($schedule);
- $this->check_scheduled_backups($schedule);
+ $this->checkResourcesNew($schedule);
$this->check_scheduled_tasks($schedule);
$schedule->command('uploads:clear')->everyTwoMinutes();
} else {
// Instance Jobs
$schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->command('cleanup:unreachable-servers')->daily();
- $schedule->job(new PullTemplatesFromCDN)->daily()->onOneServer();
- $schedule->job(new CleanupInstanceStuffsJob)->everyFiveMinutes()->onOneServer();
$this->scheduleUpdates($schedule);
$this->pull_images($schedule);
- $this->check_resources($schedule);
- $this->check_scheduled_tasks($schedule);
+ $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
+ $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer();
+ $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
+
+ // Server Jobs
$this->check_scheduled_backups($schedule);
+ $this->checkResourcesNew($schedule);
+ $this->check_scheduled_tasks($schedule);
$schedule->command('cleanup:database --yes')->daily();
$schedule->command('uploads:clear')->everyTwoMinutes();
@@ -81,6 +88,21 @@ class Kernel extends ConsoleKernel
}
}
+ private function checkResourcesNew($schedule)
+ {
+ if (isCloud()) {
+ $servers = $this->all_servers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4');
+ $own = Team::find(0)->servers;
+ $servers = $servers->merge($own);
+ } else {
+ $servers = $this->all_servers->where('ip', '!=', '1.2.3.4');
+ }
+ foreach ($servers as $server) {
+ $schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer();
+ $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer();
+ }
+ }
+
private function check_resources($schedule)
{
if (isCloud()) {
From 22f04e4708939218b90f3f183ae0882c25f40991 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 11:27:10 +0200
Subject: [PATCH 078/122] refactor: Remove unnecessary debug statement in
ApplicationDeploymentJob
---
app/Jobs/ApplicationDeploymentJob.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index d4d4ee1fb..aaba7135d 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -927,7 +927,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$envs->push('HOST=0.0.0.0');
}
}
- ray($envs);
if ($envs->isEmpty()) {
$this->env_filename = null;
if ($this->use_build_server) {
From 93322dc3cfd7e688a851ac8b7b5e3567571606c6 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Tue, 6 Aug 2024 11:29:02 +0200
Subject: [PATCH 079/122] updated helper text
---
resources/views/livewire/settings/configuration.blade.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/views/livewire/settings/configuration.blade.php b/resources/views/livewire/settings/configuration.blade.php
index 08e39adbd..e49c9f397 100644
--- a/resources/views/livewire/settings/configuration.blade.php
+++ b/resources/views/livewire/settings/configuration.blade.php
@@ -47,7 +47,7 @@
@if($is_auto_update_enabled)
@endif
-
+
@endif
From d9edb1c72f33f3e2ff38e5b409000dc4993dcdfd Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Tue, 6 Aug 2024 11:32:37 +0200
Subject: [PATCH 080/122] fix
---
app/Console/Kernel.php | 2 +-
resources/views/livewire/settings/configuration.blade.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 314205c60..8e0a7d4b1 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -78,7 +78,7 @@ class Kernel extends ConsoleKernel
private function scheduleUpdates($schedule)
{
$settings = InstanceSettings::get();
-
+
$updateCheckFrequency = $settings->update_check_frequency ?? '0 0 * * *';
$schedule->job(new CheckForUpdatesJob())->cron($updateCheckFrequency)->onOneServer();
diff --git a/resources/views/livewire/settings/configuration.blade.php b/resources/views/livewire/settings/configuration.blade.php
index e49c9f397..8a6a6e572 100644
--- a/resources/views/livewire/settings/configuration.blade.php
+++ b/resources/views/livewire/settings/configuration.blade.php
@@ -47,7 +47,7 @@
@if($is_auto_update_enabled)
@endif
-
+
@endif
From 0ce41d2c1ce21da9758700d92be14e39e37ea94e Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 11:34:51 +0200
Subject: [PATCH 081/122] chore: Update registration view to display a notice
for first user that it will be an admin
---
app/Providers/FortifyServiceProvider.php | 6 +++++-
resources/views/auth/register.blade.php | 13 ++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php
index 9b0a81026..53a2e9281 100644
--- a/app/Providers/FortifyServiceProvider.php
+++ b/app/Providers/FortifyServiceProvider.php
@@ -44,6 +44,8 @@ class FortifyServiceProvider extends ServiceProvider
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::registerView(function () {
+ $isFirstUser = User::count() === 0;
+
$settings = \App\Models\InstanceSettings::get();
if (! $settings->is_registration_enabled) {
return redirect()->route('login');
@@ -51,7 +53,9 @@ class FortifyServiceProvider extends ServiceProvider
if (config('coolify.waitlist')) {
return redirect()->route('waitlist.index');
} else {
- return view('auth.register');
+ return view('auth.register', [
+ 'isFirstUser' => $isFirstUser,
+ ]);
}
});
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php
index 297640111..1d236a6c4 100644
--- a/resources/views/auth/register.blade.php
+++ b/resources/views/auth/register.blade.php
@@ -16,9 +16,16 @@ $email = getOldOrLocal('email', 'test3@example.com');
-
- Create an account
-
+
+
+ Create an account
+
+ @if ($isFirstUser)
+
This user will be the root user (full admin access).
+
+ @endif
+
-
From e897eb2999162cca9d661efc7ef48f287aeada07 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 13:27:06 +0200
Subject: [PATCH 096/122] fix: Stop resources gracefully
---
app/Actions/Application/StopApplication.php | 8 +++-----
app/Actions/Database/StopDatabase.php | 9 +++++----
app/Actions/Service/StopService.php | 9 ++++++---
app/Jobs/ApplicationDeploymentJob.php | 2 +-
4 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/app/Actions/Application/StopApplication.php b/app/Actions/Application/StopApplication.php
index 1f05e29ac..7155f9a0a 100644
--- a/app/Actions/Application/StopApplication.php
+++ b/app/Actions/Application/StopApplication.php
@@ -31,15 +31,13 @@ class StopApplication
} else {
$containers = getCurrentApplicationContainerStatus($server, $application->id, 0);
}
- ray($containers);
if ($containers->count() > 0) {
foreach ($containers as $container) {
$containerName = data_get($container, 'Names');
if ($containerName) {
- instant_remote_process(
- ["docker rm -f {$containerName}"],
- $server
- );
+ instant_remote_process(command: ["docker stop --time=30 $containerName"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm $containerName"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm -f {$containerName}"], server: $server, throwError: false);
}
}
}
diff --git a/app/Actions/Database/StopDatabase.php b/app/Actions/Database/StopDatabase.php
index e4903ff35..d562ec56f 100644
--- a/app/Actions/Database/StopDatabase.php
+++ b/app/Actions/Database/StopDatabase.php
@@ -22,10 +22,11 @@ class StopDatabase
if (! $server->isFunctional()) {
return 'Server is not functional';
}
- instant_remote_process(
- ["docker rm -f {$database->uuid}"],
- $server
- );
+
+ instant_remote_process(command: ["docker stop --time=30 $database->uuid"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm $database->uuid"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm -f $database->uuid"], server: $server, throwError: false);
+
if ($database->is_public) {
StopDatabaseProxy::run($database);
}
diff --git a/app/Actions/Service/StopService.php b/app/Actions/Service/StopService.php
index c7b1170a7..3dd91b4e2 100644
--- a/app/Actions/Service/StopService.php
+++ b/app/Actions/Service/StopService.php
@@ -19,18 +19,21 @@ class StopService
ray('Stopping service: '.$service->name);
$applications = $service->applications()->get();
foreach ($applications as $application) {
- instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server, false);
+ instant_remote_process(command: ["docker stop --time=30 {$application->name}-{$service->uuid}"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm {$application->name}-{$service->uuid}"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm -f {$application->name}-{$service->uuid}"], server: $server, throwError: false);
$application->update(['status' => 'exited']);
}
$dbs = $service->databases()->get();
foreach ($dbs as $db) {
- instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server, false);
+ instant_remote_process(command: ["docker stop --time=30 {$db->name}-{$service->uuid}"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm {$db->name}-{$service->uuid}"], server: $server, throwError: false);
+ instant_remote_process(command: ["docker rm -f {$db->name}-{$service->uuid}"], server: $server, throwError: false);
$db->update(['status' => 'exited']);
}
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy"], $service->server);
instant_remote_process(["docker network rm {$service->uuid}"], $service->server);
} catch (\Exception $e) {
- echo $e->getMessage();
ray($e->getMessage());
return $e->getMessage();
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index fad5ad185..473cbc679 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -2030,7 +2030,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
/**
* @param int $timeout in seconds
*/
- private function graceful_shutdown_container(string $containerName, int $timeout = 60)
+ private function graceful_shutdown_container(string $containerName, int $timeout = 30)
{
try {
$this->execute_remote_command(
From c648e0dff9e338fa3df5ccc9f160dac36d32410f Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 13:50:32 +0200
Subject: [PATCH 097/122] chore: Update navbar to include service status check
---
resources/views/livewire/project/service/navbar.blade.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php
index e972b3938..2e656b131 100644
--- a/resources/views/livewire/project/service/navbar.blade.php
+++ b/resources/views/livewire/project/service/navbar.blade.php
@@ -1,4 +1,4 @@
-
+
Service Startup
From c9a7af0ffadba7d4861cf690974641dcc8532ded Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 14:02:24 +0200
Subject: [PATCH 098/122] chore: Update navbar and configuration to improve
service status check functionality
---
app/Livewire/Project/Service/Navbar.php | 5 +++++
.../views/livewire/project/service/configuration.blade.php | 2 +-
resources/views/livewire/project/service/navbar.blade.php | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php
index 419fef505..674182df5 100644
--- a/app/Livewire/Project/Service/Navbar.php
+++ b/app/Livewire/Project/Service/Navbar.php
@@ -49,6 +49,11 @@ class Navbar extends Component
}
}
+ public function check_status_without_notification()
+ {
+ $this->dispatch('check_status');
+ }
+
public function check_status()
{
$this->dispatch('check_status');
diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php
index b9282dc91..5c6fe87fd 100644
--- a/resources/views/livewire/project/service/configuration.blade.php
+++ b/resources/views/livewire/project/service/configuration.blade.php
@@ -1,4 +1,4 @@
-
+
{{ data_get_str($service, 'name')->limit(10) }} > Configuration | Coolify
diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php
index 2e656b131..125f9121a 100644
--- a/resources/views/livewire/project/service/navbar.blade.php
+++ b/resources/views/livewire/project/service/navbar.blade.php
@@ -1,4 +1,4 @@
-
+
Service Startup
From 8b817dad8729a78acbdc3f8c64e05f887a28b55c Mon Sep 17 00:00:00 2001
From: andrasbacsai
Date: Tue, 6 Aug 2024 12:04:23 +0000
Subject: [PATCH 099/122] Fix styling
---
app/Console/Kernel.php | 8 ++++----
app/Jobs/CheckForUpdatesJob.php | 2 +-
app/Jobs/PullCoolifyImageJob.php | 2 +-
app/Jobs/UpdateCoolifyJob.php | 15 +++++++++------
app/Livewire/Settings/Configuration.php | 14 ++++++++------
5 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index aafda266e..8b1978d6f 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -2,6 +2,7 @@
namespace App\Console;
+use App\Jobs\CheckForUpdatesJob;
use App\Jobs\CheckLogDrainContainerJob;
use App\Jobs\CleanupInstanceStuffsJob;
use App\Jobs\ContainerStatusJob;
@@ -15,7 +16,6 @@ use App\Jobs\ScheduledTaskJob;
use App\Jobs\ServerCheckJob;
use App\Jobs\ServerStatusJob;
use App\Jobs\UpdateCoolifyJob;
-use App\Jobs\CheckForUpdatesJob;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ScheduledTask;
@@ -83,11 +83,11 @@ class Kernel extends ConsoleKernel
$settings = InstanceSettings::get();
$updateCheckFrequency = $settings->update_check_frequency ?? '0 0 * * *';
- $schedule->job(new CheckForUpdatesJob())->cron($updateCheckFrequency)->onOneServer();
+ $schedule->job(new CheckForUpdatesJob)->cron($updateCheckFrequency)->onOneServer();
if ($settings->is_auto_update_enabled) {
$autoUpdateFrequency = $settings->auto_update_frequency ?? '0 11,23 * * *';
- $schedule->job(new UpdateCoolifyJob())->cron($autoUpdateFrequency)->onOneServer();
+ $schedule->job(new UpdateCoolifyJob)->cron($autoUpdateFrequency)->onOneServer();
}
}
@@ -214,4 +214,4 @@ class Kernel extends ConsoleKernel
require base_path('routes/console.php');
}
-}
\ No newline at end of file
+}
diff --git a/app/Jobs/CheckForUpdatesJob.php b/app/Jobs/CheckForUpdatesJob.php
index e18e37ed6..111baba8e 100644
--- a/app/Jobs/CheckForUpdatesJob.php
+++ b/app/Jobs/CheckForUpdatesJob.php
@@ -41,4 +41,4 @@ class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
// Consider implementing a notification to administrators
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Jobs/PullCoolifyImageJob.php b/app/Jobs/PullCoolifyImageJob.php
index 624dc4414..f0912493f 100644
--- a/app/Jobs/PullCoolifyImageJob.php
+++ b/app/Jobs/PullCoolifyImageJob.php
@@ -47,4 +47,4 @@ class PullCoolifyImageJob implements ShouldBeEncrypted, ShouldQueue
throw $e;
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Jobs/UpdateCoolifyJob.php b/app/Jobs/UpdateCoolifyJob.php
index 5c8e8e679..4da6025b4 100644
--- a/app/Jobs/UpdateCoolifyJob.php
+++ b/app/Jobs/UpdateCoolifyJob.php
@@ -2,6 +2,7 @@
namespace App\Jobs;
+use App\Actions\Server\UpdateCoolify;
use App\Models\InstanceSettings;
use App\Models\Server;
use Illuminate\Bus\Queueable;
@@ -10,7 +11,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
-use App\Actions\Server\UpdateCoolify;
use Illuminate\Support\Facades\Log;
class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
@@ -23,19 +23,22 @@ class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
{
try {
$settings = InstanceSettings::get();
- if (!$settings->is_auto_update_enabled) {
+ if (! $settings->is_auto_update_enabled) {
Log::info('Auto-update is disabled. Skipping update check.');
+
return;
}
- if (!$settings->new_version_available) {
+ if (! $settings->new_version_available) {
Log::info('No new version available. Skipping update.');
+
return;
}
$server = Server::findOrFail(0);
- if (!$server) {
+ if (! $server) {
Log::error('Server not found. Cannot proceed with update.');
+
return;
}
@@ -46,8 +49,8 @@ class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
Log::info('Coolify update completed successfully.');
} catch (\Throwable $e) {
- Log::error('UpdateCoolifyJob failed: ' . $e->getMessage());
+ Log::error('UpdateCoolifyJob failed: '.$e->getMessage());
// Consider implementing a notification to administrators
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php
index 60cd46907..d13bd79c1 100644
--- a/app/Livewire/Settings/Configuration.php
+++ b/app/Livewire/Settings/Configuration.php
@@ -4,8 +4,8 @@ namespace App\Livewire\Settings;
use App\Models\InstanceSettings as ModelsInstanceSettings;
use App\Models\Server;
-use Livewire\Component;
use Cron\CronExpression;
+use Livewire\Component;
class Configuration extends Component
{
@@ -91,13 +91,15 @@ class Configuration extends Component
}
$this->validate();
- if ($this->is_auto_update_enabled && !$this->validateCronExpression($this->auto_update_frequency)) {
+ if ($this->is_auto_update_enabled && ! $this->validateCronExpression($this->auto_update_frequency)) {
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
+
return;
}
- if (!$this->validateCronExpression($this->update_check_frequency)) {
+ if (! $this->validateCronExpression($this->update_check_frequency)) {
$this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
+
return;
}
@@ -163,15 +165,15 @@ class Configuration extends Component
public function updatedAutoUpdateFrequency()
{
- if (!$this->validateCronExpression($this->auto_update_frequency)) {
+ if (! $this->validateCronExpression($this->auto_update_frequency)) {
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
}
}
public function updatedUpdateCheckFrequency()
{
- if (!$this->validateCronExpression($this->update_check_frequency)) {
+ if (! $this->validateCronExpression($this->update_check_frequency)) {
$this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
}
}
-}
\ No newline at end of file
+}
From b77171d2f2d6c6b123d7173c8240fb4def979619 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 14:36:56 +0200
Subject: [PATCH 100/122] fix: settings view feat: add separate views for
settings
---
app/Console/Kernel.php | 48 +----
app/Livewire/Settings/Configuration.php | 177 -----------------
app/Livewire/Settings/Index.php | 179 ++++++++++++++++--
.../Backup.php => SettingsBackup.php} | 24 ++-
.../{Settings/Email.php => SettingsEmail.php} | 12 +-
.../{Settings/Auth.php => SettingsOauth.php} | 4 +-
.../components/settings/navbar.blade.php | 12 ++
...up.blade.php => settings-backup.blade.php} | 6 +-
...ail.blade.php => settings-email.blade.php} | 4 +
...uth.blade.php => settings-oauth.blade.php} | 22 ++-
.../livewire/settings/configuration.blade.php | 55 ------
.../views/livewire/settings/index.blade.php | 86 ++++++---
routes/web.php | 6 +
13 files changed, 301 insertions(+), 334 deletions(-)
delete mode 100644 app/Livewire/Settings/Configuration.php
rename app/Livewire/{Settings/Backup.php => SettingsBackup.php} (77%)
rename app/Livewire/{Settings/Email.php => SettingsEmail.php} (93%)
rename app/Livewire/{Settings/Auth.php => SettingsOauth.php} (95%)
rename resources/views/livewire/{settings/backup.blade.php => settings-backup.blade.php} (90%)
rename resources/views/livewire/{settings/email.blade.php => settings-email.blade.php} (97%)
rename resources/views/livewire/{settings/auth.blade.php => settings-oauth.blade.php} (61%)
delete mode 100644 resources/views/livewire/settings/configuration.blade.php
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index aafda266e..3bb3cba2f 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -2,9 +2,8 @@
namespace App\Console;
-use App\Jobs\CheckLogDrainContainerJob;
+use App\Jobs\CheckForUpdatesJob;
use App\Jobs\CleanupInstanceStuffsJob;
-use App\Jobs\ContainerStatusJob;
use App\Jobs\DatabaseBackupJob;
use App\Jobs\DockerCleanupJob;
use App\Jobs\PullCoolifyImageJob;
@@ -13,9 +12,7 @@ use App\Jobs\PullSentinelImageJob;
use App\Jobs\PullTemplatesFromCDN;
use App\Jobs\ScheduledTaskJob;
use App\Jobs\ServerCheckJob;
-use App\Jobs\ServerStatusJob;
use App\Jobs\UpdateCoolifyJob;
-use App\Jobs\CheckForUpdatesJob;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ScheduledTask;
@@ -41,8 +38,6 @@ class Kernel extends ConsoleKernel
// Server Jobs
$this->check_scheduled_backups($schedule);
$this->checkResourcesNew($schedule);
- // $this->check_resources($schedule);
- $this->check_scheduled_backups($schedule);
$this->check_scheduled_tasks($schedule);
$schedule->command('uploads:clear')->everyTwoMinutes();
} else {
@@ -57,7 +52,6 @@ class Kernel extends ConsoleKernel
// Server Jobs
$this->check_scheduled_backups($schedule);
$this->checkResourcesNew($schedule);
- // $this->check_resources($schedule);
$this->pull_images($schedule);
$this->check_scheduled_tasks($schedule);
@@ -106,44 +100,6 @@ class Kernel extends ConsoleKernel
}
}
- private function checkResourcesNew($schedule)
- {
- if (isCloud()) {
- $servers = $this->all_servers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4');
- $own = Team::find(0)->servers;
- $servers = $servers->merge($own);
- } else {
- $servers = $this->all_servers->where('ip', '!=', '1.2.3.4');
- }
- foreach ($servers as $server) {
- $schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer();
- $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer();
- }
- }
-
- private function check_resources($schedule)
- {
- if (isCloud()) {
- $servers = $this->all_servers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4');
- $own = Team::find(0)->servers;
- $servers = $servers->merge($own);
- $containerServers = $servers->where('settings.is_swarm_worker', false)->where('settings.is_build_server', false);
- } else {
- $servers = $this->all_servers->where('ip', '!=', '1.2.3.4');
- $containerServers = $servers->where('settings.is_swarm_worker', false)->where('settings.is_build_server', false);
- }
- foreach ($containerServers as $server) {
- $schedule->job(new ContainerStatusJob($server))->everyMinute()->onOneServer();
- if ($server->isLogDrainEnabled()) {
- $schedule->job(new CheckLogDrainContainerJob($server))->everyMinute()->onOneServer();
- }
- }
- foreach ($servers as $server) {
- $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer();
- $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer();
- }
- }
-
private function check_scheduled_backups($schedule)
{
$scheduled_backups = ScheduledDatabaseBackup::all();
@@ -214,4 +170,4 @@ class Kernel extends ConsoleKernel
require base_path('routes/console.php');
}
-}
\ No newline at end of file
+}
diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php
deleted file mode 100644
index 60cd46907..000000000
--- a/app/Livewire/Settings/Configuration.php
+++ /dev/null
@@ -1,177 +0,0 @@
- 'nullable',
- 'settings.resale_license' => 'nullable',
- 'settings.public_port_min' => 'required',
- 'settings.public_port_max' => 'required',
- 'settings.custom_dns_servers' => 'nullable',
- 'settings.instance_name' => 'nullable',
- 'settings.allowed_ips' => 'nullable',
- 'settings.is_auto_update_enabled' => 'boolean',
- 'auto_update_frequency' => 'nullable|string',
- 'update_check_frequency' => 'nullable|string',
- ];
-
- protected $validationAttributes = [
- 'settings.fqdn' => 'FQDN',
- 'settings.resale_license' => 'Resale License',
- 'settings.public_port_min' => 'Public port min',
- 'settings.public_port_max' => 'Public port max',
- 'settings.custom_dns_servers' => 'Custom DNS servers',
- 'settings.allowed_ips' => 'Allowed IPs',
- 'settings.is_auto_update_enabled' => 'Auto Update Enabled',
- 'auto_update_frequency' => 'Auto Update Frequency',
- 'update_check_frequency' => 'Update Check Frequency',
- ];
-
- public function mount()
- {
- $this->do_not_track = $this->settings->do_not_track;
- $this->is_auto_update_enabled = $this->settings->is_auto_update_enabled;
- $this->is_registration_enabled = $this->settings->is_registration_enabled;
- $this->is_dns_validation_enabled = $this->settings->is_dns_validation_enabled;
- $this->is_api_enabled = $this->settings->is_api_enabled;
- $this->auto_update_frequency = $this->settings->auto_update_frequency;
- $this->update_check_frequency = $this->settings->update_check_frequency;
- }
-
- public function instantSave()
- {
- $this->settings->do_not_track = $this->do_not_track;
- $this->settings->is_auto_update_enabled = $this->is_auto_update_enabled;
- $this->settings->is_registration_enabled = $this->is_registration_enabled;
- $this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
- $this->settings->is_api_enabled = $this->is_api_enabled;
- $this->settings->auto_update_frequency = $this->auto_update_frequency;
- $this->settings->update_check_frequency = $this->update_check_frequency;
- $this->settings->save();
- $this->dispatch('success', 'Settings updated!');
- }
-
- public function submit()
- {
- try {
- $error_show = false;
- $this->server = Server::findOrFail(0);
- $this->resetErrorBag();
- if ($this->settings->public_port_min > $this->settings->public_port_max) {
- $this->addError('settings.public_port_min', 'The minimum port must be lower than the maximum port.');
-
- return;
- }
- $this->validate();
-
- if ($this->is_auto_update_enabled && !$this->validateCronExpression($this->auto_update_frequency)) {
- $this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
- return;
- }
-
- if (!$this->validateCronExpression($this->update_check_frequency)) {
- $this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
- return;
- }
-
- if ($this->settings->is_dns_validation_enabled && $this->settings->fqdn) {
- if (! validate_dns_entry($this->settings->fqdn, $this->server)) {
- $this->dispatch('error', "Validating DNS failed.
Make sure you have added the DNS records correctly.
{$this->settings->fqdn}->{$this->server->ip}
Check this documentation for further help.");
- $error_show = true;
- }
- }
- if ($this->settings->fqdn) {
- check_domain_usage(domain: $this->settings->fqdn);
- }
- $this->settings->custom_dns_servers = str($this->settings->custom_dns_servers)->replaceEnd(',', '')->trim();
- $this->settings->custom_dns_servers = str($this->settings->custom_dns_servers)->trim()->explode(',')->map(function ($dns) {
- return str($dns)->trim()->lower();
- });
- $this->settings->custom_dns_servers = $this->settings->custom_dns_servers->unique();
- $this->settings->custom_dns_servers = $this->settings->custom_dns_servers->implode(',');
-
- $this->settings->allowed_ips = str($this->settings->allowed_ips)->replaceEnd(',', '')->trim();
- $this->settings->allowed_ips = str($this->settings->allowed_ips)->trim()->explode(',')->map(function ($ip) {
- return str($ip)->trim();
- });
- $this->settings->allowed_ips = $this->settings->allowed_ips->unique();
- $this->settings->allowed_ips = $this->settings->allowed_ips->implode(',');
-
- $this->settings->do_not_track = $this->do_not_track;
- $this->settings->is_auto_update_enabled = $this->is_auto_update_enabled;
- $this->settings->is_registration_enabled = $this->is_registration_enabled;
- $this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
- $this->settings->is_api_enabled = $this->is_api_enabled;
- $this->settings->auto_update_frequency = $this->auto_update_frequency;
- $this->settings->update_check_frequency = $this->update_check_frequency;
- $this->settings->save();
- $this->server->setupDynamicProxyConfiguration();
- if (! $error_show) {
- $this->dispatch('success', 'Instance settings updated successfully!');
- }
- } catch (\Exception $e) {
- return handleError($e, $this);
- }
- }
-
- private function validateCronExpression($expression): bool
- {
- if (empty($expression)) {
- return true;
- }
- $isValid = false;
- try {
- $cronExpression = new CronExpression($expression);
- $isValid = $cronExpression->getNextRunDate() !== false;
- } catch (\Exception $e) {
- $isValid = false;
- }
-
- if (isset(VALID_CRON_STRINGS[$expression])) {
- $isValid = true;
- }
-
- return $isValid;
- }
-
- public function updatedAutoUpdateFrequency()
- {
- if (!$this->validateCronExpression($this->auto_update_frequency)) {
- $this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
- }
- }
-
- public function updatedUpdateCheckFrequency()
- {
- if (!$this->validateCronExpression($this->update_check_frequency)) {
- $this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
- }
- }
-}
\ No newline at end of file
diff --git a/app/Livewire/Settings/Index.php b/app/Livewire/Settings/Index.php
index e71d2de00..18132c670 100644
--- a/app/Livewire/Settings/Index.php
+++ b/app/Livewire/Settings/Index.php
@@ -3,38 +3,185 @@
namespace App\Livewire\Settings;
use App\Models\InstanceSettings;
-use App\Models\S3Storage;
-use App\Models\StandalonePostgresql;
+use App\Models\Server;
+use Cron\CronExpression;
use Livewire\Component;
class Index extends Component
{
public InstanceSettings $settings;
- public StandalonePostgresql $database;
+ public bool $do_not_track;
- public $s3s;
+ public bool $is_auto_update_enabled;
+
+ public bool $is_registration_enabled;
+
+ public bool $is_dns_validation_enabled;
+
+ public bool $is_api_enabled;
+
+ public string $auto_update_frequency;
+
+ public string $update_check_frequency;
+
+ protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
+
+ protected Server $server;
+
+ protected $rules = [
+ 'settings.fqdn' => 'nullable',
+ 'settings.resale_license' => 'nullable',
+ 'settings.public_port_min' => 'required',
+ 'settings.public_port_max' => 'required',
+ 'settings.custom_dns_servers' => 'nullable',
+ 'settings.instance_name' => 'nullable',
+ 'settings.allowed_ips' => 'nullable',
+ 'settings.is_auto_update_enabled' => 'boolean',
+ 'auto_update_frequency' => 'nullable|string',
+ 'update_check_frequency' => 'nullable|string',
+ ];
+
+ protected $validationAttributes = [
+ 'settings.fqdn' => 'FQDN',
+ 'settings.resale_license' => 'Resale License',
+ 'settings.public_port_min' => 'Public port min',
+ 'settings.public_port_max' => 'Public port max',
+ 'settings.custom_dns_servers' => 'Custom DNS servers',
+ 'settings.allowed_ips' => 'Allowed IPs',
+ 'settings.is_auto_update_enabled' => 'Auto Update Enabled',
+ 'auto_update_frequency' => 'Auto Update Frequency',
+ 'update_check_frequency' => 'Update Check Frequency',
+ ];
public function mount()
{
if (isInstanceAdmin()) {
- $settings = \App\Models\InstanceSettings::get();
- $database = StandalonePostgresql::whereName('coolify-db')->first();
- $s3s = S3Storage::whereTeamId(0)->get() ?? [];
- if ($database) {
- if ($database->status !== 'running') {
- $database->status = 'running';
- $database->save();
- }
- $this->database = $database;
- }
- $this->settings = $settings;
- $this->s3s = $s3s;
+ $this->settings = InstanceSettings::get();
+ $this->do_not_track = $this->settings->do_not_track;
+ $this->is_auto_update_enabled = $this->settings->is_auto_update_enabled;
+ $this->is_registration_enabled = $this->settings->is_registration_enabled;
+ $this->is_dns_validation_enabled = $this->settings->is_dns_validation_enabled;
+ $this->is_api_enabled = $this->settings->is_api_enabled;
+ $this->auto_update_frequency = $this->settings->auto_update_frequency;
+ $this->update_check_frequency = $this->settings->update_check_frequency;
} else {
return redirect()->route('dashboard');
}
}
+ public function instantSave()
+ {
+ $this->settings->do_not_track = $this->do_not_track;
+ $this->settings->is_auto_update_enabled = $this->is_auto_update_enabled;
+ $this->settings->is_registration_enabled = $this->is_registration_enabled;
+ $this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
+ $this->settings->is_api_enabled = $this->is_api_enabled;
+ $this->settings->auto_update_frequency = $this->auto_update_frequency;
+ $this->settings->update_check_frequency = $this->update_check_frequency;
+ $this->settings->save();
+ $this->dispatch('success', 'Settings updated!');
+ }
+
+ public function submit()
+ {
+ try {
+ $error_show = false;
+ $this->server = Server::findOrFail(0);
+ $this->resetErrorBag();
+ if ($this->settings->public_port_min > $this->settings->public_port_max) {
+ $this->addError('settings.public_port_min', 'The minimum port must be lower than the maximum port.');
+
+ return;
+ }
+ $this->validate();
+
+ if ($this->is_auto_update_enabled && ! $this->validateCronExpression($this->auto_update_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
+
+ return;
+ }
+
+ if (! $this->validateCronExpression($this->update_check_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
+
+ return;
+ }
+
+ if ($this->settings->is_dns_validation_enabled && $this->settings->fqdn) {
+ if (! validate_dns_entry($this->settings->fqdn, $this->server)) {
+ $this->dispatch('error', "Validating DNS failed.
Make sure you have added the DNS records correctly.
{$this->settings->fqdn}->{$this->server->ip}
Check this documentation for further help.");
+ $error_show = true;
+ }
+ }
+ if ($this->settings->fqdn) {
+ check_domain_usage(domain: $this->settings->fqdn);
+ }
+ $this->settings->custom_dns_servers = str($this->settings->custom_dns_servers)->replaceEnd(',', '')->trim();
+ $this->settings->custom_dns_servers = str($this->settings->custom_dns_servers)->trim()->explode(',')->map(function ($dns) {
+ return str($dns)->trim()->lower();
+ });
+ $this->settings->custom_dns_servers = $this->settings->custom_dns_servers->unique();
+ $this->settings->custom_dns_servers = $this->settings->custom_dns_servers->implode(',');
+
+ $this->settings->allowed_ips = str($this->settings->allowed_ips)->replaceEnd(',', '')->trim();
+ $this->settings->allowed_ips = str($this->settings->allowed_ips)->trim()->explode(',')->map(function ($ip) {
+ return str($ip)->trim();
+ });
+ $this->settings->allowed_ips = $this->settings->allowed_ips->unique();
+ $this->settings->allowed_ips = $this->settings->allowed_ips->implode(',');
+
+ $this->settings->do_not_track = $this->do_not_track;
+ $this->settings->is_auto_update_enabled = $this->is_auto_update_enabled;
+ $this->settings->is_registration_enabled = $this->is_registration_enabled;
+ $this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
+ $this->settings->is_api_enabled = $this->is_api_enabled;
+ $this->settings->auto_update_frequency = $this->auto_update_frequency;
+ $this->settings->update_check_frequency = $this->update_check_frequency;
+ $this->settings->save();
+ $this->server->setupDynamicProxyConfiguration();
+ if (! $error_show) {
+ $this->dispatch('success', 'Instance settings updated successfully!');
+ }
+ } catch (\Exception $e) {
+ return handleError($e, $this);
+ }
+ }
+
+ private function validateCronExpression($expression): bool
+ {
+ if (empty($expression)) {
+ return true;
+ }
+ $isValid = false;
+ try {
+ $cronExpression = new CronExpression($expression);
+ $isValid = $cronExpression->getNextRunDate() !== false;
+ } catch (\Exception $e) {
+ $isValid = false;
+ }
+
+ if (isset(VALID_CRON_STRINGS[$expression])) {
+ $isValid = true;
+ }
+
+ return $isValid;
+ }
+
+ public function updatedAutoUpdateFrequency()
+ {
+ if (! $this->validateCronExpression($this->auto_update_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
+ }
+ }
+
+ public function updatedUpdateCheckFrequency()
+ {
+ if (! $this->validateCronExpression($this->update_check_frequency)) {
+ $this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
+ }
+ }
+
public function render()
{
return view('livewire.settings.index');
diff --git a/app/Livewire/Settings/Backup.php b/app/Livewire/SettingsBackup.php
similarity index 77%
rename from app/Livewire/Settings/Backup.php
rename to app/Livewire/SettingsBackup.php
index 08ad04b2d..da3aee491 100644
--- a/app/Livewire/Settings/Backup.php
+++ b/app/Livewire/SettingsBackup.php
@@ -1,6 +1,6 @@
backup = $this->database?->scheduledBackups->first() ?? null;
- $this->executions = $this->backup?->executions ?? [];
+ if (isInstanceAdmin()) {
+ $settings = InstanceSettings::get();
+ $database = StandalonePostgresql::whereName('coolify-db')->first();
+ $s3s = S3Storage::whereTeamId(0)->get() ?? [];
+ if ($database) {
+ if ($database->status !== 'running') {
+ $database->status = 'running';
+ $database->save();
+ }
+ $this->database = $database;
+ }
+ $this->settings = $settings;
+ $this->s3s = $s3s;
+ $this->backup = $this->database?->scheduledBackups?->first() ?? null;
+ $this->executions = $this->backup?->executions ?? [];
+ } else {
+ return redirect()->route('dashboard');
+ }
}
public function add_coolify_database()
diff --git a/app/Livewire/Settings/Email.php b/app/Livewire/SettingsEmail.php
similarity index 93%
rename from app/Livewire/Settings/Email.php
rename to app/Livewire/SettingsEmail.php
index bd7f8201e..3eb8ea646 100644
--- a/app/Livewire/Settings/Email.php
+++ b/app/Livewire/SettingsEmail.php
@@ -1,12 +1,12 @@
emails = auth()->user()->email;
+ if (isInstanceAdmin()) {
+ $this->settings = InstanceSettings::get();
+ $this->emails = auth()->user()->email;
+ } else {
+ return redirect()->route('dashboard');
+ }
+
}
public function submitFromFields()
diff --git a/app/Livewire/Settings/Auth.php b/app/Livewire/SettingsOauth.php
similarity index 95%
rename from app/Livewire/Settings/Auth.php
rename to app/Livewire/SettingsOauth.php
index 783b163e0..c3884589f 100644
--- a/app/Livewire/Settings/Auth.php
+++ b/app/Livewire/SettingsOauth.php
@@ -1,11 +1,11 @@
Resale License
@endif
+
+
+
+
+
+
+
+
+
diff --git a/resources/views/livewire/settings/backup.blade.php b/resources/views/livewire/settings-backup.blade.php
similarity index 90%
rename from resources/views/livewire/settings/backup.blade.php
rename to resources/views/livewire/settings-backup.blade.php
index d517b9516..bf29481cc 100644
--- a/resources/views/livewire/settings/backup.blade.php
+++ b/resources/views/livewire/settings-backup.blade.php
@@ -1,4 +1,8 @@
+
+ Settings | Coolify
+
+
Backup
@@ -8,7 +12,7 @@
@endif
-
Backup your Coolify instance settings
+
Backup configuration for Coolify instance.
@if (isset($database))
diff --git a/resources/views/livewire/settings/email.blade.php b/resources/views/livewire/settings-email.blade.php
similarity index 97%
rename from resources/views/livewire/settings/email.blade.php
rename to resources/views/livewire/settings-email.blade.php
index 106dd77d4..37d395cd8 100644
--- a/resources/views/livewire/settings/email.blade.php
+++ b/resources/views/livewire/settings-email.blade.php
@@ -1,4 +1,8 @@
+
+ Settings | Coolify
+
+
Transactional Email
diff --git a/resources/views/livewire/settings/auth.blade.php b/resources/views/livewire/settings-oauth.blade.php
similarity index 61%
rename from resources/views/livewire/settings/auth.blade.php
rename to resources/views/livewire/settings-oauth.blade.php
index 46aa40fa5..9a94d3c2b 100644
--- a/resources/views/livewire/settings/auth.blade.php
+++ b/resources/views/livewire/settings-oauth.blade.php
@@ -1,4 +1,8 @@
+
+ Settings | Coolify
+
+