mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-25 17:01:49 -04:00
fix(helper): prefer newer fetched helper version
Use a CDN-fetched helper version when it is newer than the bundled version, while ignoring stale stored versions.
This commit is contained in:
@@ -4234,6 +4234,8 @@ function coolifyHelperImage(): string
|
||||
|
||||
function getHelperVersion(): string
|
||||
{
|
||||
$configuredHelperVersion = config('constants.coolify.helper_version');
|
||||
|
||||
if (isDev()) {
|
||||
$devHelperVersion = InstanceSettings::query()->whereKey(0)->value('dev_helper_version');
|
||||
|
||||
@@ -4242,7 +4244,13 @@ function getHelperVersion(): string
|
||||
}
|
||||
}
|
||||
|
||||
return config('constants.coolify.helper_version');
|
||||
$fetchedHelperVersion = InstanceSettings::query()->whereKey(0)->value('helper_version');
|
||||
|
||||
if (! empty($fetchedHelperVersion) && version_compare($fetchedHelperVersion, $configuredHelperVersion, '>')) {
|
||||
return $fetchedHelperVersion;
|
||||
}
|
||||
|
||||
return $configuredHelperVersion;
|
||||
}
|
||||
|
||||
function loggy($message = null, array $context = [])
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\CheckHelperImageJob;
|
||||
use App\Models\InstanceSettings;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
InstanceSettings::forceCreate(['id' => 0]);
|
||||
|
||||
config([
|
||||
'app.env' => 'production',
|
||||
'constants.coolify.helper_version' => '1.0.17',
|
||||
'constants.coolify.versions_url' => 'https://cdn.example.com/coolify/versions.json',
|
||||
]);
|
||||
});
|
||||
|
||||
it('uses a newer helper version after fetching it from the CDN', function () {
|
||||
Http::preventStrayRequests();
|
||||
Http::fake([
|
||||
'https://cdn.example.com/coolify/versions.json' => Http::response([
|
||||
'coolify' => ['helper' => ['version' => '1.0.18']],
|
||||
]),
|
||||
]);
|
||||
|
||||
(new CheckHelperImageJob)->handle();
|
||||
|
||||
expect(InstanceSettings::findOrFail(0)->helper_version)->toBe('1.0.18')
|
||||
->and(getHelperVersion())->toBe('1.0.18');
|
||||
});
|
||||
|
||||
it('does not use a stored helper version older than the bundled version', function () {
|
||||
InstanceSettings::findOrFail(0)->update(['helper_version' => '1.0.16']);
|
||||
|
||||
expect(getHelperVersion())->toBe('1.0.17');
|
||||
});
|
||||
Reference in New Issue
Block a user