An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(docker): use custom container names for compose applications
peaklabs-dev8d07bb927410
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 5a7ebd762d..2eb6aa41b5 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -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 {diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.phpindex 0060df5b5f..d1b02b8cf4 100644--- a/bootstrap/helpers/docker.php+++ b/bootstrap/helpers/docker.php@@ -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;diff --git a/tests/Unit/ApplicationDeploymentContainerNamingTest.php b/tests/Unit/ApplicationDeploymentContainerNamingTest.phpindex 68197ffa6f..68c47013f4 100644--- a/tests/Unit/ApplicationDeploymentContainerNamingTest.php+++ b/tests/Unit/ApplicationDeploymentContainerNamingTest.php@@ -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-');});