From 5f797ec0ae5efb04eee4108d1033452cd6f60403 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 10:28:18 +0100 Subject: [PATCH 01/15] Update version and release numbers --- app/Jobs/ApplicationDeploymentJob.php | 1 - config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 457cc04ad..93dad8e8a 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -488,7 +488,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } else { $this->application_deployment_queue->addLogEntry("Starting pull request (#{$this->pull_request_id}) deployment of {$this->customRepository}:{$this->application->git_branch}."); } - ray('asddf'); $this->prepare_builder_image(); $this->check_git_if_build_needed(); $this->clone_repository(); diff --git a/config/sentry.php b/config/sentry.php index 050405d5e..cb35fa610 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.203', + 'release' => '4.0.0-beta.204', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index c1ca7dc2b..0cbf5f9b7 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Wed, 31 Jan 2024 13:40:15 +0100 Subject: [PATCH 02/15] fix: not able to use other shared envs --- .../Project/Shared/EnvironmentVariable/Add.php | 7 +++++++ .../Project/Shared/EnvironmentVariable/All.php | 14 ++++++++++++++ .../Project/Shared/EnvironmentVariable/Show.php | 12 ++++++++++-- app/Models/EnvironmentVariable.php | 3 +++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php index 78ed3c780..0b6a3897d 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php @@ -32,6 +32,13 @@ class Add extends Component public function submit() { $this->validate(); + if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) { + $type = str($this->value)->after("{{")->before(".")->value; + if (!collect(['team', 'project', 'environment'])->contains($type)) { + $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); + return; + } + } $this->dispatch('saveKey', [ 'key' => $this->key, 'value' => $this->value, diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php index 77644519a..0a9e73461 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -71,12 +71,26 @@ class All extends Component continue; } $found->value = $variable; + if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) { + $type = str($found->value)->after("{{")->before(".")->value; + if (!collect(['team', 'project', 'environment'])->contains($type)) { + $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); + return; + } + } $found->save(); continue; } else { $environment = new EnvironmentVariable(); $environment->key = $key; $environment->value = $variable; + if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) { + $type = str($environment->value)->after("{{")->before(".")->value; + if (!collect(['team', 'project', 'environment'])->contains($type)) { + $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); + return; + } + } $environment->is_build_time = false; $environment->is_preview = $isPreview ? true : false; switch ($this->resource->type()) { diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index f8709afd8..b0c57e252 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -50,7 +50,8 @@ class Show extends Component $this->isLocked = true; } } - public function serialize() { + public function serialize() + { data_forget($this->env, 'real_value'); if ($this->env->getMorphClass() === 'App\Models\SharedEnvironmentVariable') { data_forget($this->env, 'is_build_time'); @@ -80,11 +81,18 @@ class Show extends Component } else { $this->validate(); } + if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) { + $type = str($this->env->value)->after("{{")->before(".")->value; + if (!collect(['team', 'project', 'environment'])->contains($type)) { + $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); + return; + } + } $this->serialize(); $this->env->save(); $this->dispatch('success', 'Environment variable updated successfully.'); $this->dispatch('refreshEnvs'); - } catch(\Exception $e) { + } catch (\Exception $e) { return handleError($e); } } diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index 4ecc6699c..b5ecffaba 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -100,6 +100,9 @@ class EnvironmentVariable extends Model $variable = Str::after($environment_variable, "{$type}."); $variable = Str::before($variable, '}}'); $variable = Str::of($variable)->trim()->value; + if (!collect(['team', 'project', 'environment'])->contains($type)) { + return $variable; + } if ($type === 'environment') { $id = $resource->environment->id; } else if ($type === 'project') { From f1e4395a83ee175ba0444c13fa7261e95a5ccf55 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 13:43:23 +0100 Subject: [PATCH 03/15] Refactor shared variable type validation --- app/Livewire/Project/Shared/EnvironmentVariable/Add.php | 2 +- app/Livewire/Project/Shared/EnvironmentVariable/All.php | 4 ++-- app/Livewire/Project/Shared/EnvironmentVariable/Show.php | 2 +- app/Models/EnvironmentVariable.php | 2 +- bootstrap/helpers/constants.php | 2 ++ 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php index 0b6a3897d..923f0d455 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php @@ -34,7 +34,7 @@ class Add extends Component $this->validate(); if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) { $type = str($this->value)->after("{{")->before(".")->value; - if (!collect(['team', 'project', 'environment'])->contains($type)) { + if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) { $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); return; } diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php index 0a9e73461..c30011a4a 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -73,7 +73,7 @@ class All extends Component $found->value = $variable; if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) { $type = str($found->value)->after("{{")->before(".")->value; - if (!collect(['team', 'project', 'environment'])->contains($type)) { + if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) { $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); return; } @@ -86,7 +86,7 @@ class All extends Component $environment->value = $variable; if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) { $type = str($environment->value)->after("{{")->before(".")->value; - if (!collect(['team', 'project', 'environment'])->contains($type)) { + if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) { $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); return; } diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index b0c57e252..1494707e7 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -83,7 +83,7 @@ class Show extends Component } if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) { $type = str($this->env->value)->after("{{")->before(".")->value; - if (!collect(['team', 'project', 'environment'])->contains($type)) { + if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) { $this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment."); return; } diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index b5ecffaba..fafa6f30c 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -100,7 +100,7 @@ class EnvironmentVariable extends Model $variable = Str::after($environment_variable, "{$type}."); $variable = Str::before($variable, '}}'); $variable = Str::of($variable)->trim()->value; - if (!collect(['team', 'project', 'environment'])->contains($type)) { + if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) { return $variable; } if ($type === 'environment') { diff --git a/bootstrap/helpers/constants.php b/bootstrap/helpers/constants.php index 380168005..9b16ebfed 100644 --- a/bootstrap/helpers/constants.php +++ b/bootstrap/helpers/constants.php @@ -34,3 +34,5 @@ const SUPPORTED_OS = [ 'centos fedora rhel ol rocky', 'sles opensuse-leap opensuse-tumbleweed' ]; + +const SHARED_VARIABLE_TYPES = ['team', 'project', 'environment']; From ce60a39dc58fbd5b59b880a7869f773aae1fe8b1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 13:45:58 +0100 Subject: [PATCH 04/15] Throw RuntimeException instead of Exception when no resource is found in ScheduledTaskJob --- app/Jobs/ScheduledTaskJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/ScheduledTaskJob.php b/app/Jobs/ScheduledTaskJob.php index 227807b41..4a38a005b 100644 --- a/app/Jobs/ScheduledTaskJob.php +++ b/app/Jobs/ScheduledTaskJob.php @@ -39,7 +39,7 @@ class ScheduledTaskJob implements ShouldQueue } else if ($application = $task->application()->first()) { $this->resource = $application; } else { - throw new \Exception('ScheduledTaskJob failed: No resource found.'); + throw new \RuntimeException('ScheduledTaskJob failed: No resource found.'); } $this->team = Team::find($task->team_id); } From 1cbfd03912cc208eb943e45c3ed249f743c23d0f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 13:46:40 +0100 Subject: [PATCH 05/15] fix: sentry fix --- app/Livewire/Project/Service/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.php index 32c174520..afbdd47bc 100644 --- a/app/Livewire/Project/Service/Configuration.php +++ b/app/Livewire/Project/Service/Configuration.php @@ -8,7 +8,7 @@ use Livewire\Component; class Configuration extends Component { - public Service $service; + public ?Service $service = null; public $applications; public $databases; public array $parameters; From 843cd90ee568cfb158fd28f079fb7a9402ef76d9 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 13:47:16 +0100 Subject: [PATCH 06/15] Update exception type in generate_github_installation_token function --- bootstrap/helpers/github.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/helpers/github.php b/bootstrap/helpers/github.php index 11cc5a3f8..16633168f 100644 --- a/bootstrap/helpers/github.php +++ b/bootstrap/helpers/github.php @@ -29,7 +29,7 @@ function generate_github_installation_token(GithubApp $source) 'Accept' => 'application/vnd.github.machine-man-preview+json' ])->post("{$source->api_url}/app/installations/{$source->installation_id}/access_tokens"); if ($token->failed()) { - throw new \Exception("Failed to get access token for " . $source->name . " with error: " . $token->json()['message']); + throw new RuntimeException("Failed to get access token for " . $source->name . " with error: " . $token->json()['message']); } return $token->json()['token']; } From f1a9e28d5a8e05d6ca03e3c7f4e51b6d03c09b18 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 14:18:51 +0100 Subject: [PATCH 07/15] fix: sentry --- resources/views/livewire/security/private-key/show.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/livewire/security/private-key/show.blade.php b/resources/views/livewire/security/private-key/show.blade.php index 43bcd95f6..79f14bdcc 100644 --- a/resources/views/livewire/security/private-key/show.blade.php +++ b/resources/views/livewire/security/private-key/show.blade.php @@ -12,7 +12,7 @@ Save - @if ($private_key->id > 0) + @if (data_get($private_key, 'id') > 0) Delete @@ -36,7 +36,7 @@ Hide - @if ($private_key->is_git_related) + @if (data_get($private_key, 'is_git_related'))
From 8ff7aeb78bcb2d73fa42808a594b0a85bf6fa498 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 Jan 2024 14:18:59 +0100 Subject: [PATCH 08/15] ui: new modal component --- app/Livewire/Project/DeleteEnvironment.php | 1 + app/Livewire/Project/DeleteProject.php | 1 + app/Models/Project.php | 7 ++- .../views/components/new-modal.blade.php | 56 +++++++++++++++++++ .../project/delete-environment.blade.php | 11 +--- .../livewire/project/delete-project.blade.php | 13 +---- .../views/livewire/project/edit.blade.php | 4 +- .../project/environment-edit.blade.php | 1 + .../livewire/project/resource/index.blade.php | 2 +- .../views/livewire/project/show.blade.php | 4 +- 10 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 resources/views/components/new-modal.blade.php diff --git a/app/Livewire/Project/DeleteEnvironment.php b/app/Livewire/Project/DeleteEnvironment.php index 0f2b59c93..c64ebd4b2 100644 --- a/app/Livewire/Project/DeleteEnvironment.php +++ b/app/Livewire/Project/DeleteEnvironment.php @@ -9,6 +9,7 @@ class DeleteEnvironment extends Component { public array $parameters; public int $environment_id; + public bool $disabled = false; public function mount() { diff --git a/app/Livewire/Project/DeleteProject.php b/app/Livewire/Project/DeleteProject.php index 7ac4aa281..543b45784 100644 --- a/app/Livewire/Project/DeleteProject.php +++ b/app/Livewire/Project/DeleteProject.php @@ -9,6 +9,7 @@ class DeleteProject extends Component { public array $parameters; public int $project_id; + public bool $disabled = false; public function mount() { diff --git a/app/Models/Project.php b/app/Models/Project.php index d5f1bdd54..b9afc7426 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -64,10 +64,13 @@ class Project extends BaseModel } public function mysqls() { - return $this->hasMany(StandaloneMysql::class, Environment::class); + return $this->hasManyThrough(StandaloneMysql::class, Environment::class); } public function mariadbs() { - return $this->hasMany(StandaloneMariadb::class, Environment::class); + return $this->hasManyThrough(StandaloneMariadb::class, Environment::class); + } + public function resource_count() { + return $this->applications()->count() + $this->postgresqls()->count() + $this->redis()->count() + $this->mongodbs()->count() + $this->mysqls()->count() + $this->mariadbs()->count(); } } diff --git a/resources/views/components/new-modal.blade.php b/resources/views/components/new-modal.blade.php new file mode 100644 index 000000000..b542d77ac --- /dev/null +++ b/resources/views/components/new-modal.blade.php @@ -0,0 +1,56 @@ +@props([ + 'title' => 'Are you sure?', + 'buttonTitle' => 'Open Modal', + 'isErrorButton' => false, + 'disabled' => false, + 'action' => 'delete', +]) +
+ @if ($disabled) + {{ $buttonTitle }} + @elseif ($isErrorButton) + {{ $buttonTitle }} + @else + {{ $buttonTitle }} + @endif + +
diff --git a/resources/views/livewire/project/delete-environment.blade.php b/resources/views/livewire/project/delete-environment.blade.php index 01e35db2d..6173721a3 100644 --- a/resources/views/livewire/project/delete-environment.blade.php +++ b/resources/views/livewire/project/delete-environment.blade.php @@ -1,8 +1,3 @@ -
- - -

This environment will be deleted. It is not reversible.
Please think again.

-
-
- Delete Environment -
+ + This environment will be deleted. It is not reversible.
Please think again. +
diff --git a/resources/views/livewire/project/delete-project.blade.php b/resources/views/livewire/project/delete-project.blade.php index 59c2b45bd..095c139f4 100644 --- a/resources/views/livewire/project/delete-project.blade.php +++ b/resources/views/livewire/project/delete-project.blade.php @@ -1,10 +1,3 @@ -
- - -

This project will be deleted. It is not reversible.
Please think again.

-
-
- - Delete Project - -
+ + This project will be deleted. It is not reversible.
Please think again. +
diff --git a/resources/views/livewire/project/edit.blade.php b/resources/views/livewire/project/edit.blade.php index 0328b4ab5..164ba34cd 100644 --- a/resources/views/livewire/project/edit.blade.php +++ b/resources/views/livewire/project/edit.blade.php @@ -5,6 +5,7 @@

General

Save +
@@ -23,7 +24,8 @@ Add
-
You can use these variables anywhere with @{{project.VARIABLENAME}}You can use these variables anywhere with @{{ project.VARIABLENAME }}
diff --git a/resources/views/livewire/project/environment-edit.blade.php b/resources/views/livewire/project/environment-edit.blade.php index a643f197d..758d737d3 100644 --- a/resources/views/livewire/project/environment-edit.blade.php +++ b/resources/views/livewire/project/environment-edit.blade.php @@ -3,6 +3,7 @@

Environment: {{ data_get($environment, 'name') }}

Save +