mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(cloud): refresh local versions.json hourly on every node
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
666ae60c2c
commit
b1f2abf868
@@ -2,6 +2,8 @@
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Get cached versions data from versions.json.
|
||||
@@ -51,3 +53,59 @@ function invalidate_versions_cache(): void
|
||||
{
|
||||
Cache::forget('coolify:versions:all');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch versions.json from the CDN and write it to the local file of this node.
|
||||
* The Coolify version never goes below the cached or the running version.
|
||||
* When the CDN fails, the local file stays as it is.
|
||||
*
|
||||
* @return array|null The written versions data, or null if the CDN fetch failed
|
||||
*/
|
||||
function refresh_versions_file(): ?array
|
||||
{
|
||||
$response = Http::timeout(10)->retry(3, 1000, throw: false)->get(config('constants.coolify.versions_url'));
|
||||
$versions = $response->json();
|
||||
if ($response->failed() || ! is_array($versions)) {
|
||||
Log::warning('Could not fetch versions.json from the CDN, using the local file', ['status' => $response->status()]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$latestVersion = data_get($versions, 'coolify.v4.version');
|
||||
$currentVersion = config('constants.coolify.version');
|
||||
|
||||
$existingCoolifyVersion = null;
|
||||
if (File::exists(base_path('versions.json'))) {
|
||||
$existingVersions = json_decode(File::get(base_path('versions.json')), true);
|
||||
$existingCoolifyVersion = data_get($existingVersions, 'coolify.v4.version');
|
||||
}
|
||||
|
||||
$bestVersion = $latestVersion;
|
||||
|
||||
if ($existingCoolifyVersion && version_compare($existingCoolifyVersion, $bestVersion, '>')) {
|
||||
Log::warning('CDN served older Coolify version than cache', [
|
||||
'cdn_version' => $latestVersion,
|
||||
'cached_version' => $existingCoolifyVersion,
|
||||
'current_version' => $currentVersion,
|
||||
]);
|
||||
$bestVersion = $existingCoolifyVersion;
|
||||
}
|
||||
|
||||
if (version_compare($bestVersion, $currentVersion, '<')) {
|
||||
Log::warning('Version downgrade prevented in CheckForUpdatesJob', [
|
||||
'cdn_version' => $latestVersion,
|
||||
'cached_version' => $existingCoolifyVersion,
|
||||
'current_version' => $currentVersion,
|
||||
'attempted_best' => $bestVersion,
|
||||
'using' => $currentVersion,
|
||||
]);
|
||||
$bestVersion = $currentVersion;
|
||||
}
|
||||
|
||||
data_set($versions, 'coolify.v4.version', $bestVersion);
|
||||
|
||||
File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT));
|
||||
invalidate_versions_cache();
|
||||
|
||||
return $versions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user