diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.php index 8671a5f27..bfc65d8d2 100644 --- a/app/Actions/Proxy/StartProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -13,7 +13,7 @@ class StartProxy { use AsAction; - public function handle(Server $server, bool $async = true, bool $force = false): string|Activity + public function handle(Server $server, bool $async = true, bool $force = false, bool $restarting = false): string|Activity { $proxyType = $server->proxyType(); if ((is_null($proxyType) || $proxyType === 'NONE' || $server->proxy->force_stop || $server->isBuildServer()) && $force === false) { @@ -22,7 +22,10 @@ public function handle(Server $server, bool $async = true, bool $force = false): $server->proxy->set('status', 'starting'); $server->save(); $server->refresh(); - ProxyStatusChangedUI::dispatch($server->team_id); + + if (! $restarting) { + ProxyStatusChangedUI::dispatch($server->team_id); + } $commands = collect([]); $proxy_path = $server->proxyPath(); @@ -60,7 +63,16 @@ public function handle(Server $server, bool $async = true, bool $force = false): 'docker compose pull', 'if docker ps -a --format "{{.Names}}" | grep -q "^coolify-proxy$"; then', " echo 'Stopping and removing existing coolify-proxy.'", - ' docker rm -f coolify-proxy || true', + ' docker stop coolify-proxy 2>/dev/null || true', + ' docker rm -f coolify-proxy 2>/dev/null || true', + ' # Wait for container to be fully removed', + ' for i in {1..10}; do', + ' if ! docker ps -a --format "{{.Names}}" | grep -q "^coolify-proxy$"; then', + ' break', + ' fi', + ' echo "Waiting for coolify-proxy to be removed... ($i/10)"', + ' sleep 1', + ' done', " echo 'Successfully stopped and removed existing coolify-proxy.'", 'fi', "echo 'Starting coolify-proxy.'", diff --git a/app/Actions/Proxy/StopProxy.php b/app/Actions/Proxy/StopProxy.php index 29cc63b40..8f1b8af1c 100644 --- a/app/Actions/Proxy/StopProxy.php +++ b/app/Actions/Proxy/StopProxy.php @@ -12,17 +12,27 @@ class StopProxy { use AsAction; - public function handle(Server $server, bool $forceStop = true, int $timeout = 30) + public function handle(Server $server, bool $forceStop = true, int $timeout = 30, bool $restarting = false) { try { $containerName = $server->isSwarm() ? 'coolify-proxy_traefik' : 'coolify-proxy'; $server->proxy->status = 'stopping'; $server->save(); - ProxyStatusChangedUI::dispatch($server->team_id); + + if (! $restarting) { + ProxyStatusChangedUI::dispatch($server->team_id); + } instant_remote_process(command: [ - "docker stop --time=$timeout $containerName", - "docker rm -f $containerName", + "docker stop --time=$timeout $containerName 2>/dev/null || true", + "docker rm -f $containerName 2>/dev/null || true", + '# Wait for container to be fully removed', + 'for i in {1..10}; do', + " if ! docker ps -a --format \"{{.Names}}\" | grep -q \"^$containerName$\"; then", + ' break', + ' fi', + ' sleep 1', + 'done', ], server: $server, throwError: false); $server->proxy->force_stop = $forceStop; @@ -32,7 +42,10 @@ public function handle(Server $server, bool $forceStop = true, int $timeout = 30 return handleError($e); } finally { ProxyDashboardCacheService::clearCache($server); - ProxyStatusChanged::dispatch($server->id); + + if (! $restarting) { + ProxyStatusChanged::dispatch($server->id); + } } } } diff --git a/app/Console/Commands/CheckTraefikVersionCommand.php b/app/Console/Commands/CheckTraefikVersionCommand.php new file mode 100644 index 000000000..48cc78093 --- /dev/null +++ b/app/Console/Commands/CheckTraefikVersionCommand.php @@ -0,0 +1,30 @@ +info('Checking Traefik versions on all servers...'); + + try { + CheckTraefikVersionJob::dispatch(); + $this->info('Traefik version check job dispatched successfully.'); + $this->info('Notifications will be sent to teams with outdated Traefik versions.'); + + return Command::SUCCESS; + } catch (\Exception $e) { + $this->error('Failed to dispatch Traefik version check job: '.$e->getMessage()); + + return Command::FAILURE; + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index c2ea27274..832bed5ae 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -5,6 +5,7 @@ use App\Jobs\CheckAndStartSentinelJob; use App\Jobs\CheckForUpdatesJob; use App\Jobs\CheckHelperImageJob; +use App\Jobs\CheckTraefikVersionJob; use App\Jobs\CleanupInstanceStuffsJob; use App\Jobs\PullChangelog; use App\Jobs\PullTemplatesFromCDN; @@ -83,6 +84,8 @@ protected function schedule(Schedule $schedule): void $this->scheduleInstance->job(new RegenerateSslCertJob)->twiceDaily(); + $this->scheduleInstance->job(new CheckTraefikVersionJob)->weekly()->sundays()->at('00:00')->timezone($this->instanceTimezone)->onOneServer(); + $this->scheduleInstance->command('cleanup:database --yes')->daily(); $this->scheduleInstance->command('uploads:clear')->everyTwoMinutes(); } diff --git a/app/Data/ServerMetadata.php b/app/Data/ServerMetadata.php index d95944b15..cdd9c8c08 100644 --- a/app/Data/ServerMetadata.php +++ b/app/Data/ServerMetadata.php @@ -10,6 +10,8 @@ class ServerMetadata extends Data { public function __construct( public ?ProxyTypes $type, - public ?ProxyStatus $status + public ?ProxyStatus $status, + public ?string $last_saved_settings = null, + public ?string $last_applied_settings = null ) {} } diff --git a/app/Jobs/CheckForUpdatesJob.php b/app/Jobs/CheckForUpdatesJob.php index 1d3a345e1..4f2bfa68c 100644 --- a/app/Jobs/CheckForUpdatesJob.php +++ b/app/Jobs/CheckForUpdatesJob.php @@ -33,6 +33,9 @@ public function handle(): void // New version available $settings->update(['new_version_available' => true]); File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT)); + + // Invalidate cache to ensure fresh data is loaded + invalidate_versions_cache(); } else { $settings->update(['new_version_available' => false]); } diff --git a/app/Jobs/CheckTraefikVersionForServerJob.php b/app/Jobs/CheckTraefikVersionForServerJob.php new file mode 100644 index 000000000..88484bcce --- /dev/null +++ b/app/Jobs/CheckTraefikVersionForServerJob.php @@ -0,0 +1,173 @@ +server); + + // Update detected version in database + $this->server->update(['detected_traefik_version' => $currentVersion]); + + if (! $currentVersion) { + return; + } + + // Check if image tag is 'latest' by inspecting the image (makes SSH call) + $imageTag = instant_remote_process([ + "docker inspect coolify-proxy --format '{{.Config.Image}}' 2>/dev/null", + ], $this->server, false); + + // Handle empty/null response from SSH command + if (empty(trim($imageTag))) { + return; + } + + if (str_contains(strtolower(trim($imageTag)), ':latest')) { + return; + } + + // Parse current version to extract major.minor.patch + $current = ltrim($currentVersion, 'v'); + if (! preg_match('/^(\d+\.\d+)\.(\d+)$/', $current, $matches)) { + return; + } + + $currentBranch = $matches[1]; // e.g., "3.6" + + // Find the latest version for this branch + $latestForBranch = $this->traefikVersions["v{$currentBranch}"] ?? null; + + if (! $latestForBranch) { + // User is on a branch we don't track - check if newer branches exist + $newerBranchInfo = $this->getNewerBranchInfo($currentBranch); + + if ($newerBranchInfo) { + $this->storeOutdatedInfo($current, $newerBranchInfo['latest'], 'minor_upgrade', $newerBranchInfo['target']); + } else { + // No newer branch found, clear outdated info + $this->server->update(['traefik_outdated_info' => null]); + } + + return; + } + + // Compare patch version within the same branch + $latest = ltrim($latestForBranch, 'v'); + + // Always check for newer branches first + $newerBranchInfo = $this->getNewerBranchInfo($currentBranch); + + if (version_compare($current, $latest, '<')) { + // Patch update available + $this->storeOutdatedInfo($current, $latest, 'patch_update', null, $newerBranchInfo); + } elseif ($newerBranchInfo) { + // Only newer branch available (no patch update) + $this->storeOutdatedInfo($current, $newerBranchInfo['latest'], 'minor_upgrade', $newerBranchInfo['target']); + } else { + // Fully up to date + $this->server->update(['traefik_outdated_info' => null]); + } + } + + /** + * Get information about newer branches if available. + */ + private function getNewerBranchInfo(string $currentBranch): ?array + { + $newestBranch = null; + $newestVersion = null; + + foreach ($this->traefikVersions as $branch => $version) { + $branchNum = ltrim($branch, 'v'); + if (version_compare($branchNum, $currentBranch, '>')) { + if (! $newestVersion || version_compare($version, $newestVersion, '>')) { + $newestBranch = $branchNum; + $newestVersion = $version; + } + } + } + + if ($newestVersion) { + return [ + 'target' => "v{$newestBranch}", + 'latest' => ltrim($newestVersion, 'v'), + ]; + } + + return null; + } + + /** + * Store outdated information in database and send immediate notification. + */ + private function storeOutdatedInfo(string $current, string $latest, string $type, ?string $upgradeTarget = null, ?array $newerBranchInfo = null): void + { + $outdatedInfo = [ + 'current' => $current, + 'latest' => $latest, + 'type' => $type, + 'checked_at' => now()->toIso8601String(), + ]; + + // For minor upgrades, add the upgrade_target field (e.g., "v3.6") + if ($type === 'minor_upgrade' && $upgradeTarget) { + $outdatedInfo['upgrade_target'] = $upgradeTarget; + } + + // If there's a newer branch available (even for patch updates), include that info + if ($newerBranchInfo) { + $outdatedInfo['newer_branch_target'] = $newerBranchInfo['target']; + $outdatedInfo['newer_branch_latest'] = $newerBranchInfo['latest']; + } + + $this->server->update(['traefik_outdated_info' => $outdatedInfo]); + + // Send immediate notification to the team + $this->sendNotification($outdatedInfo); + } + + /** + * Send notification to team about outdated Traefik. + */ + private function sendNotification(array $outdatedInfo): void + { + // Attach the outdated info as a dynamic property for the notification + $this->server->outdatedInfo = $outdatedInfo; + + // Get the team and send notification + $team = $this->server->team()->first(); + + if ($team) { + $team->notify(new TraefikVersionOutdated(collect([$this->server]))); + } + } +} diff --git a/app/Jobs/CheckTraefikVersionJob.php b/app/Jobs/CheckTraefikVersionJob.php new file mode 100644 index 000000000..a513f280e --- /dev/null +++ b/app/Jobs/CheckTraefikVersionJob.php @@ -0,0 +1,45 @@ +whereProxyType(ProxyTypes::TRAEFIK->value) + ->whereRelation('settings', 'is_reachable', true) + ->whereRelation('settings', 'is_usable', true) + ->get(); + + if ($servers->isEmpty()) { + return; + } + + // Dispatch individual server check jobs in parallel + // Each job will send immediate notifications when outdated Traefik is detected + foreach ($servers as $server) { + CheckTraefikVersionForServerJob::dispatch($server, $traefikVersions); + } + } +} diff --git a/app/Jobs/RestartProxyJob.php b/app/Jobs/RestartProxyJob.php index dba4f4ac8..e3e809c8d 100644 --- a/app/Jobs/RestartProxyJob.php +++ b/app/Jobs/RestartProxyJob.php @@ -31,12 +31,12 @@ public function __construct(public Server $server) {} public function handle() { try { - StopProxy::run($this->server); + StopProxy::run($this->server, restarting: true); $this->server->proxy->force_stop = false; $this->server->save(); - StartProxy::run($this->server, force: true); + StartProxy::run($this->server, force: true, restarting: true); } catch (\Throwable $e) { return handleError($e); diff --git a/app/Livewire/Boarding/Index.php b/app/Livewire/Boarding/Index.php index 7912c4b85..9f1eac4d2 100644 --- a/app/Livewire/Boarding/Index.php +++ b/app/Livewire/Boarding/Index.php @@ -347,6 +347,8 @@ public function selectProxy(?string $proxyType = null) } $this->createdServer->proxy->type = $proxyType; $this->createdServer->proxy->status = 'exited'; + $this->createdServer->proxy->last_saved_settings = null; + $this->createdServer->proxy->last_applied_settings = null; $this->createdServer->save(); $this->getProjects(); } diff --git a/app/Livewire/Notifications/Discord.php b/app/Livewire/Notifications/Discord.php index 28d1cb866..b914fbd94 100644 --- a/app/Livewire/Notifications/Discord.php +++ b/app/Livewire/Notifications/Discord.php @@ -62,6 +62,9 @@ class Discord extends Component #[Validate(['boolean'])] public bool $serverPatchDiscordNotifications = false; + #[Validate(['boolean'])] + public bool $traefikOutdatedDiscordNotifications = true; + #[Validate(['boolean'])] public bool $discordPingEnabled = true; @@ -98,6 +101,7 @@ public function syncData(bool $toModel = false) $this->settings->server_reachable_discord_notifications = $this->serverReachableDiscordNotifications; $this->settings->server_unreachable_discord_notifications = $this->serverUnreachableDiscordNotifications; $this->settings->server_patch_discord_notifications = $this->serverPatchDiscordNotifications; + $this->settings->traefik_outdated_discord_notifications = $this->traefikOutdatedDiscordNotifications; $this->settings->discord_ping_enabled = $this->discordPingEnabled; @@ -120,6 +124,7 @@ public function syncData(bool $toModel = false) $this->serverReachableDiscordNotifications = $this->settings->server_reachable_discord_notifications; $this->serverUnreachableDiscordNotifications = $this->settings->server_unreachable_discord_notifications; $this->serverPatchDiscordNotifications = $this->settings->server_patch_discord_notifications; + $this->traefikOutdatedDiscordNotifications = $this->settings->traefik_outdated_discord_notifications; $this->discordPingEnabled = $this->settings->discord_ping_enabled; } diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.php index d62a08417..847f10765 100644 --- a/app/Livewire/Notifications/Email.php +++ b/app/Livewire/Notifications/Email.php @@ -104,6 +104,9 @@ class Email extends Component #[Validate(['boolean'])] public bool $serverPatchEmailNotifications = false; + #[Validate(['boolean'])] + public bool $traefikOutdatedEmailNotifications = true; + #[Validate(['nullable', 'email'])] public ?string $testEmailAddress = null; @@ -155,6 +158,7 @@ public function syncData(bool $toModel = false) $this->settings->server_reachable_email_notifications = $this->serverReachableEmailNotifications; $this->settings->server_unreachable_email_notifications = $this->serverUnreachableEmailNotifications; $this->settings->server_patch_email_notifications = $this->serverPatchEmailNotifications; + $this->settings->traefik_outdated_email_notifications = $this->traefikOutdatedEmailNotifications; $this->settings->save(); } else { @@ -187,6 +191,7 @@ public function syncData(bool $toModel = false) $this->serverReachableEmailNotifications = $this->settings->server_reachable_email_notifications; $this->serverUnreachableEmailNotifications = $this->settings->server_unreachable_email_notifications; $this->serverPatchEmailNotifications = $this->settings->server_patch_email_notifications; + $this->traefikOutdatedEmailNotifications = $this->settings->traefik_outdated_email_notifications; } } diff --git a/app/Livewire/Notifications/Pushover.php b/app/Livewire/Notifications/Pushover.php index 9c7ff64ad..d79eea87b 100644 --- a/app/Livewire/Notifications/Pushover.php +++ b/app/Livewire/Notifications/Pushover.php @@ -70,6 +70,9 @@ class Pushover extends Component #[Validate(['boolean'])] public bool $serverPatchPushoverNotifications = false; + #[Validate(['boolean'])] + public bool $traefikOutdatedPushoverNotifications = true; + public function mount() { try { @@ -104,6 +107,7 @@ public function syncData(bool $toModel = false) $this->settings->server_reachable_pushover_notifications = $this->serverReachablePushoverNotifications; $this->settings->server_unreachable_pushover_notifications = $this->serverUnreachablePushoverNotifications; $this->settings->server_patch_pushover_notifications = $this->serverPatchPushoverNotifications; + $this->settings->traefik_outdated_pushover_notifications = $this->traefikOutdatedPushoverNotifications; $this->settings->save(); refreshSession(); @@ -125,6 +129,7 @@ public function syncData(bool $toModel = false) $this->serverReachablePushoverNotifications = $this->settings->server_reachable_pushover_notifications; $this->serverUnreachablePushoverNotifications = $this->settings->server_unreachable_pushover_notifications; $this->serverPatchPushoverNotifications = $this->settings->server_patch_pushover_notifications; + $this->traefikOutdatedPushoverNotifications = $this->settings->traefik_outdated_pushover_notifications; } } diff --git a/app/Livewire/Notifications/Slack.php b/app/Livewire/Notifications/Slack.php index d21399c42..fa8c97ae9 100644 --- a/app/Livewire/Notifications/Slack.php +++ b/app/Livewire/Notifications/Slack.php @@ -67,6 +67,9 @@ class Slack extends Component #[Validate(['boolean'])] public bool $serverPatchSlackNotifications = false; + #[Validate(['boolean'])] + public bool $traefikOutdatedSlackNotifications = true; + public function mount() { try { @@ -100,6 +103,7 @@ public function syncData(bool $toModel = false) $this->settings->server_reachable_slack_notifications = $this->serverReachableSlackNotifications; $this->settings->server_unreachable_slack_notifications = $this->serverUnreachableSlackNotifications; $this->settings->server_patch_slack_notifications = $this->serverPatchSlackNotifications; + $this->settings->traefik_outdated_slack_notifications = $this->traefikOutdatedSlackNotifications; $this->settings->save(); refreshSession(); @@ -120,6 +124,7 @@ public function syncData(bool $toModel = false) $this->serverReachableSlackNotifications = $this->settings->server_reachable_slack_notifications; $this->serverUnreachableSlackNotifications = $this->settings->server_unreachable_slack_notifications; $this->serverPatchSlackNotifications = $this->settings->server_patch_slack_notifications; + $this->traefikOutdatedSlackNotifications = $this->settings->traefik_outdated_slack_notifications; } } diff --git a/app/Livewire/Notifications/Telegram.php b/app/Livewire/Notifications/Telegram.php index ca9df47c1..fc3966cf6 100644 --- a/app/Livewire/Notifications/Telegram.php +++ b/app/Livewire/Notifications/Telegram.php @@ -70,6 +70,9 @@ class Telegram extends Component #[Validate(['boolean'])] public bool $serverPatchTelegramNotifications = false; + #[Validate(['boolean'])] + public bool $traefikOutdatedTelegramNotifications = true; + #[Validate(['nullable', 'string'])] public ?string $telegramNotificationsDeploymentSuccessThreadId = null; @@ -109,6 +112,9 @@ class Telegram extends Component #[Validate(['nullable', 'string'])] public ?string $telegramNotificationsServerPatchThreadId = null; + #[Validate(['nullable', 'string'])] + public ?string $telegramNotificationsTraefikOutdatedThreadId = null; + public function mount() { try { @@ -143,6 +149,7 @@ public function syncData(bool $toModel = false) $this->settings->server_reachable_telegram_notifications = $this->serverReachableTelegramNotifications; $this->settings->server_unreachable_telegram_notifications = $this->serverUnreachableTelegramNotifications; $this->settings->server_patch_telegram_notifications = $this->serverPatchTelegramNotifications; + $this->settings->traefik_outdated_telegram_notifications = $this->traefikOutdatedTelegramNotifications; $this->settings->telegram_notifications_deployment_success_thread_id = $this->telegramNotificationsDeploymentSuccessThreadId; $this->settings->telegram_notifications_deployment_failure_thread_id = $this->telegramNotificationsDeploymentFailureThreadId; @@ -157,6 +164,7 @@ public function syncData(bool $toModel = false) $this->settings->telegram_notifications_server_reachable_thread_id = $this->telegramNotificationsServerReachableThreadId; $this->settings->telegram_notifications_server_unreachable_thread_id = $this->telegramNotificationsServerUnreachableThreadId; $this->settings->telegram_notifications_server_patch_thread_id = $this->telegramNotificationsServerPatchThreadId; + $this->settings->telegram_notifications_traefik_outdated_thread_id = $this->telegramNotificationsTraefikOutdatedThreadId; $this->settings->save(); } else { @@ -177,6 +185,7 @@ public function syncData(bool $toModel = false) $this->serverReachableTelegramNotifications = $this->settings->server_reachable_telegram_notifications; $this->serverUnreachableTelegramNotifications = $this->settings->server_unreachable_telegram_notifications; $this->serverPatchTelegramNotifications = $this->settings->server_patch_telegram_notifications; + $this->traefikOutdatedTelegramNotifications = $this->settings->traefik_outdated_telegram_notifications; $this->telegramNotificationsDeploymentSuccessThreadId = $this->settings->telegram_notifications_deployment_success_thread_id; $this->telegramNotificationsDeploymentFailureThreadId = $this->settings->telegram_notifications_deployment_failure_thread_id; @@ -191,6 +200,7 @@ public function syncData(bool $toModel = false) $this->telegramNotificationsServerReachableThreadId = $this->settings->telegram_notifications_server_reachable_thread_id; $this->telegramNotificationsServerUnreachableThreadId = $this->settings->telegram_notifications_server_unreachable_thread_id; $this->telegramNotificationsServerPatchThreadId = $this->settings->telegram_notifications_server_patch_thread_id; + $this->telegramNotificationsTraefikOutdatedThreadId = $this->settings->telegram_notifications_traefik_outdated_thread_id; } } diff --git a/app/Livewire/Notifications/Webhook.php b/app/Livewire/Notifications/Webhook.php index cf4e71105..8af70c6eb 100644 --- a/app/Livewire/Notifications/Webhook.php +++ b/app/Livewire/Notifications/Webhook.php @@ -62,6 +62,9 @@ class Webhook extends Component #[Validate(['boolean'])] public bool $serverPatchWebhookNotifications = false; + #[Validate(['boolean'])] + public bool $traefikOutdatedWebhookNotifications = true; + public function mount() { try { @@ -95,6 +98,7 @@ public function syncData(bool $toModel = false) $this->settings->server_reachable_webhook_notifications = $this->serverReachableWebhookNotifications; $this->settings->server_unreachable_webhook_notifications = $this->serverUnreachableWebhookNotifications; $this->settings->server_patch_webhook_notifications = $this->serverPatchWebhookNotifications; + $this->settings->traefik_outdated_webhook_notifications = $this->traefikOutdatedWebhookNotifications; $this->settings->save(); refreshSession(); @@ -115,6 +119,7 @@ public function syncData(bool $toModel = false) $this->serverReachableWebhookNotifications = $this->settings->server_reachable_webhook_notifications; $this->serverUnreachableWebhookNotifications = $this->settings->server_unreachable_webhook_notifications; $this->serverPatchWebhookNotifications = $this->settings->server_patch_webhook_notifications; + $this->traefikOutdatedWebhookNotifications = $this->settings->traefik_outdated_webhook_notifications; } } diff --git a/app/Livewire/Server/Navbar.php b/app/Livewire/Server/Navbar.php index 6baa54672..4e3481912 100644 --- a/app/Livewire/Server/Navbar.php +++ b/app/Livewire/Server/Navbar.php @@ -5,7 +5,8 @@ use App\Actions\Proxy\CheckProxy; use App\Actions\Proxy\StartProxy; use App\Actions\Proxy\StopProxy; -use App\Jobs\RestartProxyJob; +use App\Enums\ProxyTypes; +use App\Jobs\CheckTraefikVersionForServerJob; use App\Models\Server; use App\Services\ProxyDashboardCacheService; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; @@ -61,7 +62,18 @@ public function restart() { try { $this->authorize('manageProxy', $this->server); - RestartProxyJob::dispatch($this->server); + StopProxy::run($this->server, restarting: true); + + $this->server->proxy->force_stop = false; + $this->server->save(); + + $activity = StartProxy::run($this->server, force: true, restarting: true); + $this->dispatch('activityMonitor', $activity->id); + + // Check Traefik version after restart to provide immediate feedback + if ($this->server->proxyType() === ProxyTypes::TRAEFIK->value) { + CheckTraefikVersionForServerJob::dispatch($this->server, get_traefik_versions()); + } } catch (\Throwable $e) { return handleError($e, $this); } @@ -118,19 +130,25 @@ public function checkProxyStatus() public function showNotification() { + $previousStatus = $this->proxyStatus; $this->server->refresh(); $this->proxyStatus = $this->server->proxy->status ?? 'unknown'; switch ($this->proxyStatus) { case 'running': $this->loadProxyConfiguration(); - $this->dispatch('success', 'Proxy is running.'); - break; - case 'restarting': - $this->dispatch('info', 'Initiating proxy restart.'); + // Only show "Proxy is running" notification when transitioning from a stopped/error state + // Don't show during normal start/restart flows (starting, restarting, stopping) + if (in_array($previousStatus, ['exited', 'stopped', 'unknown', null])) { + $this->dispatch('success', 'Proxy is running.'); + } break; case 'exited': - $this->dispatch('info', 'Proxy has exited.'); + // Only show "Proxy has exited" notification when transitioning from running state + // Don't show during normal stop/restart flows (stopping, restarting) + if (in_array($previousStatus, ['running'])) { + $this->dispatch('info', 'Proxy has exited.'); + } break; case 'stopping': $this->dispatch('info', 'Proxy is stopping.'); @@ -154,6 +172,22 @@ public function refreshServer() $this->server->load('settings'); } + /** + * Check if Traefik has any outdated version info (patch or minor upgrade). + * This shows a warning indicator in the navbar. + */ + public function getHasTraefikOutdatedProperty(): bool + { + if ($this->server->proxyType() !== ProxyTypes::TRAEFIK->value) { + return false; + } + + // Check if server has outdated info stored + $outdatedInfo = $this->server->traefik_outdated_info; + + return ! empty($outdatedInfo) && isset($outdatedInfo['type']); + } + public function render() { return view('livewire.server.navbar'); diff --git a/app/Livewire/Server/Proxy.php b/app/Livewire/Server/Proxy.php index bc7e9bde4..c92f73f17 100644 --- a/app/Livewire/Server/Proxy.php +++ b/app/Livewire/Server/Proxy.php @@ -4,6 +4,7 @@ use App\Actions\Proxy\GetProxyConfiguration; use App\Actions\Proxy\SaveProxyConfiguration; +use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Livewire\Component; @@ -24,6 +25,12 @@ class Proxy extends Component public bool $generateExactLabels = false; + /** + * Cache the versions.json file data in memory for this component instance. + * This avoids multiple file reads during a single request/render cycle. + */ + protected ?array $cachedVersionsFile = null; + public function getListeners() { $teamId = auth()->user()->currentTeam()->id; @@ -55,6 +62,34 @@ private function syncData(bool $toModel = false): void } } + /** + * Get Traefik versions from cached data with in-memory optimization. + * Returns array like: ['v3.5' => '3.5.6', 'v3.6' => '3.6.2'] + * + * This method adds an in-memory cache layer on top of the global + * get_traefik_versions() helper to avoid multiple calls during + * a single component lifecycle/render. + */ + protected function getTraefikVersions(): ?array + { + // In-memory cache for this component instance (per-request) + if ($this->cachedVersionsFile !== null) { + return data_get($this->cachedVersionsFile, 'traefik'); + } + + // Load from global cached helper (Redis + filesystem) + $versionsData = get_versions_data(); + $this->cachedVersionsFile = $versionsData; + + if (! $versionsData) { + return null; + } + + $traefikVersions = data_get($versionsData, 'traefik'); + + return is_array($traefikVersions) ? $traefikVersions : null; + } + public function getConfigurationFilePathProperty() { return $this->server->proxyPath().'docker-compose.yml'; @@ -144,4 +179,131 @@ public function loadProxyConfiguration() return handleError($e, $this); } } + + /** + * Get the latest Traefik version for this server's current branch. + * + * This compares the server's detected version against available versions + * in versions.json to determine the latest patch for the current branch, + * or the newest available version if no current version is detected. + */ + public function getLatestTraefikVersionProperty(): ?string + { + try { + $traefikVersions = $this->getTraefikVersions(); + + if (! $traefikVersions) { + return null; + } + + // Get this server's current version + $currentVersion = $this->server->detected_traefik_version; + + // If we have a current version, try to find matching branch + if ($currentVersion && $currentVersion !== 'latest') { + $current = ltrim($currentVersion, 'v'); + if (preg_match('/^(\d+\.\d+)/', $current, $matches)) { + $branch = "v{$matches[1]}"; + if (isset($traefikVersions[$branch])) { + $version = $traefikVersions[$branch]; + + return str_starts_with($version, 'v') ? $version : "v{$version}"; + } + } + } + + // Return the newest available version + $newestVersion = collect($traefikVersions) + ->map(fn ($v) => ltrim($v, 'v')) + ->sortBy(fn ($v) => $v, SORT_NATURAL) + ->last(); + + return $newestVersion ? "v{$newestVersion}" : null; + } catch (\Throwable $e) { + return null; + } + } + + public function getIsTraefikOutdatedProperty(): bool + { + if ($this->server->proxyType() !== ProxyTypes::TRAEFIK->value) { + return false; + } + + $currentVersion = $this->server->detected_traefik_version; + if (! $currentVersion || $currentVersion === 'latest') { + return false; + } + + $latestVersion = $this->latestTraefikVersion; + if (! $latestVersion) { + return false; + } + + // Compare versions (strip 'v' prefix) + $current = ltrim($currentVersion, 'v'); + $latest = ltrim($latestVersion, 'v'); + + return version_compare($current, $latest, '<'); + } + + /** + * Check if a newer Traefik branch (minor version) is available for this server. + * Returns the branch identifier (e.g., "v3.6") if a newer branch exists. + */ + public function getNewerTraefikBranchAvailableProperty(): ?string + { + try { + if ($this->server->proxyType() !== ProxyTypes::TRAEFIK->value) { + return null; + } + + // Get this server's current version + $currentVersion = $this->server->detected_traefik_version; + if (! $currentVersion || $currentVersion === 'latest') { + return null; + } + + // Check if we have outdated info stored for this server (faster than computing) + $outdatedInfo = $this->server->traefik_outdated_info; + if ($outdatedInfo && isset($outdatedInfo['type']) && $outdatedInfo['type'] === 'minor_upgrade') { + // Use the upgrade_target field if available (e.g., "v3.6") + if (isset($outdatedInfo['upgrade_target'])) { + return str_starts_with($outdatedInfo['upgrade_target'], 'v') + ? $outdatedInfo['upgrade_target'] + : "v{$outdatedInfo['upgrade_target']}"; + } + } + + // Fallback: compute from cached versions data + $traefikVersions = $this->getTraefikVersions(); + + if (! $traefikVersions) { + return null; + } + + // Extract current branch (e.g., "3.5" from "3.5.6") + $current = ltrim($currentVersion, 'v'); + if (! preg_match('/^(\d+\.\d+)/', $current, $matches)) { + return null; + } + + $currentBranch = $matches[1]; + + // Find the newest branch that's greater than current + $newestBranch = null; + foreach ($traefikVersions as $branch => $version) { + $branchNum = ltrim($branch, 'v'); + if (version_compare($branchNum, $currentBranch, '>')) { + if (! $newestBranch || version_compare($branchNum, $newestBranch, '>')) { + $newestBranch = $branchNum; + } + } + } + + return $newestBranch ? "v{$newestBranch}" : null; + } catch (\Throwable $e) { + return null; + } + } } diff --git a/app/Models/DiscordNotificationSettings.php b/app/Models/DiscordNotificationSettings.php index 34adfc997..23e1f0f12 100644 --- a/app/Models/DiscordNotificationSettings.php +++ b/app/Models/DiscordNotificationSettings.php @@ -29,6 +29,7 @@ class DiscordNotificationSettings extends Model 'server_reachable_discord_notifications', 'server_unreachable_discord_notifications', 'server_patch_discord_notifications', + 'traefik_outdated_discord_notifications', 'discord_ping_enabled', ]; @@ -48,6 +49,7 @@ class DiscordNotificationSettings extends Model 'server_reachable_discord_notifications' => 'boolean', 'server_unreachable_discord_notifications' => 'boolean', 'server_patch_discord_notifications' => 'boolean', + 'traefik_outdated_discord_notifications' => 'boolean', 'discord_ping_enabled' => 'boolean', ]; diff --git a/app/Models/EmailNotificationSettings.php b/app/Models/EmailNotificationSettings.php index 39617b4cf..ee31a49b6 100644 --- a/app/Models/EmailNotificationSettings.php +++ b/app/Models/EmailNotificationSettings.php @@ -36,6 +36,7 @@ class EmailNotificationSettings extends Model 'scheduled_task_failure_email_notifications', 'server_disk_usage_email_notifications', 'server_patch_email_notifications', + 'traefik_outdated_email_notifications', ]; protected $casts = [ @@ -63,6 +64,7 @@ class EmailNotificationSettings extends Model 'scheduled_task_failure_email_notifications' => 'boolean', 'server_disk_usage_email_notifications' => 'boolean', 'server_patch_email_notifications' => 'boolean', + 'traefik_outdated_email_notifications' => 'boolean', ]; public function team() diff --git a/app/Models/PushoverNotificationSettings.php b/app/Models/PushoverNotificationSettings.php index a75fd71d7..189d05dd4 100644 --- a/app/Models/PushoverNotificationSettings.php +++ b/app/Models/PushoverNotificationSettings.php @@ -30,6 +30,7 @@ class PushoverNotificationSettings extends Model 'server_reachable_pushover_notifications', 'server_unreachable_pushover_notifications', 'server_patch_pushover_notifications', + 'traefik_outdated_pushover_notifications', ]; protected $casts = [ @@ -49,6 +50,7 @@ class PushoverNotificationSettings extends Model 'server_reachable_pushover_notifications' => 'boolean', 'server_unreachable_pushover_notifications' => 'boolean', 'server_patch_pushover_notifications' => 'boolean', + 'traefik_outdated_pushover_notifications' => 'boolean', ]; public function team() diff --git a/app/Models/Server.php b/app/Models/Server.php index e39526949..e88af2b15 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -31,6 +31,51 @@ use Symfony\Component\Yaml\Yaml; use Visus\Cuid2\Cuid2; +/** + * @property array{ + * current: string, + * latest: string, + * type: 'patch_update'|'minor_upgrade', + * checked_at: string, + * newer_branch_target?: string, + * newer_branch_latest?: string, + * upgrade_target?: string + * }|null $traefik_outdated_info Traefik version tracking information. + * + * This JSON column stores information about outdated Traefik proxy versions on this server. + * The structure varies depending on the type of update available: + * + * **For patch updates** (e.g., 3.5.0 → 3.5.2): + * ```php + * [ + * 'current' => '3.5.0', // Current version (without 'v' prefix) + * 'latest' => '3.5.2', // Latest patch version available + * 'type' => 'patch_update', // Update type identifier + * 'checked_at' => '2025-11-14T10:00:00Z', // ISO8601 timestamp + * 'newer_branch_target' => 'v3.6', // (Optional) Available major/minor version + * 'newer_branch_latest' => '3.6.2' // (Optional) Latest version in that branch + * ] + * ``` + * + * **For minor/major upgrades** (e.g., 3.5.6 → 3.6.2): + * ```php + * [ + * 'current' => '3.5.6', // Current version + * 'latest' => '3.6.2', // Latest version in target branch + * 'type' => 'minor_upgrade', // Update type identifier + * 'upgrade_target' => 'v3.6', // Target branch (with 'v' prefix) + * 'checked_at' => '2025-11-14T10:00:00Z' // ISO8601 timestamp + * ] + * ``` + * + * **Null value**: Set to null when: + * - Server is fully up-to-date with the latest version + * - Traefik image uses the 'latest' tag (no fixed version tracking) + * - No Traefik version detected on the server + * + * @see \App\Jobs\CheckTraefikVersionForServerJob Where this data is populated + * @see \App\Livewire\Server\Proxy Where this data is read and displayed + */ #[OA\Schema( description: 'Server model', type: 'object', @@ -142,6 +187,7 @@ protected static function booted() protected $casts = [ 'proxy' => SchemalessAttributes::class, + 'traefik_outdated_info' => 'array', 'logdrain_axiom_api_key' => 'encrypted', 'logdrain_newrelic_license_key' => 'encrypted', 'delete_unused_volumes' => 'boolean', @@ -167,6 +213,8 @@ protected static function booted() 'hetzner_server_id', 'hetzner_server_status', 'is_validating', + 'detected_traefik_version', + 'traefik_outdated_info', ]; protected $guarded = []; @@ -522,6 +570,11 @@ public function scopeWithProxy(): Builder return $this->proxy->modelScope(); } + public function scopeWhereProxyType(Builder $query, string $proxyType): Builder + { + return $query->where('proxy->type', $proxyType); + } + public function isLocalhost() { return $this->ip === 'host.docker.internal' || $this->id === 0; diff --git a/app/Models/SlackNotificationSettings.php b/app/Models/SlackNotificationSettings.php index 2b52bfd5b..128b25221 100644 --- a/app/Models/SlackNotificationSettings.php +++ b/app/Models/SlackNotificationSettings.php @@ -29,6 +29,7 @@ class SlackNotificationSettings extends Model 'server_reachable_slack_notifications', 'server_unreachable_slack_notifications', 'server_patch_slack_notifications', + 'traefik_outdated_slack_notifications', ]; protected $casts = [ @@ -47,6 +48,7 @@ class SlackNotificationSettings extends Model 'server_reachable_slack_notifications' => 'boolean', 'server_unreachable_slack_notifications' => 'boolean', 'server_patch_slack_notifications' => 'boolean', + 'traefik_outdated_slack_notifications' => 'boolean', ]; public function team() diff --git a/app/Models/Team.php b/app/Models/Team.php index 6c30389ee..5cb186942 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -49,7 +49,9 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover, Sen protected static function booted() { static::created(function ($team) { - $team->emailNotificationSettings()->create(); + $team->emailNotificationSettings()->create([ + 'use_instance_email_settings' => isDev(), + ]); $team->discordNotificationSettings()->create(); $team->slackNotificationSettings()->create(); $team->telegramNotificationSettings()->create(); diff --git a/app/Models/TelegramNotificationSettings.php b/app/Models/TelegramNotificationSettings.php index 94315ee30..73889910e 100644 --- a/app/Models/TelegramNotificationSettings.php +++ b/app/Models/TelegramNotificationSettings.php @@ -30,6 +30,7 @@ class TelegramNotificationSettings extends Model 'server_reachable_telegram_notifications', 'server_unreachable_telegram_notifications', 'server_patch_telegram_notifications', + 'traefik_outdated_telegram_notifications', 'telegram_notifications_deployment_success_thread_id', 'telegram_notifications_deployment_failure_thread_id', @@ -43,6 +44,7 @@ class TelegramNotificationSettings extends Model 'telegram_notifications_server_reachable_thread_id', 'telegram_notifications_server_unreachable_thread_id', 'telegram_notifications_server_patch_thread_id', + 'telegram_notifications_traefik_outdated_thread_id', ]; protected $casts = [ @@ -62,6 +64,7 @@ class TelegramNotificationSettings extends Model 'server_reachable_telegram_notifications' => 'boolean', 'server_unreachable_telegram_notifications' => 'boolean', 'server_patch_telegram_notifications' => 'boolean', + 'traefik_outdated_telegram_notifications' => 'boolean', 'telegram_notifications_deployment_success_thread_id' => 'encrypted', 'telegram_notifications_deployment_failure_thread_id' => 'encrypted', @@ -75,6 +78,7 @@ class TelegramNotificationSettings extends Model 'telegram_notifications_server_reachable_thread_id' => 'encrypted', 'telegram_notifications_server_unreachable_thread_id' => 'encrypted', 'telegram_notifications_server_patch_thread_id' => 'encrypted', + 'telegram_notifications_traefik_outdated_thread_id' => 'encrypted', ]; public function team() diff --git a/app/Models/WebhookNotificationSettings.php b/app/Models/WebhookNotificationSettings.php index 4ca89e0d3..79bd0ae62 100644 --- a/app/Models/WebhookNotificationSettings.php +++ b/app/Models/WebhookNotificationSettings.php @@ -29,6 +29,7 @@ class WebhookNotificationSettings extends Model 'server_reachable_webhook_notifications', 'server_unreachable_webhook_notifications', 'server_patch_webhook_notifications', + 'traefik_outdated_webhook_notifications', ]; protected function casts(): array @@ -49,6 +50,7 @@ protected function casts(): array 'server_reachable_webhook_notifications' => 'boolean', 'server_unreachable_webhook_notifications' => 'boolean', 'server_patch_webhook_notifications' => 'boolean', + 'traefik_outdated_webhook_notifications' => 'boolean', ]; } diff --git a/app/Notifications/Server/TraefikVersionOutdated.php b/app/Notifications/Server/TraefikVersionOutdated.php new file mode 100644 index 000000000..09ef4257d --- /dev/null +++ b/app/Notifications/Server/TraefikVersionOutdated.php @@ -0,0 +1,262 @@ +onQueue('high'); + } + + public function via(object $notifiable): array + { + return $notifiable->getEnabledChannels('traefik_outdated'); + } + + private function formatVersion(string $version): string + { + // Add 'v' prefix if not present for consistent display + return str_starts_with($version, 'v') ? $version : "v{$version}"; + } + + private function getUpgradeTarget(array $info): string + { + // For minor upgrades, use the upgrade_target field (e.g., "v3.6") + if (($info['type'] ?? 'patch_update') === 'minor_upgrade' && isset($info['upgrade_target'])) { + return $this->formatVersion($info['upgrade_target']); + } + + // For patch updates, show the full version + return $this->formatVersion($info['latest'] ?? 'unknown'); + } + + public function toMail($notifiable = null): MailMessage + { + $mail = new MailMessage; + $count = $this->servers->count(); + + $mail->subject("Coolify: Traefik proxy outdated on {$count} server(s)"); + $mail->view('emails.traefik-version-outdated', [ + 'servers' => $this->servers, + 'count' => $count, + ]); + + return $mail; + } + + public function toDiscord(): DiscordMessage + { + $count = $this->servers->count(); + $hasUpgrades = $this->servers->contains(fn ($s) => ($s->outdatedInfo['type'] ?? 'patch_update') === 'minor_upgrade' || + isset($s->outdatedInfo['newer_branch_target']) + ); + + $description = "**{$count} server(s)** running outdated Traefik proxy. Update recommended for security and features.\n\n"; + $description .= "**Affected servers:**\n"; + + foreach ($this->servers as $server) { + $info = $server->outdatedInfo ?? []; + $current = $this->formatVersion($info['current'] ?? 'unknown'); + $latest = $this->formatVersion($info['latest'] ?? 'unknown'); + $upgradeTarget = $this->getUpgradeTarget($info); + $isPatch = ($info['type'] ?? 'patch_update') === 'patch_update'; + $hasNewerBranch = isset($info['newer_branch_target']); + + if ($isPatch && $hasNewerBranch) { + $newerBranchTarget = $info['newer_branch_target']; + $newerBranchLatest = $this->formatVersion($info['newer_branch_latest']); + $description .= "• {$server->name}: {$current} → {$upgradeTarget} (patch update available)\n"; + $description .= " ↳ Also available: {$newerBranchTarget} (latest patch: {$newerBranchLatest}) - new minor version\n"; + } elseif ($isPatch) { + $description .= "• {$server->name}: {$current} → {$upgradeTarget} (patch update available)\n"; + } else { + $description .= "• {$server->name}: {$current} (latest patch: {$latest}) → {$upgradeTarget} (new minor version available)\n"; + } + } + + $description .= "\n⚠️ It is recommended to test before switching the production version."; + + if ($hasUpgrades) { + $description .= "\n\n📖 **For minor version upgrades**: Read the Traefik changelog before upgrading to understand breaking changes and new features."; + } + + return new DiscordMessage( + title: ':warning: Coolify: Traefik proxy outdated', + description: $description, + color: DiscordMessage::warningColor(), + ); + } + + public function toTelegram(): array + { + $count = $this->servers->count(); + $hasUpgrades = $this->servers->contains(fn ($s) => ($s->outdatedInfo['type'] ?? 'patch_update') === 'minor_upgrade' || + isset($s->outdatedInfo['newer_branch_target']) + ); + + $message = "⚠️ Coolify: Traefik proxy outdated on {$count} server(s)!\n\n"; + $message .= "Update recommended for security and features.\n"; + $message .= "📊 Affected servers:\n"; + + foreach ($this->servers as $server) { + $info = $server->outdatedInfo ?? []; + $current = $this->formatVersion($info['current'] ?? 'unknown'); + $latest = $this->formatVersion($info['latest'] ?? 'unknown'); + $upgradeTarget = $this->getUpgradeTarget($info); + $isPatch = ($info['type'] ?? 'patch_update') === 'patch_update'; + $hasNewerBranch = isset($info['newer_branch_target']); + + if ($isPatch && $hasNewerBranch) { + $newerBranchTarget = $info['newer_branch_target']; + $newerBranchLatest = $this->formatVersion($info['newer_branch_latest']); + $message .= "• {$server->name}: {$current} → {$upgradeTarget} (patch update available)\n"; + $message .= " ↳ Also available: {$newerBranchTarget} (latest patch: {$newerBranchLatest}) - new minor version\n"; + } elseif ($isPatch) { + $message .= "• {$server->name}: {$current} → {$upgradeTarget} (patch update available)\n"; + } else { + $message .= "• {$server->name}: {$current} (latest patch: {$latest}) → {$upgradeTarget} (new minor version available)\n"; + } + } + + $message .= "\n⚠️ It is recommended to test before switching the production version."; + + if ($hasUpgrades) { + $message .= "\n\n📖 For minor version upgrades: Read the Traefik changelog before upgrading to understand breaking changes and new features."; + } + + return [ + 'message' => $message, + 'buttons' => [], + ]; + } + + public function toPushover(): PushoverMessage + { + $count = $this->servers->count(); + $hasUpgrades = $this->servers->contains(fn ($s) => ($s->outdatedInfo['type'] ?? 'patch_update') === 'minor_upgrade' || + isset($s->outdatedInfo['newer_branch_target']) + ); + + $message = "Traefik proxy outdated on {$count} server(s)!\n"; + $message .= "Affected servers:\n"; + + foreach ($this->servers as $server) { + $info = $server->outdatedInfo ?? []; + $current = $this->formatVersion($info['current'] ?? 'unknown'); + $latest = $this->formatVersion($info['latest'] ?? 'unknown'); + $upgradeTarget = $this->getUpgradeTarget($info); + $isPatch = ($info['type'] ?? 'patch_update') === 'patch_update'; + $hasNewerBranch = isset($info['newer_branch_target']); + + if ($isPatch && $hasNewerBranch) { + $newerBranchTarget = $info['newer_branch_target']; + $newerBranchLatest = $this->formatVersion($info['newer_branch_latest']); + $message .= "• {$server->name}: {$current} → {$upgradeTarget} (patch update available)\n"; + $message .= " Also: {$newerBranchTarget} (latest: {$newerBranchLatest}) - new minor version\n"; + } elseif ($isPatch) { + $message .= "• {$server->name}: {$current} → {$upgradeTarget} (patch update available)\n"; + } else { + $message .= "• {$server->name}: {$current} (latest patch: {$latest}) → {$upgradeTarget} (new minor version available)\n"; + } + } + + $message .= "\nIt is recommended to test before switching the production version."; + + if ($hasUpgrades) { + $message .= "\n\nFor minor version upgrades: Read the Traefik changelog before upgrading."; + } + + return new PushoverMessage( + title: 'Traefik proxy outdated', + level: 'warning', + message: $message, + ); + } + + public function toSlack(): SlackMessage + { + $count = $this->servers->count(); + $hasUpgrades = $this->servers->contains(fn ($s) => ($s->outdatedInfo['type'] ?? 'patch_update') === 'minor_upgrade' || + isset($s->outdatedInfo['newer_branch_target']) + ); + + $description = "Traefik proxy outdated on {$count} server(s)!\n"; + $description .= "*Affected servers:*\n"; + + foreach ($this->servers as $server) { + $info = $server->outdatedInfo ?? []; + $current = $this->formatVersion($info['current'] ?? 'unknown'); + $latest = $this->formatVersion($info['latest'] ?? 'unknown'); + $upgradeTarget = $this->getUpgradeTarget($info); + $isPatch = ($info['type'] ?? 'patch_update') === 'patch_update'; + $hasNewerBranch = isset($info['newer_branch_target']); + + if ($isPatch && $hasNewerBranch) { + $newerBranchTarget = $info['newer_branch_target']; + $newerBranchLatest = $this->formatVersion($info['newer_branch_latest']); + $description .= "• `{$server->name}`: {$current} → {$upgradeTarget} (patch update available)\n"; + $description .= " ↳ Also available: {$newerBranchTarget} (latest patch: {$newerBranchLatest}) - new minor version\n"; + } elseif ($isPatch) { + $description .= "• `{$server->name}`: {$current} → {$upgradeTarget} (patch update available)\n"; + } else { + $description .= "• `{$server->name}`: {$current} (latest patch: {$latest}) → {$upgradeTarget} (new minor version available)\n"; + } + } + + $description .= "\n:warning: It is recommended to test before switching the production version."; + + if ($hasUpgrades) { + $description .= "\n\n:book: For minor version upgrades: Read the Traefik changelog before upgrading to understand breaking changes and new features."; + } + + return new SlackMessage( + title: 'Coolify: Traefik proxy outdated', + description: $description, + color: SlackMessage::warningColor() + ); + } + + public function toWebhook(): array + { + $servers = $this->servers->map(function ($server) { + $info = $server->outdatedInfo ?? []; + + $webhookData = [ + 'name' => $server->name, + 'uuid' => $server->uuid, + 'current_version' => $info['current'] ?? 'unknown', + 'latest_version' => $info['latest'] ?? 'unknown', + 'update_type' => $info['type'] ?? 'patch_update', + ]; + + // For minor upgrades, include the upgrade target (e.g., "v3.6") + if (($info['type'] ?? 'patch_update') === 'minor_upgrade' && isset($info['upgrade_target'])) { + $webhookData['upgrade_target'] = $info['upgrade_target']; + } + + // Include newer branch info if available + if (isset($info['newer_branch_target'])) { + $webhookData['newer_branch_target'] = $info['newer_branch_target']; + $webhookData['newer_branch_latest'] = $info['newer_branch_latest']; + } + + return $webhookData; + })->toArray(); + + return [ + 'success' => false, + 'message' => 'Traefik proxy outdated', + 'event' => 'traefik_version_outdated', + 'affected_servers_count' => $this->servers->count(), + 'servers' => $servers, + ]; + } +} diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php index b8274a3b3..08fad4958 100644 --- a/bootstrap/helpers/proxy.php +++ b/bootstrap/helpers/proxy.php @@ -334,3 +334,93 @@ function generateDefaultProxyConfiguration(Server $server, array $custom_command return $config; } + +function getExactTraefikVersionFromContainer(Server $server): ?string +{ + try { + Log::debug("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Checking for exact version"); + + // Method A: Execute traefik version command (most reliable) + $versionCommand = "docker exec coolify-proxy traefik version 2>/dev/null | grep -oP 'Version:\s+\K\d+\.\d+\.\d+'"; + Log::debug("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Running: {$versionCommand}"); + + $output = instant_remote_process([$versionCommand], $server, false); + + if (! empty(trim($output))) { + $version = trim($output); + Log::debug("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Detected exact version from command: {$version}"); + + return $version; + } + + // Method B: Try OCI label as fallback + $labelCommand = "docker inspect coolify-proxy --format '{{index .Config.Labels \"org.opencontainers.image.version\"}}' 2>/dev/null"; + Log::debug("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Trying OCI label"); + + $label = instant_remote_process([$labelCommand], $server, false); + + if (! empty(trim($label))) { + // Extract version number from label (might have 'v' prefix) + if (preg_match('/(\d+\.\d+\.\d+)/', trim($label), $matches)) { + Log::debug("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Detected from OCI label: {$matches[1]}"); + + return $matches[1]; + } + } + + Log::debug("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Could not detect exact version"); + + return null; + } catch (\Exception $e) { + Log::error("getExactTraefikVersionFromContainer: Server '{$server->name}' (ID: {$server->id}) - Error: ".$e->getMessage()); + + return null; + } +} + +function getTraefikVersionFromDockerCompose(Server $server): ?string +{ + try { + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Starting version detection"); + + // Try to get exact version from running container (e.g., "3.6.0") + $exactVersion = getExactTraefikVersionFromContainer($server); + if ($exactVersion) { + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Using exact version: {$exactVersion}"); + + return $exactVersion; + } + + // Fallback: Check image tag (current method) + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Falling back to image tag detection"); + + $containerName = 'coolify-proxy'; + $inspectCommand = "docker inspect {$containerName} --format '{{.Config.Image}}' 2>/dev/null"; + + $image = instant_remote_process([$inspectCommand], $server, false); + + if (empty(trim($image))) { + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Container '{$containerName}' not found or not running"); + + return null; + } + + $image = trim($image); + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Running container image: {$image}"); + + // Extract version from image string (e.g., "traefik:v3.6" or "traefik:3.6.0" or "traefik:latest") + if (preg_match('/traefik:(v?\d+\.\d+(?:\.\d+)?|latest)/i', $image, $matches)) { + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Extracted version from image tag: {$matches[1]}"); + + return $matches[1]; + } + + Log::debug("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Image format doesn't match expected pattern: {$image}"); + + return null; + } catch (\Exception $e) { + Log::error("getTraefikVersionFromDockerCompose: Server '{$server->name}' (ID: {$server->id}) - Error: ".$e->getMessage()); + + return null; + } +} diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index d9e76f399..384b960ef 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -241,10 +241,9 @@ function get_latest_sentinel_version(): string function get_latest_version_of_coolify(): string { try { - $versions = File::get(base_path('versions.json')); - $versions = json_decode($versions, true); + $versions = get_versions_data(); - return data_get($versions, 'coolify.v4.version'); + return data_get($versions, 'coolify.v4.version', '0.0.0'); } catch (\Throwable $e) { return '0.0.0'; diff --git a/bootstrap/helpers/versions.php b/bootstrap/helpers/versions.php new file mode 100644 index 000000000..bb4694de5 --- /dev/null +++ b/bootstrap/helpers/versions.php @@ -0,0 +1,53 @@ + '3.5.6']) + */ +function get_traefik_versions(): ?array +{ + $versions = get_versions_data(); + + if (! $versions) { + return null; + } + + $traefikVersions = data_get($versions, 'traefik'); + + return is_array($traefikVersions) ? $traefikVersions : null; +} + +/** + * Invalidate the versions cache. + * Call this after updating versions.json to ensure fresh data is loaded. + */ +function invalidate_versions_cache(): void +{ + Cache::forget('coolify:versions:all'); +} diff --git a/config/constants.php b/config/constants.php index 6ad70b31a..58191e0b2 100644 --- a/config/constants.php +++ b/config/constants.php @@ -95,4 +95,27 @@ 'storage_api_key' => env('BUNNY_STORAGE_API_KEY'), 'api_key' => env('BUNNY_API_KEY'), ], + + 'server_checks' => [ + // Notification delay configuration for parallel server checks + // Used for Traefik version checks and other future server check jobs + // These settings control how long to wait before sending notifications + // after dispatching parallel check jobs for all servers + + // Minimum delay in seconds (120s = 2 minutes) + // Accounts for job processing time, retries, and network latency + 'notification_delay_min' => 120, + + // Maximum delay in seconds (300s = 5 minutes) + // Prevents excessive waiting for very large server counts + 'notification_delay_max' => 300, + + // Scaling factor: seconds to add per server (0.2) + // Formula: delay = min(max, max(min, serverCount * scaling)) + // Examples: + // - 100 servers: 120s (uses minimum) + // - 1000 servers: 200s + // - 2000 servers: 300s (hits maximum) + 'notification_delay_scaling' => 0.2, + ], ]; diff --git a/database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php b/database/migrations/2025_10_10_120002_create_cloud_init_scripts_table.php similarity index 50% rename from database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php rename to database/migrations/2025_10_10_120002_create_cloud_init_scripts_table.php index e0b2934f3..3d5634f50 100644 --- a/database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php +++ b/database/migrations/2025_10_10_120002_create_cloud_init_scripts_table.php @@ -11,15 +11,13 @@ */ public function up(): void { - Schema::create('cloud_init_scripts', function (Blueprint $table) { - $table->id(); - $table->foreignId('team_id')->constrained()->onDelete('cascade'); - $table->string('name'); - $table->text('script'); // Encrypted in the model - $table->timestamps(); - - $table->index('team_id'); - }); + Schema::create('cloud_init_scripts', function (Blueprint $table) { + $table->id(); + $table->foreignId('team_id')->constrained()->onDelete('cascade'); + $table->string('name'); + $table->text('script'); // Encrypted in the model + $table->timestamps(); + }); } /** diff --git a/database/migrations/2025_10_10_120002_create_webhook_notification_settings_table.php b/database/migrations/2025_10_10_120002_create_webhook_notification_settings_table.php index 5ff8aa46d..a3edacbf9 100644 --- a/database/migrations/2025_10_10_120002_create_webhook_notification_settings_table.php +++ b/database/migrations/2025_10_10_120002_create_webhook_notification_settings_table.php @@ -11,29 +11,29 @@ */ public function up(): void { - Schema::create('webhook_notification_settings', function (Blueprint $table) { - $table->id(); - $table->foreignId('team_id')->constrained()->cascadeOnDelete(); + Schema::create('webhook_notification_settings', function (Blueprint $table) { + $table->id(); + $table->foreignId('team_id')->constrained()->cascadeOnDelete(); - $table->boolean('webhook_enabled')->default(false); - $table->text('webhook_url')->nullable(); + $table->boolean('webhook_enabled')->default(false); + $table->text('webhook_url')->nullable(); - $table->boolean('deployment_success_webhook_notifications')->default(false); - $table->boolean('deployment_failure_webhook_notifications')->default(true); - $table->boolean('status_change_webhook_notifications')->default(false); - $table->boolean('backup_success_webhook_notifications')->default(false); - $table->boolean('backup_failure_webhook_notifications')->default(true); - $table->boolean('scheduled_task_success_webhook_notifications')->default(false); - $table->boolean('scheduled_task_failure_webhook_notifications')->default(true); - $table->boolean('docker_cleanup_success_webhook_notifications')->default(false); - $table->boolean('docker_cleanup_failure_webhook_notifications')->default(true); - $table->boolean('server_disk_usage_webhook_notifications')->default(true); - $table->boolean('server_reachable_webhook_notifications')->default(false); - $table->boolean('server_unreachable_webhook_notifications')->default(true); - $table->boolean('server_patch_webhook_notifications')->default(false); + $table->boolean('deployment_success_webhook_notifications')->default(false); + $table->boolean('deployment_failure_webhook_notifications')->default(true); + $table->boolean('status_change_webhook_notifications')->default(false); + $table->boolean('backup_success_webhook_notifications')->default(false); + $table->boolean('backup_failure_webhook_notifications')->default(true); + $table->boolean('scheduled_task_success_webhook_notifications')->default(false); + $table->boolean('scheduled_task_failure_webhook_notifications')->default(true); + $table->boolean('docker_cleanup_success_webhook_notifications')->default(false); + $table->boolean('docker_cleanup_failure_webhook_notifications')->default(true); + $table->boolean('server_disk_usage_webhook_notifications')->default(true); + $table->boolean('server_reachable_webhook_notifications')->default(false); + $table->boolean('server_unreachable_webhook_notifications')->default(true); + $table->boolean('server_patch_webhook_notifications')->default(false); - $table->unique(['team_id']); - }); + $table->unique(['team_id']); + }); } /** diff --git a/database/migrations/2025_11_12_130931_add_traefik_version_tracking_to_servers_table.php b/database/migrations/2025_11_12_130931_add_traefik_version_tracking_to_servers_table.php new file mode 100644 index 000000000..3bab33368 --- /dev/null +++ b/database/migrations/2025_11_12_130931_add_traefik_version_tracking_to_servers_table.php @@ -0,0 +1,28 @@ +string('detected_traefik_version')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('detected_traefik_version'); + }); + } +}; diff --git a/database/migrations/2025_11_12_131252_add_traefik_outdated_to_email_notification_settings.php b/database/migrations/2025_11_12_131252_add_traefik_outdated_to_email_notification_settings.php new file mode 100644 index 000000000..ac509dc71 --- /dev/null +++ b/database/migrations/2025_11_12_131252_add_traefik_outdated_to_email_notification_settings.php @@ -0,0 +1,28 @@ +boolean('traefik_outdated_email_notifications')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('email_notification_settings', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_email_notifications'); + }); + } +}; diff --git a/database/migrations/2025_11_12_133400_add_traefik_outdated_thread_id_to_telegram_notification_settings.php b/database/migrations/2025_11_12_133400_add_traefik_outdated_thread_id_to_telegram_notification_settings.php new file mode 100644 index 000000000..b7d69e634 --- /dev/null +++ b/database/migrations/2025_11_12_133400_add_traefik_outdated_thread_id_to_telegram_notification_settings.php @@ -0,0 +1,28 @@ +text('telegram_notifications_traefik_outdated_thread_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('telegram_notification_settings', function (Blueprint $table) { + $table->dropColumn('telegram_notifications_traefik_outdated_thread_id'); + }); + } +}; diff --git a/database/migrations/2025_11_14_114632_add_traefik_outdated_info_to_servers_table.php b/database/migrations/2025_11_14_114632_add_traefik_outdated_info_to_servers_table.php new file mode 100644 index 000000000..99e10707d --- /dev/null +++ b/database/migrations/2025_11_14_114632_add_traefik_outdated_info_to_servers_table.php @@ -0,0 +1,28 @@ +json('traefik_outdated_info')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_info'); + }); + } +}; diff --git a/database/migrations/2025_11_17_092707_add_traefik_outdated_to_notification_settings.php b/database/migrations/2025_11_17_092707_add_traefik_outdated_to_notification_settings.php new file mode 100644 index 000000000..b5cad28b0 --- /dev/null +++ b/database/migrations/2025_11_17_092707_add_traefik_outdated_to_notification_settings.php @@ -0,0 +1,60 @@ +boolean('traefik_outdated_discord_notifications')->default(true); + }); + + Schema::table('slack_notification_settings', function (Blueprint $table) { + $table->boolean('traefik_outdated_slack_notifications')->default(true); + }); + + Schema::table('webhook_notification_settings', function (Blueprint $table) { + $table->boolean('traefik_outdated_webhook_notifications')->default(true); + }); + + Schema::table('telegram_notification_settings', function (Blueprint $table) { + $table->boolean('traefik_outdated_telegram_notifications')->default(true); + }); + + Schema::table('pushover_notification_settings', function (Blueprint $table) { + $table->boolean('traefik_outdated_pushover_notifications')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('discord_notification_settings', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_discord_notifications'); + }); + + Schema::table('slack_notification_settings', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_slack_notifications'); + }); + + Schema::table('webhook_notification_settings', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_webhook_notifications'); + }); + + Schema::table('telegram_notification_settings', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_telegram_notifications'); + }); + + Schema::table('pushover_notification_settings', function (Blueprint $table) { + $table->dropColumn('traefik_outdated_pushover_notifications'); + }); + } +}; diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index adada458e..511af1a9f 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -113,6 +113,8 @@ public function run(): void $server_details['proxy'] = ServerMetadata::from([ 'type' => ProxyTypes::TRAEFIK->value, 'status' => ProxyStatus::EXITED->value, + 'last_saved_settings' => null, + 'last_applied_settings' => null, ]); $server = Server::create($server_details); $server->settings->is_reachable = true; @@ -177,6 +179,8 @@ public function run(): void $server_details['proxy'] = ServerMetadata::from([ 'type' => ProxyTypes::TRAEFIK->value, 'status' => ProxyStatus::EXITED->value, + 'last_saved_settings' => null, + 'last_applied_settings' => null, ]); $server = Server::create($server_details); $server->settings->is_reachable = true; diff --git a/resources/views/components/callout.blade.php b/resources/views/components/callout.blade.php index e65dad63b..67da3ba7f 100644 --- a/resources/views/components/callout.blade.php +++ b/resources/views/components/callout.blade.php @@ -1,13 +1,13 @@ -@props(['type' => 'warning', 'title' => 'Warning', 'class' => '']) +@props(['type' => 'warning', 'title' => 'Warning', 'class' => '', 'dismissible' => false, 'onDismiss' => null]) @php $icons = [ 'warning' => '', - + 'danger' => '', - + 'info' => '', - + 'success' => '' ]; @@ -42,12 +42,12 @@ $icon = $icons[$type] ?? $icons['warning']; @endphp -