diff --git a/app/Livewire/Project/Application/Advanced.php b/app/Livewire/Project/Application/Advanced.php index 75fe6fcfc..bb1e58067 100644 --- a/app/Livewire/Project/Application/Advanced.php +++ b/app/Livewire/Project/Application/Advanced.php @@ -236,12 +236,19 @@ class Advanced extends Component return; } + + $this->customContainerNamePrefix = null; $customInternalName = $this->customInternalName; $server = $this->application->destination->server; $allApplications = $server->applications(); $foundSameInternalName = $allApplications->filter(function ($application) { - return $application->id !== $this->application->id && $application->settings->custom_internal_name === $this->customInternalName; + if ($application->id === $this->application->id) { + return false; + } + + return $application->settings->custom_internal_name === $this->customInternalName + || $application->settings->custom_container_name_prefix === $this->customInternalName; }); if ($foundSameInternalName->isNotEmpty()) { $this->dispatch('error', 'This custom container name is already in use by another application on this server.'); @@ -268,6 +275,32 @@ class Advanced extends Component $this->customContainerNamePrefix = null; } + if (is_null($this->customContainerNamePrefix)) { + $this->syncData(true); + $this->dispatch('success', 'Custom container name prefix saved.'); + + return; + } + + $this->customInternalName = null; + $server = $this->application->destination->server; + $allApplications = $server->applications(); + + $foundDuplicate = $allApplications->filter(function ($application) { + if ($application->id === $this->application->id) { + return false; + } + + return $application->settings->custom_container_name_prefix === $this->customContainerNamePrefix + || $application->settings->custom_internal_name === $this->customContainerNamePrefix; + }); + + if ($foundDuplicate->isNotEmpty()) { + $this->dispatch('error', 'This custom container name prefix is already in use by another application on this server.'); + + return; + } + $this->syncData(true); $this->dispatch('success', 'Custom container name prefix saved.'); } catch (\Throwable $e) { diff --git a/resources/views/livewire/project/application/advanced.blade.php b/resources/views/livewire/project/application/advanced.blade.php index 63656c34f..2c7e4d743 100644 --- a/resources/views/livewire/project/application/advanced.blade.php +++ b/resources/views/livewire/project/application/advanced.blade.php @@ -63,17 +63,20 @@ @if ($isConsistentContainerNameEnabled === false)
- Save + helper="You can add a custom name for your container.

The name will be converted to slug format when you save it. You will lose the rolling update feature!

Cannot be used together with Custom Container Name Prefix." + id="customInternalName" label="Custom Container Name" canGate="update" + :canResource="$application" :disabled="!empty($customContainerNamePrefix)" /> + Save
- Save + :canResource="$application" placeholder="e.g. my-nextjs-app" + :disabled="!empty($customInternalName)" /> + Save @endif @if ($application->build_pack === 'dockercompose')