fix(deployments): keep every domain intact in COOLIFY_URL and COOLIFY… (#11527)

Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
This commit is contained in:
Devin Dissanayaka 2026-08-30 20:23:23 +05:30 committed by GitHub
parent ccea7287bf
commit e0d233f933
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 97 additions and 3 deletions

View file

@ -2280,9 +2280,9 @@ private function set_coolify_variables()
$fqdn = $this->preview->fqdn;
}
if (isset($fqdn)) {
$url = Url::fromString($fqdn);
$fqdn = $url->getHost();
$url = $url->withHost($fqdn)->withPort(null)->__toString();
$domains = str($fqdn)->explode(',')->map(fn (string $domain) => trim($domain))->filter();
$url = $domains->map(fn (string $domain) => Url::fromString($domain)->withPort(null)->__toString())->implode(',');
$fqdn = $domains->map(fn (string $domain) => Url::fromString($domain)->getHost())->implode(',');
if ((int) $this->application->compose_parsing_version >= 3) {
$this->coolify_variables .= 'COOLIFY_URL='.escapeShellValue($url).' ';
$this->coolify_variables .= 'COOLIFY_FQDN='.escapeShellValue($fqdn).' ';

View file

@ -0,0 +1,94 @@
<?php
use App\Jobs\ApplicationDeploymentJob;
use App\Models\Application;
use App\Models\Environment;
use App\Models\Project;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\Team;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
class TestableCoolifyUrlDeploymentJob extends ApplicationDeploymentJob
{
public function __construct() {}
public function execute_remote_command(...$commands): void {}
}
function coolifyVariablesForFqdn(string $fqdn, string $composeParsingVersion = '3'): string
{
$team = Team::create([
'name' => 'Coolify Url Team',
'personal_team' => false,
'show_boarding' => false,
]);
$project = Project::create([
'name' => 'Coolify Url Project',
'team_id' => $team->id,
]);
$environment = Environment::where('project_id', $project->id)->firstOrFail();
$server = Server::factory()->create(['team_id' => $team->id]);
$destination = $server->standaloneDockers()->firstOrFail();
$application = Application::factory()->create([
'environment_id' => $environment->id,
'destination_id' => $destination->id,
'destination_type' => StandaloneDocker::class,
'build_pack' => 'dockercompose',
'fqdn' => $fqdn,
]);
// The created hook resets this, so it has to be set afterwards.
$application->compose_parsing_version = $composeParsingVersion;
$application->save();
$job = new TestableCoolifyUrlDeploymentJob;
$reflection = new ReflectionClass(ApplicationDeploymentJob::class);
foreach ([
'application' => $application->fresh(),
'pull_request_id' => 0,
'commit' => 'HEAD',
] as $property => $value) {
$reflection->getProperty($property)->setValue($job, $value);
}
$reflection->getMethod('set_coolify_variables')->invoke($job);
return $reflection->getProperty('coolify_variables')->getValue($job);
}
it('keeps every domain intact when an application has multiple domains', function () {
$variables = coolifyVariablesForFqdn('https://a.example.com,https://b.example.com');
expect($variables)
->toContain("COOLIFY_URL='https://a.example.com,https://b.example.com'")
->toContain("COOLIFY_FQDN='a.example.com,b.example.com'");
});
it('strips the port from every domain when an application has multiple domains', function () {
$variables = coolifyVariablesForFqdn('https://a.example.com:8080,https://b.example.com:9000');
expect($variables)
->toContain("COOLIFY_URL='https://a.example.com,https://b.example.com'")
->toContain("COOLIFY_FQDN='a.example.com,b.example.com'");
});
it('keeps every domain intact on the legacy compose parsing version', function () {
$variables = coolifyVariablesForFqdn('https://a.example.com,https://b.example.com', '2');
expect($variables)
->toContain("COOLIFY_URL='a.example.com,b.example.com'")
->toContain("COOLIFY_FQDN='https://a.example.com,https://b.example.com'");
});
it('still resolves a single domain', function () {
$variables = coolifyVariablesForFqdn('https://a.example.com');
expect($variables)
->toContain("COOLIFY_URL='https://a.example.com'")
->toContain("COOLIFY_FQDN='a.example.com'");
});