Skip to content

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.

fix(previews): split compose domains into Traefik labels (#11812)

Andras Bacsai1b842090adb5
diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.php
index 067a27bc20..f145ec0477 100644
--- a/bootstrap/helpers/parsers.php
+++ b/bootstrap/helpers/parsers.php
@@ -1257,7 +1257,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
if ($docker_compose_domains->count() > 0) {
$found_fqdn = getComposeServiceDomainString($docker_compose_domains, (string) $serviceName);
if ($found_fqdn) {
- $fqdns = collect($found_fqdn);
+ $fqdns = str($found_fqdn)->explode(',')->map(fn ($fqdn) => trim($fqdn))->filter();
} else {
$fqdns = collect([]);
}
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index a7a606330e..79dddd59ac 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -3892,7 +3892,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
if (count($docker_compose_domains) > 0) {
$found_fqdn = getComposeServiceDomainString($docker_compose_domains, (string) $serviceName);
if ($found_fqdn) {
- $fqdns = collect($found_fqdn);
+ $fqdns = str($found_fqdn)->explode(',')->map(fn ($fqdn) => trim($fqdn))->filter();
} else {
$fqdns = collect([]);
}
diff --git a/tests/Feature/ApplicationParserDockerComposeDomainsTest.php b/tests/Feature/ApplicationParserDockerComposeDomainsTest.php
index 10e312b545..160abcc5de 100644
--- a/tests/Feature/ApplicationParserDockerComposeDomainsTest.php
+++ b/tests/Feature/ApplicationParserDockerComposeDomainsTest.php
@@ -616,6 +616,49 @@ YAML,
'web and database' => " database:\n image: postgres:16-alpine",
])->with([false, true]);
+test('compose preview labels split multiple domains for one service', function (int $parserVersion) {
+ $application = disableExactProxyLabels(Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => StandaloneDocker::class,
+ 'build_pack' => 'dockercompose',
+ 'compose_parsing_version' => $parserVersion,
+ 'docker_compose_raw' => <<<'YAML'
+services:
+ frontend:
+ image: httpd:2.4-alpine
+YAML,
+ 'fqdn' => null,
+ 'docker_compose_domains' => json_encode([
+ 'frontend' => ['domain' => 'https://app.example.com,https://api.example.com'],
+ ]),
+ ]));
+
+ $preview = ApplicationPreview::create([
+ 'application_id' => $application->id,
+ 'pull_request_id' => 7915,
+ 'pull_request_html_url' => 'https://github.com/coollabsio/coolify/pull/7915',
+ 'fqdn' => 'https://7915.app.example.com,https://7915.api.example.com',
+ 'docker_compose_domains' => json_encode([
+ 'frontend' => ['domain' => 'https://7915.app.example.com,https://7915.api.example.com'],
+ ]),
+ ]);
+
+ $parsedCompose = $application->fresh()->parse(
+ pull_request_id: $preview->pull_request_id,
+ preview_id: $preview->id,
+ );
+ $labels = collect(data_get($parsedCompose, 'services'))
+ ->flatMap(fn ($service) => data_get($service, 'labels', []));
+
+ expect($labels->contains(fn (string $label): bool => str_ends_with($label, 'rule=Host(`7915.app.example.com`) && PathPrefix(`/`)')))
+ ->toBeTrue()
+ ->and($labels->contains(fn (string $label): bool => str_ends_with($label, 'rule=Host(`7915.api.example.com`) && PathPrefix(`/`)')))
+ ->toBeTrue()
+ ->and($labels->contains(fn (string $label): bool => str_contains($label, 'PathPrefix(`//')))
+ ->toBeFalse();
+})->with([2, 3]);
+
test('applicationParser compose labels prefer the service exposed port over application ports_exposes', function (string $portConfiguration) {
$application = disableExactProxyLabels(Application::factory()->create([
'environment_id' => $this->environment->id,