diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 5dbdbf215..6cf642f27 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -329,7 +329,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue } else { $this->write_deployment_configurations(); } - $this->application_deployment_queue->addLogEntry("Starting graceful shutdown container: {$this->deployment_uuid}"); + $this->application_deployment_queue->addLogEntry("Gracefully shutting down build container: {$this->deployment_uuid}"); $this->graceful_shutdown_container($this->deployment_uuid); ApplicationStatusChanged::dispatch(data_get($this->application, 'environment.project.team.id')); @@ -1361,7 +1361,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue } } $this->application_deployment_queue->addLogEntry("Preparing container with helper image: $helperImage."); - $this->application_deployment_queue->addLogEntry("Starting graceful shutdown container: {$this->deployment_uuid}"); $this->graceful_shutdown_container($this->deployment_uuid); $this->execute_remote_command( [ @@ -1710,6 +1709,10 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue ]); $this->application->parseHealthcheckFromDockerfile($this->saved_outputs->get('dockerfile_from_repo')); } + $custom_network_aliases = []; + if (is_array($this->application->custom_network_aliases) && count($this->application->custom_network_aliases) > 0) { + $custom_network_aliases = $this->application->custom_network_aliases; + } $docker_compose = [ 'services' => [ $this->container_name => [ @@ -1719,9 +1722,10 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue 'expose' => $ports, 'networks' => [ $this->destination->network => [ - 'aliases' => [ - $this->container_name, - ], + 'aliases' => array_merge( + [$this->container_name], + $custom_network_aliases + ), ], ], 'mem_limit' => $this->application->limits_memory, diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index 9e5126281..eaa988b99 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -68,6 +68,7 @@ class General extends Component 'application.publish_directory' => 'nullable', 'application.ports_exposes' => 'required', 'application.ports_mappings' => 'nullable', + 'application.custom_network_aliases' => 'nullable', 'application.dockerfile' => 'nullable', 'application.docker_registry_image_name' => 'nullable', 'application.docker_registry_image_tag' => 'nullable', @@ -121,6 +122,7 @@ class General extends Component 'application.custom_labels' => 'Custom labels', 'application.dockerfile_target_build' => 'Dockerfile target build', 'application.custom_docker_run_options' => 'Custom docker run commands', + 'application.custom_network_aliases' => 'Custom docker network aliases', 'application.docker_compose_custom_start_command' => 'Docker compose custom start command', 'application.docker_compose_custom_build_command' => 'Docker compose custom build command', 'application.custom_nginx_configuration' => 'Custom Nginx configuration', diff --git a/app/Models/Application.php b/app/Models/Application.php index d07577cc7..2feaebf94 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -45,6 +45,7 @@ use Visus\Cuid2\Cuid2; 'start_command' => ['type' => 'string', 'description' => 'Start command.'], 'ports_exposes' => ['type' => 'string', 'description' => 'Ports exposes.'], 'ports_mappings' => ['type' => 'string', 'nullable' => true, 'description' => 'Ports mappings.'], + 'custom_network_aliases' => ['type' => 'string', 'nullable' => true, 'description' => 'Network aliases for Docker container.'], 'base_directory' => ['type' => 'string', 'description' => 'Base directory for all commands.'], 'publish_directory' => ['type' => 'string', 'description' => 'Publish directory.'], 'health_check_enabled' => ['type' => 'boolean', 'description' => 'Health check enabled.'], @@ -115,6 +116,68 @@ class Application extends BaseModel protected $appends = ['server_status']; + protected $casts = ['custom_network_aliases' => 'array']; + + public function customNetworkAliases(): Attribute + { + return Attribute::make( + set: function ($value) { + if (is_null($value) || $value === '') { + return null; + } + + // If it's already a JSON string, decode it + if (is_string($value) && $this->isJson($value)) { + $value = json_decode($value, true); + } + + // If it's a string but not JSON, treat it as a comma-separated list + if (is_string($value) && ! is_array($value)) { + $value = explode(',', $value); + } + + $value = collect($value) + ->map(function ($alias) { + if (is_string($alias)) { + return str_replace(' ', '-', trim($alias)); + } + + return null; + }) + ->filter() + ->unique() // Remove duplicate values + ->values() + ->toArray(); + + return empty($value) ? null : json_encode($value); + }, + get: function ($value) { + if (is_null($value)) { + return null; + } + + if (is_string($value) && $this->isJson($value)) { + return json_decode($value, true); + } + + return is_array($value) ? $value : []; + } + ); + } + + /** + * Check if a string is a valid JSON + */ + private function isJson($string) + { + if (! is_string($string)) { + return false; + } + json_decode($string); + + return json_last_error() === JSON_ERROR_NONE; + } + protected static function booted() { static::addGlobalScope('withRelations', function ($builder) { diff --git a/database/migrations/2025_01_05_050736_add_network_aliases_to_applications_table.php b/database/migrations/2025_01_05_050736_add_network_aliases_to_applications_table.php new file mode 100644 index 000000000..61fadd0e5 --- /dev/null +++ b/database/migrations/2025_01_05_050736_add_network_aliases_to_applications_table.php @@ -0,0 +1,22 @@ +text('custom_network_aliases')->nullable(); + }); + } + + public function down() + { + Schema::table('applications', function (Blueprint $table) { + $table->dropColumn('custom_network_aliases'); + }); + } +}; diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index 8c12d1d62..f971c8a4f 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -342,6 +342,11 @@ @endif + @if (!$application->destination->server->isSwarm()) + + @endif @if ($application->settings->is_container_label_readonly_enabled)