fix(api): persist Docker Compose domain ports as overrides

Normalize Compose domains on create and update, retaining explicit ports in
`domain_port_overrides` while storing port-free domain values. Preserve empty
Compose FQDNs and cover both API flows with feature tests.
This commit is contained in:
Andras Bacsai
2026-09-05 14:24:24 +02:00
parent 208f7720bc
commit 47c61feb84
3 changed files with 97 additions and 3 deletions
@@ -165,6 +165,61 @@ test('changing a domain port regenerates managed labels with the requested port'
->and($labels)->not->toContain('loadbalancer.server.port=3000');
});
test('compose domain ports are stored as overrides when updating through the API', function () {
$this->application->update([
'build_pack' => 'dockercompose',
'docker_compose_raw' => "services:\n api:\n image: nginx\n frontend:\n image: nginx\n",
'docker_compose_domains' => json_encode([
'api' => ['domain' => 'https://api.example.com'],
'frontend' => ['domain' => 'https://app.example.com'],
]),
]);
$this->withHeaders(applicationSettingsApiHeaders($this->bearerToken))
->patchJson("/api/v1/applications/{$this->application->uuid}", [
'docker_compose_domains' => [
['name' => 'api', 'domain' => 'https://api.example.com'],
['name' => 'frontend', 'domain' => 'https://app.example.com:80'],
],
])
->assertOk();
$application = $this->application->fresh();
$domains = json_decode($application->docker_compose_domains, true);
expect(data_get($domains, 'frontend.domain'))->toBe('https://app.example.com')
->and($application->domain_port_overrides)->toBe([
'https://app.example.com' => 80,
]);
});
test('compose domain ports are stored as overrides when creating through the API', function () {
Queue::fake();
$response = $this->withHeaders(applicationSettingsApiHeaders($this->bearerToken))
->postJson('/api/v1/applications/public', [
'project_uuid' => $this->project->uuid,
'environment_uuid' => $this->environment->uuid,
'server_uuid' => $this->server->uuid,
'git_repository' => 'https://gitlab.com/coolify/compose-domain-port-test',
'git_branch' => 'main',
'build_pack' => 'dockercompose',
'autogenerate_domain' => false,
'docker_compose_domains' => [
['name' => 'frontend', 'domain' => 'https://app.example.com:80'],
],
])
->assertCreated();
$application = Application::where('uuid', $response->json('uuid'))->firstOrFail();
$domains = json_decode($application->docker_compose_domains, true);
expect(data_get($domains, 'frontend.domain'))->toBe('https://app.example.com')
->and($application->domain_port_overrides)->toBe([
'https://app.example.com' => 80,
]);
});
test('http basic auth updates regenerate managed labels', function () {
$this->application->settings->update(['is_container_label_readonly_enabled' => true]);
$this->application->update([