diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index d1f5e4016b..f40c51a335 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -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 = []) diff --git a/tests/Feature/HelperVersionTest.php b/tests/Feature/HelperVersionTest.php new file mode 100644 index 0000000000..64ef8466a7 --- /dev/null +++ b/tests/Feature/HelperVersionTest.php @@ -0,0 +1,38 @@ + 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'); +});