fix(parser): populate compose domains from service env keys

This commit is contained in:
Andras Bacsai
2026-07-03 11:57:02 +02:00
parent e551f9c176
commit eddcbe819b
2 changed files with 175 additions and 18 deletions
@@ -82,6 +82,7 @@ YAML;
->and($domains)->toBeArray()
->and($domains)->toHaveKey('backend')
->and($domains['backend'])->toHaveKey('domain')
->and($domains['backend']['domain'])->toStartWith('http://')
->and($domains['backend']['domain'])->not->toBeEmpty();
});
@@ -142,3 +143,147 @@ YAML;
$domains = json_decode($application->docker_compose_domains, true);
expect($domains)->toBeNull();
});
test('applicationParser populates docker_compose_domains for KEY-based SERVICE_URL variables', function () {
$dockerCompose = <<<'YAML'
services:
frontend:
image: myapp/frontend:latest
environment:
- SERVICE_URL_FRONTEND=/ui
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)->not->toBeNull()
->and($domains)->toHaveKey('frontend')
->and($domains['frontend']['domain'])->toStartWith('http://')
->and($domains['frontend']['domain'])->toEndWith('/ui');
});
test('applicationParser preserves existing docker_compose_domains entries', function () {
$dockerCompose = <<<'YAML'
services:
backend:
image: myapp/backend:latest
environment:
- SERVICE_FQDN_BACKEND_8000=${BACKEND_URL}
frontend:
image: myapp/frontend:latest
environment:
- SERVICE_URL_FRONTEND=/ui
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([
'frontend' => ['domain' => 'https://existing.example.com'],
]),
]);
applicationParser($application);
$application->refresh();
$domains = json_decode($application->docker_compose_domains, true);
expect($domains['frontend']['domain'])->toBe('https://existing.example.com')
->and($domains)->toHaveKey('backend')
->and($domains['backend']['domain'])->toStartWith('http://');
});
test('applicationParser handles other docker compose domain shapes without regressions', function () {
$createApplication = function (string $dockerCompose, ?string $dockerComposeDomains = null): Application {
return 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' => $dockerComposeDomains,
]);
};
$valueBasedCompose = <<<'YAML'
services:
backend:
image: myapp/backend:latest
frontend:
image: myapp/frontend:latest
environment:
API_URL: ${SERVICE_URL_BACKEND}
YAML;
$valueBasedApplication = $createApplication($valueBasedCompose);
applicationParser($valueBasedApplication);
$valueBasedApplication->refresh();
$valueBasedDomains = json_decode($valueBasedApplication->docker_compose_domains, true);
expect($valueBasedDomains)->toHaveKey('backend')
->and($valueBasedDomains['backend']['domain'])->toStartWith('http://')
->and($valueBasedDomains)->not->toHaveKey('frontend');
$mapStyleCompose = <<<'YAML'
services:
frontend:
image: myapp/frontend:latest
environment:
SERVICE_URL_FRONTEND: /ui
YAML;
$mapStyleApplication = $createApplication($mapStyleCompose);
applicationParser($mapStyleApplication);
$mapStyleApplication->refresh();
$mapStyleDomains = json_decode($mapStyleApplication->docker_compose_domains, true);
expect($mapStyleDomains)->toHaveKey('frontend')
->and($mapStyleDomains['frontend']['domain'])->toEndWith('/ui');
$missingServiceCompose = <<<'YAML'
services:
worker:
image: myapp/worker:latest
environment:
SERVICE_URL_API: /api
YAML;
$missingServiceApplication = $createApplication($missingServiceCompose);
applicationParser($missingServiceApplication);
$missingServiceApplication->refresh();
expect(json_decode($missingServiceApplication->docker_compose_domains, true))->toBeNull();
$plainCompose = <<<'YAML'
services:
worker:
image: myapp/worker:latest
environment:
FOO: bar
YAML;
$plainApplication = $createApplication($plainCompose);
applicationParser($plainApplication);
$plainApplication->refresh();
expect(json_decode($plainApplication->docker_compose_domains, true))->toBeNull();
});