diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index bf24024e6..2591482c8 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -24,12 +24,12 @@ class General extends Component public string|null $global_wildcard_domain = null; public bool $is_static; - public bool $is_git_submodules_allowed; - public bool $is_git_lfs_allowed; - public bool $is_debug; - public bool $is_previews; - public bool $is_auto_deploy; - public bool $is_force_https; + 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; protected $rules = [ 'application.name' => 'required|min:6', @@ -51,12 +51,12 @@ public function instantSave() { // @TODO: find another way - if possible $this->application->settings->is_static = $this->is_static; - $this->application->settings->is_git_submodules_allowed = $this->is_git_submodules_allowed; - $this->application->settings->is_git_lfs_allowed = $this->is_git_lfs_allowed; - $this->application->settings->is_debug = $this->is_debug; - $this->application->settings->is_previews = $this->is_previews; - $this->application->settings->is_auto_deploy = $this->is_auto_deploy; - $this->application->settings->is_force_https = $this->is_force_https; + $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->save(); $this->application->refresh(); $this->emit('saved', 'Application settings updated!'); @@ -72,12 +72,12 @@ protected function checkWildCardDomain() public function mount() { $this->is_static = $this->application->settings->is_static; - $this->is_git_submodules_allowed = $this->application->settings->is_git_submodules_allowed; - $this->is_git_lfs_allowed = $this->application->settings->is_git_lfs_allowed; - $this->is_debug = $this->application->settings->is_debug; - $this->is_previews = $this->application->settings->is_previews; - $this->is_auto_deploy = $this->application->settings->is_auto_deploy; - $this->is_force_https = $this->application->settings->is_force_https; + $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->checkWildCardDomain(); } public function generateGlobalRandomDomain() diff --git a/app/Http/Livewire/Project/Application/Previews.php b/app/Http/Livewire/Project/Application/Previews.php index 86024aec7..48b6f74fd 100644 --- a/app/Http/Livewire/Project/Application/Previews.php +++ b/app/Http/Livewire/Project/Application/Previews.php @@ -75,10 +75,7 @@ public function stop(int $pull_request_id) ray('Stopping container: ' . $container_name); instant_remote_process(["docker rm -f $container_name"], $this->application->destination->server, throwError: false); - $found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first(); - if ($found) { - $found->delete(); - } + ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->delete(); $this->application->refresh(); } catch (\Throwable $th) { return general_error_handler($th, $this); diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 1d4a077c2..934ec70e9 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -501,7 +501,7 @@ private function set_labels_for_applications() // Set labels for http (redirect to https) $labels[] = "traefik.http.routers.{$http_label}.rule=Host(`{$host}`) && PathPrefix(`{$path}`)"; $labels[] = "traefik.http.routers.{$http_label}.entryPoints=http"; - if ($this->application->settings->is_force_https) { + if ($this->application->settings->is_force_https_enabled) { $labels[] = "traefik.http.routers.{$http_label}.middlewares=redirect-to-https"; } } else { @@ -539,7 +539,7 @@ private function execute_now( 'command' => $commandText, ]); $this->activity->save(); - if ($isDebuggable && !$this->application->settings->is_debug) { + if ($isDebuggable && !$this->application->settings->is_debug_enabled) { $hideFromOutput = true; } $remote_process = resolve(RunRemoteProcess::class, [ @@ -565,10 +565,10 @@ private function set_git_import_settings($git_clone_command) if ($this->application->git_commit_sha !== 'HEAD') { $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git -c advice.detachedHead=false checkout {$this->application->git_commit_sha} >/dev/null 2>&1"; } - if ($this->application->settings->is_git_submodules_allowed) { + if ($this->application->settings->is_git_submodules_enabled) { $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git submodule update --init --recursive"; } - if ($this->application->settings->is_git_lfs_allowed) { + if ($this->application->settings->is_git_lfs_enabled) { $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git lfs pull"; } return $git_clone_command; diff --git a/app/Models/Application.php b/app/Models/Application.php index 4f19481c2..e3dbe0706 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -154,7 +154,14 @@ public function get_deployment(string $deployment_uuid) } public function isDeployable(): bool { - if ($this->settings->is_auto_deploy) { + if ($this->settings->is_auto_deploy_enabled) { + return true; + } + return false; + } + public function isPRDeployable(): bool + { + if ($this->settings->is_preview_deployments_enabled) { return true; } return false; diff --git a/app/Models/ApplicationDeploymentQueue.php b/app/Models/ApplicationDeploymentQueue.php index cee3293b0..474c38cc8 100644 --- a/app/Models/ApplicationDeploymentQueue.php +++ b/app/Models/ApplicationDeploymentQueue.php @@ -15,5 +15,6 @@ class ApplicationDeploymentQueue extends Model 'force_rebuild', 'commit', 'status', + 'is_webhook', ]; } diff --git a/app/Models/ApplicationSetting.php b/app/Models/ApplicationSetting.php index c0beabe7c..3bdd6a7cd 100644 --- a/app/Models/ApplicationSetting.php +++ b/app/Models/ApplicationSetting.php @@ -7,10 +7,24 @@ class ApplicationSetting extends Model { + protected $cast = [ + 'is_static' => 'boolean', + 'is_auto_deploy_enabled' => 'boolean', + 'is_force_https_enabled' => 'boolean', + 'is_debug_enabled' => 'boolean', + 'is_preview_deployments_enabled' => 'boolean', + 'is_git_submodules_enabled' => 'boolean', + 'is_git_lfs_enabled' => 'boolean', + ]; protected $fillable = [ 'application_id', - 'is_git_submodules_allowed', - 'is_git_lfs_allowed', + 'is_static', + 'is_auto_deploy_enabled', + 'is_force_https_enabled', + 'is_debug_enabled', + 'is_preview_deployments_enabled', + 'is_git_submodules_enabled', + 'is_git_lfs_enabled', ]; public function isStatic(): Attribute { diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index e72c7c980..9914bc9a9 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -3,7 +3,7 @@ use App\Jobs\ApplicationDeploymentJob; use App\Models\ApplicationDeploymentQueue; -function queue_application_deployment(int $application_id, string $deployment_uuid, int|null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false) +function queue_application_deployment(int $application_id, string $deployment_uuid, int|null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false) { ray('Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild); $deployment = ApplicationDeploymentQueue::create([ @@ -11,6 +11,7 @@ function queue_application_deployment(int $application_id, string $deployment_uu 'deployment_uuid' => $deployment_uuid, 'pull_request_id' => $pull_request_id, 'force_rebuild' => $force_rebuild, + 'is_webhook' => $is_webhook, 'commit' => $commit, ]); $queued_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'queued')->get()->sortByDesc('created_at'); diff --git a/database/migrations/2023_03_27_081717_create_application_settings_table.php b/database/migrations/2023_03_27_081717_create_application_settings_table.php index 0e7e386a2..e13f7f366 100644 --- a/database/migrations/2023_03_27_081717_create_application_settings_table.php +++ b/database/migrations/2023_03_27_081717_create_application_settings_table.php @@ -14,13 +14,13 @@ public function up(): void Schema::create('application_settings', function (Blueprint $table) { $table->id(); $table->boolean('is_static')->default(false); - $table->boolean('is_git_submodules_allowed')->default(true); - $table->boolean('is_git_lfs_allowed')->default(true); - $table->boolean('is_auto_deploy')->default(true); - $table->boolean('is_force_https')->default(true); + $table->boolean('is_git_submodules_enabled')->default(true); + $table->boolean('is_git_lfs_enabled')->default(true); + $table->boolean('is_auto_deploy_enabled')->default(true); + $table->boolean('is_force_https_enabled')->default(true); + $table->boolean('is_debug_enabled')->default(false); + $table->boolean('is_preview_deployments_enabled')->default(false); // $table->boolean('is_dual_cert')->default(false); - $table->boolean('is_debug')->default(false); - $table->boolean('is_previews')->default(false); // $table->boolean('is_custom_ssl')->default(false); // $table->boolean('is_http2')->default(false); $table->foreignId('application_id'); diff --git a/database/migrations/2023_05_24_083426_create_application_deployment_queues_table.php b/database/migrations/2023_05_24_083426_create_application_deployment_queues_table.php index bf8bfcc35..9573b9735 100644 --- a/database/migrations/2023_05_24_083426_create_application_deployment_queues_table.php +++ b/database/migrations/2023_05_24_083426_create_application_deployment_queues_table.php @@ -19,6 +19,7 @@ public function up(): void $table->boolean('force_rebuild')->default(false); $table->string('commit')->default('HEAD'); $table->string('status')->default('queued'); + $table->boolean('is_webhook')->default(false); $table->timestamps(); }); } diff --git a/database/seeders/ApplicationSettingsSeeder.php b/database/seeders/ApplicationSettingsSeeder.php index 1b6068ad5..3ab5bd967 100644 --- a/database/seeders/ApplicationSettingsSeeder.php +++ b/database/seeders/ApplicationSettingsSeeder.php @@ -18,7 +18,7 @@ class ApplicationSettingsSeeder extends Seeder public function run(): void { $application_1 = Application::find(1)->load(['settings']); - $application_1->settings->is_debug = false; + $application_1->settings->is_debug_enabled = false; $application_1->settings->save(); } } diff --git a/resources/views/livewire/project/application/deployments.blade.php b/resources/views/livewire/project/application/deployments.blade.php index e8fc089ca..bcb74b296 100644 --- a/resources/views/livewire/project/application/deployments.blade.php +++ b/resources/views/livewire/project/application/deployments.blade.php @@ -20,7 +20,20 @@ class="hover:no-underline">