mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-26 01:10:30 -04:00
fix(docker): use custom container names for compose applications
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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-');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user