mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-27 17:55:59 -04:00
fix: preserve custom names and use Livewire redirects
Resolve custom container names consistently, clean up legacy container names during deployments, and route Livewire resource redirects through the navigation helper.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\ApplicationDeploymentJob;
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationSetting;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
function containerNamingJob(Application $application, int $pullRequestId = 0): array
|
||||
{
|
||||
$job = (new ReflectionClass(ApplicationDeploymentJob::class))->newInstanceWithoutConstructor();
|
||||
$reflection = new ReflectionClass(ApplicationDeploymentJob::class);
|
||||
$reflection->getProperty('application')->setValue($job, $application);
|
||||
$reflection->getProperty('pull_request_id')->setValue($job, $pullRequestId);
|
||||
|
||||
return [$job, $reflection];
|
||||
}
|
||||
|
||||
function applicationWithContainerNaming(string $customName = 'shadowuw'): Application
|
||||
{
|
||||
$application = new Application;
|
||||
$application->forceFill(['uuid' => 'application-uuid']);
|
||||
$application->setRelation('settings', new ApplicationSetting([
|
||||
'custom_internal_name' => $customName,
|
||||
'is_consistent_container_name_enabled' => true,
|
||||
]));
|
||||
|
||||
return $application;
|
||||
}
|
||||
|
||||
it('uses the custom container name when consistent naming is enabled', function () {
|
||||
$application = applicationWithContainerNaming();
|
||||
|
||||
[$job, $reflection] = containerNamingJob($application);
|
||||
|
||||
expect($reflection->getMethod('resolveContainerName')->invoke($job))->toBe('shadowuw');
|
||||
});
|
||||
|
||||
it('adds the pull request suffix to a custom container name', function () {
|
||||
$application = applicationWithContainerNaming();
|
||||
|
||||
[$job, $reflection] = containerNamingJob($application, 42);
|
||||
|
||||
expect($reflection->getMethod('resolveContainerName')->invoke($job))->toBe('shadowuw-pr-42');
|
||||
});
|
||||
|
||||
it('includes old generated containers when cleaning up a consistent deployment', function () {
|
||||
$application = applicationWithContainerNaming();
|
||||
[$job, $reflection] = containerNamingJob($application);
|
||||
$reflection->getProperty('container_name')->setValue($job, 'shadowuw');
|
||||
|
||||
$containers = new Collection([
|
||||
['Names' => 'application-uuid-192238854305'],
|
||||
['Names' => 'shadowuw'],
|
||||
]);
|
||||
|
||||
expect($reflection->getMethod('containerNamesToRemove')->invoke($job, $containers)->all())
|
||||
->toBe(['application-uuid-192238854305', 'shadowuw']);
|
||||
});
|
||||
@@ -64,7 +64,7 @@ function generateComposeServiceWithCustomDockerOptions(string $customDockerOptio
|
||||
'server' => $server,
|
||||
'mainServer' => $server,
|
||||
'pull_request_id' => 0,
|
||||
'container_name' => $application->uuid,
|
||||
'container_name' => 'custom-internal-name',
|
||||
'production_image_name' => 'example/app:latest',
|
||||
'deployment_uuid' => 'deployment-uuid',
|
||||
'workdir' => '/artifacts/custom-docker-options-app',
|
||||
@@ -82,7 +82,8 @@ function generateComposeServiceWithCustomDockerOptions(string $customDockerOptio
|
||||
|
||||
it('applies an entrypoint when consistent naming and a custom internal name are configured', function () {
|
||||
expect(generateComposeServiceWithCustomDockerOptions('--entrypoint "/bin/echo hello world"'))
|
||||
->toHaveKey('entrypoint', '/bin/echo hello world');
|
||||
->toHaveKey('entrypoint', '/bin/echo hello world')
|
||||
->toHaveKey('container_name', 'custom-internal-name');
|
||||
});
|
||||
|
||||
it('preserves custom network aliases when a static IP is configured', function () {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
it('uses Livewire navigation after deleting or converting page resources', function (string $path, array $redirects) {
|
||||
$contents = file_get_contents(dirname(__DIR__, 2).'/'.$path);
|
||||
|
||||
foreach ($redirects as $redirect) {
|
||||
expect($contents)->toContain($redirect);
|
||||
}
|
||||
})->with([
|
||||
'S3 storage' => [
|
||||
'app/Livewire/Storage/Show.php',
|
||||
["redirectRoute(\$this, 'storage.index')"],
|
||||
],
|
||||
'database backup schedule' => [
|
||||
'app/Livewire/Project/Database/BackupEdit.php',
|
||||
[
|
||||
"redirectRoute(\$this, 'project.service.database.backups'",
|
||||
"redirectRoute(\$this, 'project.database.backup.index'",
|
||||
],
|
||||
],
|
||||
'scheduled task' => [
|
||||
'app/Livewire/Project/Shared/ScheduledTask/Show.php',
|
||||
[
|
||||
"redirectRoute(\$this, 'project.application.scheduled-tasks.show'",
|
||||
"redirectRoute(\$this, 'project.service.scheduled-tasks.show'",
|
||||
],
|
||||
],
|
||||
'GitHub source' => [
|
||||
'app/Livewire/Source/Github/Change.php',
|
||||
["redirectRoute(\$this, 'source.all')"],
|
||||
],
|
||||
'GitLab source' => [
|
||||
'app/Livewire/Source/Gitlab/Change.php',
|
||||
["redirectRoute(\$this, 'source.all')"],
|
||||
],
|
||||
'service resources' => [
|
||||
'app/Livewire/Project/Service/Index.php',
|
||||
[
|
||||
"return redirectRoute(\$this, 'project.service.configuration', \$this->parameters);",
|
||||
"return redirectRoute(\$this, 'project.service.configuration', \$redirectParams);",
|
||||
],
|
||||
],
|
||||
]);
|
||||
Reference in New Issue
Block a user