diff --git a/app/Http/Livewire/Project/Application/Advanced.php b/app/Http/Livewire/Project/Application/Advanced.php new file mode 100644 index 000000000..552a3873a --- /dev/null +++ b/app/Http/Livewire/Project/Application/Advanced.php @@ -0,0 +1,54 @@ + 'boolean|required', + 'application.settings.is_git_lfs_enabled' => 'boolean|required', + 'application.settings.is_preview_deployments_enabled' => 'boolean|required', + 'application.settings.is_auto_deploy_enabled' => 'boolean|required', + 'application.settings.is_force_https_enabled' => 'boolean|required', + 'application.settings.is_log_drain_enabled' => 'boolean|required', + 'application.settings.is_gpu_enabled' => 'boolean|required', + 'application.settings.gpu_driver' => 'string|required', + 'application.settings.gpu_count' => 'string|required', + 'application.settings.gpu_device_ids' => 'string|required', + 'application.settings.gpu_options' => 'string|required', + ]; + public function instantSave() + { + if ($this->application->settings->is_log_drain_enabled) { + if (!$this->application->destination->server->isLogDrainEnabled()) { + $this->application->settings->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on this server.'); + return; + } + } + if ($this->application->settings->is_force_https_enabled) { + $this->emit('resetDefaultLabels', false); + } + $this->application->settings->save(); + $this->emit('success', 'Settings saved.'); + } + public function submit() { + if ($this->application->settings->gpu_count && $this->application->settings->gpu_device_ids) { + $this->emit('error', 'You cannot set both GPU count and GPU device IDs.'); + $this->application->settings->gpu_count = null; + $this->application->settings->gpu_device_ids = null; + $this->application->settings->save(); + return; + } + $this->application->settings->save(); + $this->emit('success', 'Settings saved.'); + } + public function render() + { + return view('livewire.project.application.advanced'); + } +} diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index 63dbeba23..27c5023c3 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -26,14 +26,10 @@ class General extends Component public bool $isConfigurationChanged = false; public bool $is_static; - public bool $is_git_submodules_enabled; - public bool $is_git_lfs_enabled; - public bool $is_debug_enabled; - public bool $is_preview_deployments_enabled; - public bool $is_auto_deploy_enabled; - public bool $is_force_https_enabled; - public bool $is_log_drain_enabled; + protected $listeners = [ + 'resetDefaultLabels' + ]; protected $rules = [ 'application.name' => 'required', 'application.description' => 'nullable', @@ -56,6 +52,7 @@ class General extends Component 'application.dockerfile_location' => 'nullable', 'application.custom_labels' => 'nullable', 'application.dockerfile_target_build' => 'nullable', + 'application.settings.is_static' => 'boolean|required', ]; protected $validationAttributes = [ 'application.name' => 'name', @@ -79,6 +76,7 @@ class General extends Component 'application.dockerfile_location' => 'Dockerfile location', 'application.custom_labels' => 'Custom labels', 'application.dockerfile_target_build' => 'Dockerfile target build', + 'application.settings.is_static' => 'Is static', ]; public function mount() @@ -93,18 +91,13 @@ class General extends Component } else { $this->customLabels = str($this->application->custom_labels)->replace(',', "\n"); } - if (data_get($this->application, 'settings')) { - $this->is_static = $this->application->settings->is_static; - $this->is_git_submodules_enabled = $this->application->settings->is_git_submodules_enabled; - $this->is_git_lfs_enabled = $this->application->settings->is_git_lfs_enabled; - $this->is_debug_enabled = $this->application->settings->is_debug_enabled; - $this->is_preview_deployments_enabled = $this->application->settings->is_preview_deployments_enabled; - $this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled; - $this->is_force_https_enabled = $this->application->settings->is_force_https_enabled; - $this->is_log_drain_enabled = $this->application->settings->is_log_drain_enabled; - } $this->checkLabelUpdates(); } + public function instantSave() + { + $this->application->settings->save(); + $this->emit('success', 'Settings saved.'); + } public function updatedApplicationBuildPack() { if ($this->application->build_pack !== 'nixpacks') { @@ -121,40 +114,6 @@ class General extends Component $this->labelsChanged = false; } } - public function instantSave() - { - // @TODO: find another way - if possible - $force_https = $this->application->settings->is_force_https_enabled; - $this->application->settings->is_static = $this->is_static; - if ($this->is_static) { - $this->application->ports_exposes = 80; - } else { - $this->application->ports_exposes = 3000; - } - $this->application->settings->is_git_submodules_enabled = $this->is_git_submodules_enabled; - $this->application->settings->is_git_lfs_enabled = $this->is_git_lfs_enabled; - $this->application->settings->is_debug_enabled = $this->is_debug_enabled; - $this->application->settings->is_preview_deployments_enabled = $this->is_preview_deployments_enabled; - $this->application->settings->is_auto_deploy_enabled = $this->is_auto_deploy_enabled; - $this->application->settings->is_force_https_enabled = $this->is_force_https_enabled; - $this->application->settings->is_log_drain_enabled = $this->is_log_drain_enabled; - if ($this->is_log_drain_enabled) { - if (!$this->application->destination->server->isLogDrainEnabled()) { - $this->application->settings->is_log_drain_enabled = $this->is_log_drain_enabled = false; - $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); - return; - } - } - $this->application->settings->save(); - $this->application->save(); - $this->application->refresh(); - $this->emit('success', 'Application settings updated!'); - $this->checkLabelUpdates(); - $this->isConfigurationChanged = $this->application->isConfigurationChanged(); - if ($force_https !== $this->is_force_https_enabled) { - $this->resetDefaultLabels(false); - } - } public function getWildcardDomain() { diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 32f92aefd..29f298918 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -873,6 +873,27 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ] ]; } + if ($this->application->settings->is_gpu_enabled) { + ray('asd'); + $docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'] = [ + [ + 'driver' => data_get($this->application, 'settings.gpu_driver', 'nvidia'), + 'capabilities' => ['gpu'], + 'options' => data_get($this->application, 'settings.gpu_options', []) + ] + ]; + if (data_get($this->application, 'settings.gpu_count')) { + $count = data_get($this->application, 'settings.gpu_count'); + ray($count); + if ($count === 'all') { + $docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'][0]['count'] = $count; + } else { + $docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'][0]['count'] = (int) $count; + } + } else if (data_get($this->application, 'settings.gpu_device_ids')) { + $docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'][0]['ids'] = data_get($this->application, 'settings.gpu_device_ids'); + } + } if ($this->application->isHealthcheckDisabled()) { data_forget($docker_compose, 'services.' . $this->container_name . '.healthcheck'); } @@ -891,6 +912,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted // 'dockerfile' => $this->workdir . $this->dockerfile_location, // ]; // } + ray($docker_compose); $this->docker_compose = Yaml::dump($docker_compose, 10); $this->docker_compose_base64 = base64_encode($this->docker_compose); $this->execute_remote_command([executeInDocker($this->deployment_uuid, "echo '{$this->docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml"), "hidden" => true]); diff --git a/app/View/Components/Forms/Textarea.php b/app/View/Components/Forms/Textarea.php index 69c618fb4..50ffe77f7 100644 --- a/app/View/Components/Forms/Textarea.php +++ b/app/View/Components/Forms/Textarea.php @@ -38,7 +38,7 @@ class Textarea extends Component if (is_null($this->id)) $this->id = new Cuid2(7); if (is_null($this->name)) $this->name = $this->id; - $this->label = Str::title($this->label); + // $this->label = Str::title($this->label); return view('components.forms.textarea'); } } diff --git a/database/migrations/2023_11_20_094628_add_gpu_settings.php b/database/migrations/2023_11_20_094628_add_gpu_settings.php new file mode 100644 index 000000000..9aeb255d9 --- /dev/null +++ b/database/migrations/2023_11_20_094628_add_gpu_settings.php @@ -0,0 +1,36 @@ +boolean('is_gpu_enabled')->default(false); + $table->string('gpu_driver')->default('nvidia'); + $table->string('gpu_count')->nullable(); + $table->string('gpu_device_ids')->nullable(); + $table->longText('gpu_options')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('application_settings', function (Blueprint $table) { + $table->dropColumn('is_gpu_enabled'); + $table->dropColumn('gpu_driver'); + $table->dropColumn('gpu_count'); + $table->dropColumn('gpu_device_ids'); + $table->dropColumn('gpu_options'); + }); + } +}; diff --git a/resources/views/components/forms/checkbox.blade.php b/resources/views/components/forms/checkbox.blade.php index de4abb87a..63c340d72 100644 --- a/resources/views/components/forms/checkbox.blade.php +++ b/resources/views/components/forms/checkbox.blade.php @@ -1,4 +1,4 @@ -
+
@if ($application->could_set_build_commands())
-
@endif @@ -112,29 +112,5 @@ Reset to Coolify Generated Labels
-

Advanced

-
- - - @if ($application->git_based()) - - - - - - @endif - - {{-- - - --}} -
diff --git a/resources/views/project/application/configuration.blade.php b/resources/views/project/application/configuration.blade.php index c8a85e82b..502f436db 100644 --- a/resources/views/project/application/configuration.blade.php +++ b/resources/views/project/application/configuration.blade.php @@ -5,6 +5,8 @@
General + Advanced @if ($application->build_pack !== 'static')
+
+ +