fix(deployment): enhance COOLIFY_URL and COOLIFY_FQDN variable generation for better compatibility

This commit is contained in:
Andras Bacsai
2025-07-07 12:55:35 +02:00
parent e9ca8c3559
commit 085529dc63
3 changed files with 15 additions and 6 deletions

View File

@@ -1347,9 +1347,16 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$fqdn = $this->preview->fqdn; $fqdn = $this->preview->fqdn;
} }
if (isset($fqdn)) { if (isset($fqdn)) {
$this->coolify_variables .= "COOLIFY_FQDN={$fqdn} "; $fqdnWithoutPort = str($fqdn)->after('://')->before(':')->prepend(str($fqdn)->before('://')->append('://'));
$url = str($fqdn)->replace('http://', '')->replace('https://', ''); $url = str($fqdn)->replace('http://', '')->replace('https://', '')->before(':');
$this->coolify_variables .= "COOLIFY_URL={$url} "; if ((int) $this->application->compose_parsing_version >= 3) {
$this->coolify_variables .= "COOLIFY_URL={$fqdnWithoutPort} ";
$this->coolify_variables .= "COOLIFY_FQDN={$url} ";
} else {
$this->coolify_variables .= "COOLIFY_URL={$fqdnWithoutPort} ";
$this->coolify_variables .= "COOLIFY_FQDN={$url} ";
}
} }
if (isset($this->application->git_branch)) { if (isset($this->application->git_branch)) {
$this->coolify_variables .= "COOLIFY_BRANCH={$this->application->git_branch} "; $this->coolify_variables .= "COOLIFY_BRANCH={$this->application->git_branch} ";

View File

@@ -1264,7 +1264,6 @@ class Service extends BaseModel
foreach ($sorted as $env) { foreach ($sorted as $env) {
$envs->push("{$env->key}={$env->real_value}"); $envs->push("{$env->key}={$env->real_value}");
} }
ray($envs);
if ($envs->count() === 0) { if ($envs->count() === 0) {
$commands[] = 'touch .env'; $commands[] = 'touch .env';
} else { } else {

View File

@@ -3716,10 +3716,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
// Add COOLIFY_FQDN & COOLIFY_URL to environment // Add COOLIFY_FQDN & COOLIFY_URL to environment
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) { if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
$coolifyEnvironments->put('COOLIFY_URL', $fqdns->implode(',')); $fqdnsWithoutPort = $fqdns->map(function ($fqdn) {
return str($fqdn)->after('://')->before(':')->prepend(str($fqdn)->before('://')->append('://'));
});
$coolifyEnvironments->put('COOLIFY_URL', $fqdnsWithoutPort->implode(','));
$urls = $fqdns->map(function ($fqdn) { $urls = $fqdns->map(function ($fqdn) {
return str($fqdn)->replace('http://', '')->replace('https://', ''); return str($fqdn)->replace('http://', '')->replace('https://', '')->before(':');
}); });
$coolifyEnvironments->put('COOLIFY_FQDN', $urls->implode(',')); $coolifyEnvironments->put('COOLIFY_FQDN', $urls->implode(','));
} }