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
refactor(environment): standardize service name formatting by replacing '-' and '.' with '_' in environment variable keys
Andras Bacsai501e6a265071
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex fab8705441..54201053cf 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -955,7 +955,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue}}} else {- $this->env_filename = addPreviewDeploymentSuffix(".env", $this->pull_request_id);+ $this->env_filename = addPreviewDeploymentSuffix('.env', $this->pull_request_id);foreach ($sorted_environment_variables_preview as $env) {$envs->push($env->key.'='.$env->real_value);}@@ -991,7 +991,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue$rawDockerCompose = Yaml::parse($this->application->docker_compose_raw);$rawServices = data_get($rawDockerCompose, 'services', []);foreach ($rawServices as $rawServiceName => $_) {- $envs->push('SERVICE_NAME_'.str($rawServiceName)->upper().'='.addPreviewDeploymentSuffix($rawServiceName, $this->pull_request_id));+ $envs->push('SERVICE_NAME_'.str($rawServiceName)->upper().'='.addPreviewDeploymentSuffix($rawServiceName, $this->pull_request_id));}}}diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.phpindex 76aa909c8c..9f15011c2a 100644--- a/app/Livewire/Project/Application/General.php+++ b/app/Livewire/Project/Application/General.php@@ -671,7 +671,7 @@ class General extends Component$domains = collect(json_decode($this->application->docker_compose_domains, true)) ?? collect([]);foreach ($domains as $serviceName => $service) {- $serviceNameFormatted = str($serviceName)->upper()->replace('-', '_');+ $serviceNameFormatted = str($serviceName)->upper()->replace('-', '_')->replace('.', '_');$domain = data_get($service, 'domain');// Delete SERVICE_FQDN_ and SERVICE_URL_ variables if domain is removed$this->application->environment_variables()->where('resourceable_type', Application::class)diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 11755b16eb..4a22a1953b 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -1474,14 +1474,14 @@ class Application extends BaseModel$json = collect(json_decode($this->docker_compose_domains));foreach ($json as $key => $value) {if (str($key)->contains('-')) {- $key = str($key)->replace('-', '_');+ $key = str($key)->replace('-', '_')->replace('.', '_');}$json->put((string) $key, $value);}$services = collect(data_get($parsedServices, 'services', []));foreach ($services as $name => $service) {if (str($name)->contains('-')) {- $replacedName = str($name)->replace('-', '_');+ $replacedName = str($name)->replace('-', '_')->replace('.', '_');$services->put((string) $replacedName, $service);$services->forget((string) $name);}diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.phpindex f162039a22..3dbfb6b33a 100644--- a/bootstrap/helpers/parsers.php+++ b/bootstrap/helpers/parsers.php@@ -373,7 +373,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int$fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();$originalFqdnFor = str($fqdnFor)->replace('_', '-');if (str($fqdnFor)->contains('-')) {- $fqdnFor = str($fqdnFor)->replace('-', '_');+ $fqdnFor = str($fqdnFor)->replace('-', '_')->replace('.', '_');}// Generated FQDN & URL$fqdn = generateFqdn(server: $server, random: "$originalFqdnFor-$uuid", parserVersion: $resource->compose_parsing_version);@@ -409,7 +409,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int$urlFor = $key->after('SERVICE_URL_')->lower()->value();$originalUrlFor = str($urlFor)->replace('_', '-');if (str($urlFor)->contains('-')) {- $urlFor = str($urlFor)->replace('-', '_');+ $urlFor = str($urlFor)->replace('-', '_')->replace('.', '_');}$url = generateUrl(server: $server, random: "$originalUrlFor-$uuid");$resource->environment_variables()->firstOrCreate([@@ -864,13 +864,13 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?intif ($resource->build_pack !== 'dockercompose') {$domains = collect([]);}- $changedServiceName = str($serviceName)->replace('-', '_')->value();+ $changedServiceName = str($serviceName)->replace('-', '_')->replace('.', '_')->value();$fqdns = data_get($domains, "$changedServiceName.domain");// Generate SERVICE_FQDN & SERVICE_URL for dockercomposeif ($resource->build_pack === 'dockercompose') {foreach ($domains as $forServiceName => $domain) {$parsedDomain = data_get($domain, 'domain');- $serviceNameFormatted = str($serviceName)->upper()->replace('-', '_');+ $serviceNameFormatted = str($serviceName)->upper()->replace('-', '_')->replace('.', '_');if (filled($parsedDomain)) {$parsedDomain = str($parsedDomain)->explode(',')->first();@@ -878,12 +878,12 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int$coolifyScheme = $coolifyUrl->getScheme();$coolifyFqdn = $coolifyUrl->getHost();$coolifyUrl = $coolifyUrl->withScheme($coolifyScheme)->withHost($coolifyFqdn)->withPort(null);- $coolifyEnvironments->put('SERVICE_URL_'.str($forServiceName)->upper()->replace('-', '_'), $coolifyUrl->__toString());- $coolifyEnvironments->put('SERVICE_FQDN_'.str($forServiceName)->upper()->replace('-', '_'), $coolifyFqdn);+ $coolifyEnvironments->put('SERVICE_URL_'.str($forServiceName)->upper()->replace('-', '_')->replace('.', '_'), $coolifyUrl->__toString());+ $coolifyEnvironments->put('SERVICE_FQDN_'.str($forServiceName)->upper()->replace('-', '_')->replace('.', '_'), $coolifyFqdn);$resource->environment_variables()->updateOrCreate(['resourceable_type' => Application::class,'resourceable_id' => $resource->id,- 'key' => 'SERVICE_URL_'.str($forServiceName)->upper()->replace('-', '_'),+ 'key' => 'SERVICE_URL_'.str($forServiceName)->upper()->replace('-', '_')->replace('.', '_'),], ['value' => $coolifyUrl->__toString(),'is_build_time' => false,@@ -892,7 +892,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int$resource->environment_variables()->updateOrCreate(['resourceable_type' => Application::class,'resourceable_id' => $resource->id,- 'key' => 'SERVICE_FQDN_'.str($forServiceName)->upper()->replace('-', '_'),+ 'key' => 'SERVICE_FQDN_'.str($forServiceName)->upper()->replace('-', '_')->replace('.', '_'),], ['value' => $coolifyFqdn,'is_build_time' => false,diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.phpindex 7b53c538e9..7d3cb71ff0 100644--- a/bootstrap/helpers/services.php+++ b/bootstrap/helpers/services.php@@ -114,14 +114,14 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)$resource->save();}- $serviceName = str($resource->name)->upper()->replace('-', '_');+ $serviceName = str($resource->name)->upper()->replace('-', '_')->replace('.', '_');$resource->service->environment_variables()->where('key', 'LIKE', "SERVICE_FQDN_{$serviceName}%")->delete();$resource->service->environment_variables()->where('key', 'LIKE', "SERVICE_URL_{$serviceName}%")->delete();if ($resource->fqdn) {$resourceFqdns = str($resource->fqdn)->explode(',');$resourceFqdns = $resourceFqdns->first();- $variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_');+ $variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_')->replace('.', '_');$url = Url::fromString($resourceFqdns);$port = $url->getPort();$path = $url->getPath();@@ -148,7 +148,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)'is_preview' => false,]);}- $variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_');+ $variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_')->replace('.', '_');$fqdn = Url::fromString($resourceFqdns);$port = $fqdn->getPort();$path = $fqdn->getPath();diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex a5a64fa9be..6778a0ed11 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -3003,14 +3003,15 @@ function parseDockerfileInterval(string $something)function addPreviewDeploymentSuffix(string $name, int $pull_request_id = 0): string{- return ($pull_request_id === 0)? $name : $name.'-pr-'.$pull_request_id;+ return ($pull_request_id === 0) ? $name : $name.'-pr-'.$pull_request_id;}-function generateDockerComposeServiceName(mixed $services, int $pullRequestId = 0) : Collection+function generateDockerComposeServiceName(mixed $services, int $pullRequestId = 0): Collection{$collection = collect([]);foreach ($services as $serviceName => $_) {- $collection->put('SERVICE_NAME_'.str($serviceName)->upper(), addPreviewDeploymentSuffix($serviceName,$pullRequestId));+ $collection->put('SERVICE_NAME_'.str($serviceName)->replace('-', '_')->replace('.', '_')->upper(), addPreviewDeploymentSuffix($serviceName, $pullRequestId));}+return $collection;}