An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(services): resolve the old denoKV template key to deno-kv
Andras Bacsaia5ec854e3525
diff --git a/app/Http/Controllers/Api/ServicesController.php b/app/Http/Controllers/Api/ServicesController.phpindex dba19f6751..988f380ea9 100644--- a/app/Http/Controllers/Api/ServicesController.php+++ b/app/Http/Controllers/Api/ServicesController.php@@ -507,6 +507,9 @@ class ServicesController extends Controller}}$services = get_service_templates();+ if (filled($request->type)) {+ $request->offsetSet('type', resolve_service_template_key($request->type, $services));+ }$serviceKeys = $services->keys();if ($serviceKeys->contains($request->type)) {$oneClickServiceName = $request->type;diff --git a/app/Livewire/Project/Resource/Create.php b/app/Livewire/Project/Resource/Create.phpindex 1558a44138..d523fb3b9f 100644--- a/app/Livewire/Project/Resource/Create.php+++ b/app/Livewire/Project/Resource/Create.php@@ -78,7 +78,7 @@ class Create extends Component]);}if ($type->startsWith('one-click-service-')) {- $oneClickServiceName = $type->after('one-click-service-')->value();+ $oneClickServiceName = resolve_service_template_key($type->after('one-click-service-')->value(), $services);$oneClickService = data_get($services, "$oneClickServiceName.compose");$oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null);if ($oneClickDotEnvs) {diff --git a/app/Models/Service.php b/app/Models/Service.phpindex 3d795efac0..e3f343375c 100644--- a/app/Models/Service.php+++ b/app/Models/Service.php@@ -1463,7 +1463,7 @@ class Service extends BaseModelpublic function documentation(){$services = get_service_templates();- $service = data_get($services, str($this->name)->beforeLast('-')->value, []);+ $service = data_get($services, resolve_service_template_key(str($this->name)->beforeLast('-')->value, $services), []);return data_get($service, 'documentation', config('constants.urls.docs'));}@@ -1478,7 +1478,7 @@ class Service extends BaseModelif (blank($this->service_type)) {return null;}- $serviceName = $this->service_type;+ $serviceName = resolve_service_template_key($this->service_type, $services);$service = data_get($services, $serviceName, []);$port = data_get($service, 'port');diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 9b97c551c5..cf620bb964 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -1568,6 +1568,24 @@ function get_service_templates(bool $force = false): Collection});}+/**+ * The template key for a service type. A renamed template keeps its old key as an alias, so API callers+ * and services stored with the old key still find the template. A key that the templates contain is+ * returned as is.+ */+function resolve_service_template_key(?string $type, ?Collection $templates = null): ?string+{+ $aliases = [+ 'denoKV' => 'deno-kv',+ ];+ if (blank($type) || ! isset($aliases[$type])) {+ return $type;+ }+ $templates ??= get_service_templates();++ return $templates->has($type) ? $type : $aliases[$type];+}+function getResourceByUuid(string $uuid, ?int $teamId = null){if (is_null($teamId)) {diff --git a/tests/Feature/ServiceTemplateAliasTest.php b/tests/Feature/ServiceTemplateAliasTest.phpnew file mode 100644index 0000000000..f2a29a8d38--- /dev/null+++ b/tests/Feature/ServiceTemplateAliasTest.php@@ -0,0 +1,54 @@+<?php++use App\Models\Service;+use Illuminate\Support\Facades\Cache;++beforeEach(function () {+ Cache::flush();+});++/**+ * Stores a service templates bundle in the shared cache, as the CDN pull does.+ *+ * @param list<string> $keys+ */+function storeServiceTemplateAliasBundle(array $keys): void+{+ $templates = collect($keys)->mapWithKeys(fn (string $key) => [$key => ['compose' => '', 'documentation' => "https://example.com/{$key}"]])->all();+ Cache::forever(service_templates_cache_key(), [+ 'fetched_at' => now()->toIso8601String(),+ 'json' => json_encode($templates, JSON_THROW_ON_ERROR),+ ]);+}++it('resolves the old key of a renamed service template to the new key', function () {+ storeServiceTemplateAliasBundle(['deno-kv', 'wordpress']);++ expect(resolve_service_template_key('denoKV'))->toBe('deno-kv')+ ->and(data_get(get_service_templates(), resolve_service_template_key('denoKV').'.documentation'))->toBe('https://example.com/deno-kv');+});++it('keeps a key that the templates contain', function (array $keys, string $key) {+ storeServiceTemplateAliasBundle($keys);++ expect(resolve_service_template_key($key))->toBe($key);+})->with([+ 'current key' => [['deno-kv'], 'deno-kv'],+ 'old key in an old templates bundle' => [['denoKV'], 'denoKV'],+ 'unknown key' => [['deno-kv'], 'unknown-template'],+]);++it('finds the template of an existing service that was created with the old key', function () {+ storeServiceTemplateAliasBundle(['deno-kv']);+ $templates = json_decode(Cache::get(service_templates_cache_key())['json'], true);+ $templates['deno-kv']['port'] = '4512';+ Cache::forever(service_templates_cache_key(), [+ 'fetched_at' => now()->toIso8601String(),+ 'json' => json_encode($templates, JSON_THROW_ON_ERROR),+ ]);++ $service = (new Service)->forceFill(['name' => 'denoKV-abc123', 'service_type' => 'denoKV']);++ expect($service->documentation())->toBe('https://example.com/deno-kv')+ ->and($service->getRequiredPort())->toBe(4512);+});