feat: add custom container name prefix option

This commit is contained in:
TheGenio 2026-02-02 00:49:22 +03:00
parent 3b68914b73
commit 596f8bcf97
4 changed files with 63 additions and 1 deletions

View file

@ -70,6 +70,9 @@ class Advanced extends Component
#[Validate(['string', 'nullable'])]
public ?string $customInternalName = null;
#[Validate(['string', 'nullable'])]
public ?string $customContainerNamePrefix = null;
#[Validate(['boolean'])]
public bool $isGzipEnabled = true;
@ -111,6 +114,7 @@ class Advanced extends Component
$this->application->settings->is_build_server_enabled = $this->isBuildServerEnabled;
$this->application->settings->is_consistent_container_name_enabled = $this->isConsistentContainerNameEnabled;
$this->application->settings->custom_internal_name = $this->customInternalName;
$this->application->settings->custom_container_name_prefix = $this->customContainerNamePrefix;
$this->application->settings->is_gzip_enabled = $this->isGzipEnabled;
$this->application->settings->is_stripprefix_enabled = $this->isStripprefixEnabled;
$this->application->settings->is_raw_compose_deployment_enabled = $this->isRawComposeDeploymentEnabled;
@ -139,6 +143,7 @@ class Advanced extends Component
$this->isBuildServerEnabled = $this->application->settings->is_build_server_enabled;
$this->isConsistentContainerNameEnabled = $this->application->settings->is_consistent_container_name_enabled;
$this->customInternalName = $this->application->settings->custom_internal_name;
$this->customContainerNamePrefix = $this->application->settings->custom_container_name_prefix;
$this->isRawComposeDeploymentEnabled = $this->application->settings->is_raw_compose_deployment_enabled;
$this->isConnectToDockerNetworkEnabled = $this->application->settings->connect_to_docker_network;
$this->disableBuildCache = $this->application->settings->disable_build_cache;
@ -252,6 +257,24 @@ class Advanced extends Component
}
}
public function saveCustomNamePrefix()
{
try {
$this->authorize('update', $this->application);
if (str($this->customContainerNamePrefix)->isNotEmpty()) {
$this->customContainerNamePrefix = str($this->customContainerNamePrefix)->slug()->value();
} else {
$this->customContainerNamePrefix = null;
}
$this->syncData(true);
$this->dispatch('success', 'Custom container name prefix saved.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.application.advanced');

View file

@ -180,6 +180,7 @@ 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;
$custom_container_name_prefix = $application->settings->custom_container_name_prefix;
$now = now()->format('Hisu');
if ($pull_request_id !== 0 && $pull_request_id !== null) {
return $application->uuid.'-pr-'.$pull_request_id;
@ -188,7 +189,10 @@ function generateApplicationContainerName(Application $application, $pull_reques
return $application->uuid;
}
return $application->uuid.'-'.$now;
// Use custom prefix if set, otherwise use uuid
$prefix = $custom_container_name_prefix ?? $application->uuid;
return $prefix.'-'.$now;
}
}
function get_port_from_dockerfile($dockerfile): ?int

View file

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('application_settings', function (Blueprint $table) {
$table->string('custom_container_name_prefix')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('application_settings', function (Blueprint $table) {
$table->dropColumn('custom_container_name_prefix');
});
}
};

View file

@ -68,6 +68,13 @@
:canResource="$application" />
<x-forms.button canGate="update" :canResource="$application" type="submit">Save</x-forms.button>
</form>
<form class="flex items-end gap-2 " wire:submit.prevent='saveCustomNamePrefix'>
<x-forms.input
helper="Set a custom prefix for your container name. The final name will be: <span class='font-bold'>your-prefix-randomGibberish</span>.<br><br>The name will be converted to slug format when you save it.<br><br>This option <span class='font-bold dark:text-success'>keeps rolling updates working!</span>"
id="customContainerNamePrefix" label="Custom Container Name Prefix" canGate="update"
:canResource="$application" placeholder="e.g. my-nextjs-app" />
<x-forms.button canGate="update" :canResource="$application" type="submit">Save</x-forms.button>
</form>
@endif
@if ($application->build_pack === 'dockercompose')
<h3 class="pt-4">Network</h3>