mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-23 12:23:46 +00:00
fix(compose): normalize service-name keys for domains and env vars (#11040)
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user