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

This commit is contained in:
Andras Bacsai
2026-09-16 13:33:29 +02:00
committed by GitHub
parent 16b092336e
commit 1b842090ad
3 changed files with 45 additions and 2 deletions
+1 -1
View File
@@ -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([]);
}
+1 -1
View File
@@ -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([]);
}
@@ -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,