fix(docker): use custom container names for compose applications

This commit is contained in:
peaklabs-dev
2026-09-09 13:38:07 +02:00
parent de013ace2a
commit 8d07bb9274
3 changed files with 7 additions and 29 deletions
+1 -14
View File
@@ -273,7 +273,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$this->configuration_dir = application_configuration_dir()."/{$this->application->uuid}";
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
$this->container_name = $this->resolveContainerName();
$this->container_name = generateApplicationContainerName($this->application, $this->pull_request_id);
$this->saved_outputs = collect();
@@ -2216,19 +2216,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
}
}
private function resolveContainerName(): string
{
if (! $this->application->settings->is_consistent_container_name_enabled || str($this->application->settings->custom_internal_name)->isEmpty()) {
return generateApplicationContainerName($this->application, $this->pull_request_id);
}
if ($this->pull_request_id === 0) {
return $this->application->settings->custom_internal_name;
}
return addPreviewDeploymentSuffix($this->application->settings->custom_internal_name, $this->pull_request_id);
}
private function health_check()
{
try {
+3 -2
View File
@@ -349,12 +349,13 @@ function generateApplicationContainerName(Application $application, $pull_reques
// TODO: refactor generateApplicationContainerName, we do not need $application and $pull_request_id
$consistent_container_name = $application->settings->is_consistent_container_name_enabled;
$name = $consistent_container_name ? ($application->settings->custom_internal_name ?: $application->uuid) : $application->uuid;
$now = now()->format('Hisu');
if ($pull_request_id !== 0 && $pull_request_id !== null) {
return $application->uuid.'-pr-'.$pull_request_id;
return $name.'-pr-'.$pull_request_id;
} else {
if ($consistent_container_name) {
return $application->uuid;
return $name;
}
return $application->uuid.'-'.$now;
@@ -28,19 +28,11 @@ function applicationWithContainerNaming(string $customName = 'shadowuw'): Applic
}
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');
expect(generateApplicationContainerName(applicationWithContainerNaming()))->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');
expect(generateApplicationContainerName(applicationWithContainerNaming(), 42))->toBe('shadowuw-pr-42');
});
it('includes old generated containers when cleaning up a consistent deployment', function () {
@@ -61,7 +53,5 @@ it('ignores the custom container name when consistent naming is disabled', funct
$application = applicationWithContainerNaming();
$application->settings->is_consistent_container_name_enabled = false;
[$job, $reflection] = containerNamingJob($application);
expect($reflection->getMethod('resolveContainerName')->invoke($job))->toStartWith('application-uuid-');
expect(generateApplicationContainerName($application))->toStartWith('application-uuid-');
});