Files
coolify/tests/Feature/ComposePreviewServiceAliasTest.php
T
Andras BacsaiandClaude Opus 5.5 3c87879e6b fix(compose): keep service names as hostnames in preview deployments
A preview renames its services to <name>-pr-<id>, so services that call
each other by their Compose names failed to start. Add the original name as an alias on the preview network.

Closes #8030

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 22:02:23 +01:00

64 lines
2.3 KiB
PHP

<?php
use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Models\Environment;
use App\Models\Project;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\Team;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
Server::flushIdentityMap();
$team = Team::factory()->create();
$server = Server::factory()->create(['team_id' => $team->id]);
$destination = StandaloneDocker::query()->where('server_id', $server->id)->first()
?? StandaloneDocker::factory()->create(['server_id' => $server->id]);
$project = Project::factory()->create(['team_id' => $team->id]);
$environment = Environment::factory()->create(['project_id' => $project->id]);
$this->application = Application::factory()->create([
'build_pack' => 'dockercompose',
'environment_id' => $environment->id,
'destination_id' => $destination->id,
'destination_type' => $destination->getMorphClass(),
'docker_compose_raw' => <<<'YAML'
services:
search:
image: getmeili/meilisearch:v1.11.3
web:
image: nginx:alpine
environment:
MEILI_URL: http://search:7700
depends_on:
search:
condition: service_healthy
YAML,
]);
});
it('keeps the compose service name as a hostname on the preview network', function () {
$preview = ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => 685,
'pull_request_html_url' => 'https://github.com/example/repository/pull/685',
]);
$services = $this->application->fresh()->parse(pull_request_id: 685, preview_id: $preview->id)->toArray()['services'];
$previewNetwork = "{$this->application->uuid}-685";
expect(array_keys($services))->toBe(['search-pr-685', 'web-pr-685'])
->and($services['search-pr-685']['networks'])->toBe([$previewNetwork => ['aliases' => ['search']]])
->and($services['web-pr-685']['networks'])->toBe([$previewNetwork => ['aliases' => ['web']]]);
});
it('adds no alias to the network of a production deployment', function () {
$services = $this->application->fresh()->parse()->toArray()['services'];
expect($services['search']['networks'])->toBe([$this->application->uuid => null]);
});