fix(compose): normalize service-name keys for domains and env vars (#11040)

This commit is contained in:
Andras Bacsai
2026-08-03 23:08:56 +02:00
committed by GitHub
parent 7b18777f06
commit 0b843bb07c
18 changed files with 1443 additions and 220 deletions
@@ -211,6 +211,86 @@ YAML;
->and($domains['backend']['domain'])->toStartWith('http://');
});
test('applicationParser stores domains under original hyphenated compose service names', function () {
$dockerCompose = <<<'YAML'
services:
another-service:
image: myapp/api:latest
environment:
- SERVICE_FQDN_ANOTHER_SERVICE=${API_URL}
analytics:
image: myapp/analytics:latest
YAML;
$application = Application::factory()->create([
'environment_id' => $this->environment->id,
'destination_id' => $this->destination->id,
'destination_type' => StandaloneDocker::class,
'build_pack' => 'dockercompose',
'docker_compose_raw' => $dockerCompose,
'fqdn' => null,
'docker_compose_domains' => null,
]);
applicationParser($application);
$application->refresh();
$domains = json_decode($application->docker_compose_domains, true);
expect($domains)->toBeArray()
->and($domains)->toHaveKey('another-service')
->and($domains)->not->toHaveKey('another_service')
->and($domains['another-service']['domain'])->toStartWith('http://');
});
test('applicationParser preserves legacy underscore domain keys by matching hyphenated services', function () {
$dockerCompose = <<<'YAML'
services:
another-service:
image: myapp/api:latest
environment:
- SERVICE_FQDN_ANOTHER_SERVICE=${API_URL}
YAML;
$application = Application::factory()->create([
'environment_id' => $this->environment->id,
'destination_id' => $this->destination->id,
'destination_type' => StandaloneDocker::class,
'build_pack' => 'dockercompose',
'docker_compose_raw' => $dockerCompose,
'fqdn' => null,
'docker_compose_domains' => json_encode([
'another_service' => ['domain' => 'https://legacy.example.com'],
]),
]);
applicationParser($application);
$application->refresh();
$domains = json_decode($application->docker_compose_domains, true);
// Existing domain is preserved (not overwritten) even when stored under legacy underscore key.
expect(getComposeServiceDomainString($domains, 'another-service'))->toBe('https://legacy.example.com');
});
test('compose domain reconciliation preserves stored domains when parsing returns no services', function () {
$storedDomains = json_encode([
'frontend' => ['domain' => 'https://frontend.example.com'],
]);
$application = Application::factory()->create([
'environment_id' => $this->environment->id,
'destination_id' => $this->destination->id,
'destination_type' => StandaloneDocker::class,
'build_pack' => 'dockercompose',
'docker_compose_domains' => $storedDomains,
]);
$method = new ReflectionMethod($application, 'reconcileDockerComposeDomains');
$method->invoke($application, ['services' => []]);
expect($application->fresh()->docker_compose_domains)->toBe($storedDomains);
});
test('applicationParser handles other docker compose domain shapes without regressions', function () {
$createApplication = function (string $dockerCompose, ?string $dockerComposeDomains = null): Application {
return Application::factory()->create([