From a4c164a57efde1529ee7faccedc3a52161d28c01 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 14 Mar 2024 21:19:37 +0100 Subject: [PATCH 01/10] fix: duplicate dockerfile --- app/Jobs/ApplicationDeploymentJob.php | 4 ++-- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 129df7814..f96a68582 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1128,9 +1128,9 @@ private function generate_compose_file() $this->custom_healthcheck_found = false; if ($this->application->build_pack === 'dockerfile' || $this->application->dockerfile) { $this->execute_remote_command([ - executeInDocker($this->deployment_uuid, "cat {$this->workdir}{$this->dockerfile_location}"), "hidden" => true, "save" => 'dockerfile', "ignore_errors" => true + executeInDocker($this->deployment_uuid, "cat {$this->workdir}{$this->dockerfile_location}"), "hidden" => true, "save" => 'dockerfile_from_repo', "ignore_errors" => true ]); - $dockerfile = collect(Str::of($this->saved_outputs->get('dockerfile'))->trim()->explode("\n")); + $dockerfile = collect(Str::of($this->saved_outputs->get('dockerfile_from_repo'))->trim()->explode("\n")); if (str($dockerfile)->contains('HEALTHCHECK')) { $this->custom_healthcheck_found = true; } diff --git a/config/sentry.php b/config/sentry.php index 150b055c3..1fe45fcc9 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // 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.238', + 'release' => '4.0.0-beta.239', // 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 6a881ff74..cf8c3ba8b 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Thu, 14 Mar 2024 23:00:06 +0100 Subject: [PATCH 02/10] fix: $ in env variable feat: multiline envs --- app/Jobs/ApplicationDeploymentJob.php | 17 ++++++++--- .../Shared/EnvironmentVariable/Show.php | 2 ++ bootstrap/helpers/docker.php | 10 ++++++- config/sentry.php | 2 +- config/version.php | 2 +- .../2024_03_14_214402_add_multiline_envs.php | 28 +++++++++++++++++++ .../environment-variable/show.blade.php | 11 ++++++-- templates/compose/uptime-kuma.yaml | 2 +- templates/service-templates.json | 2 +- versions.json | 2 +- 10 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 database/migrations/2024_03_14_214402_add_multiline_envs.php diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index f96a68582..ca0efd2c3 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1359,23 +1359,31 @@ private function generate_environment_variables($ports) $environment_variables = collect(); if ($this->pull_request_id === 0) { foreach ($this->application->runtime_environment_variables as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } foreach ($this->application->nixpacks_environment_variables as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } } else { foreach ($this->application->runtime_environment_variables_preview as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } foreach ($this->application->nixpacks_environment_variables_preview as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } } // Add PORT if not exists, use the first port as default if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) { $environment_variables->push("PORT={$ports[0]}"); } + // Add HOST if not exists + if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('HOST'))->isEmpty()) { + $environment_variables->push("HOST=0.0.0.0"); + } if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('SOURCE_COMMIT'))->isEmpty()) { if (!is_null($this->commit)) { $environment_variables->push("SOURCE_COMMIT={$this->commit}"); @@ -1383,6 +1391,7 @@ private function generate_environment_variables($ports) $environment_variables->push("SOURCE_COMMIT=unknown"); } } + ray($environment_variables->all()); return $environment_variables->all(); } diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index 9252c44f8..7903e8e51 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -21,6 +21,7 @@ class Show extends Component 'env.key' => 'required|string', 'env.value' => 'nullable', 'env.is_build_time' => 'required|boolean', + 'env.is_multiline' => 'required|boolean', 'env.is_shown_once' => 'required|boolean', 'env.real_value' => 'nullable', ]; @@ -28,6 +29,7 @@ class Show extends Component 'env.key' => 'Key', 'env.value' => 'Value', 'env.is_build_time' => 'Build Time', + 'env.is_multiline' => 'Multiline', 'env.is_shown_once' => 'Shown Once', ]; diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 898789adf..aed77a7bb 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -557,7 +557,8 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null return $compose_options->toArray(); } -function validateComposeFile(string $compose, int $server_id): string|Throwable { +function validateComposeFile(string $compose, int $server_id): string|Throwable +{ return 'OK'; try { $uuid = Str::random(10); @@ -578,3 +579,10 @@ function validateComposeFile(string $compose, int $server_id): string|Throwable ], $server); } } + +function escapeEnvVariables($value) +{ + $search = array("\\", "\r", "\t", "\x0", '"', "'", "$"); + $replace = array("\\\\", "\\r", "\\t", "\\0", '\"', "\'", "$$"); + return str_replace($search, $replace, $value); +} diff --git a/config/sentry.php b/config/sentry.php index 1fe45fcc9..5d46ba7f3 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // 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.239', + 'release' => '4.0.0-beta.240', // 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 cf8c3ba8b..c7e1008fc 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ boolean('is_multiline')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('environment_variables', function (Blueprint $table) { + $table->dropColumn('is_multiline'); + }); + } +}; diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.php index 5b2c95373..d64490605 100644 --- a/resources/views/livewire/project/shared/environment-variable/show.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php @@ -20,11 +20,18 @@ class="flex flex-col gap-2 p-4 m-2 border lg:items-center border-coolgray-300 lg @endif @else - - + @if ($env->is_multiline) + + + @else + + + @endif @if ($env->is_shared) @endif + @if ($type !== 'service' && !$isSharedVariable) @endif diff --git a/templates/compose/uptime-kuma.yaml b/templates/compose/uptime-kuma.yaml index d5c07684d..cd20d60cb 100644 --- a/templates/compose/uptime-kuma.yaml +++ b/templates/compose/uptime-kuma.yaml @@ -8,7 +8,7 @@ services: uptime-kuma: image: louislam/uptime-kuma:1 environment: - - SERVICE_FQDN_3001 + - SERVICE_FQDN_UPTIME-KUMA_3001 volumes: - uptime-kuma:/app/data healthcheck: diff --git a/templates/service-templates.json b/templates/service-templates.json index c7a4d91db..76bdf2bd8 100644 --- a/templates/service-templates.json +++ b/templates/service-templates.json @@ -772,7 +772,7 @@ "uptime-kuma": { "documentation": "https:\/\/github.com\/louislam\/uptime-kuma?tab=readme-ov-file", "slogan": "Uptime Kuma is a monitoring tool for tracking the status and performance of your applications in real-time.", - "compose": "c2VydmljZXM6CiAgdXB0aW1lLWt1bWE6CiAgICBpbWFnZTogJ2xvdWlzbGFtL3VwdGltZS1rdW1hOjEnCiAgICBlbnZpcm9ubWVudDoKICAgICAgLSBTRVJWSUNFX0ZRRE5fMzAwMQogICAgdm9sdW1lczoKICAgICAgLSAndXB0aW1lLWt1bWE6L2FwcC9kYXRhJwogICAgaGVhbHRoY2hlY2s6CiAgICAgIHRlc3Q6CiAgICAgICAgLSBDTUQtU0hFTEwKICAgICAgICAtIGV4dHJhL2hlYWx0aGNoZWNrCiAgICAgIGludGVydmFsOiAycwogICAgICB0aW1lb3V0OiAxMHMKICAgICAgcmV0cmllczogMTUK", + "compose": "c2VydmljZXM6CiAgdXB0aW1lLWt1bWE6CiAgICBpbWFnZTogJ2xvdWlzbGFtL3VwdGltZS1rdW1hOjEnCiAgICBlbnZpcm9ubWVudDoKICAgICAgLSBTRVJWSUNFX0ZRRE5fVVBUSU1FLUtVTUFfMzAwMQogICAgdm9sdW1lczoKICAgICAgLSAndXB0aW1lLWt1bWE6L2FwcC9kYXRhJwogICAgaGVhbHRoY2hlY2s6CiAgICAgIHRlc3Q6CiAgICAgICAgLSBDTUQtU0hFTEwKICAgICAgICAtIGV4dHJhL2hlYWx0aGNoZWNrCiAgICAgIGludGVydmFsOiAycwogICAgICB0aW1lb3V0OiAxMHMKICAgICAgcmV0cmllczogMTUK", "tags": [ "monitoring", "status", diff --git a/versions.json b/versions.json index 8f30ba88c..ba197ca84 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.239" + "version": "4.0.0-beta.240" } } } From 73f889ac9fd24238a3cf26af1b499179ba7d8c62 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 15 Mar 2024 07:11:05 +0100 Subject: [PATCH 03/10] Fix realtime container name and env var --- templates/compose/supabase.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/compose/supabase.yaml b/templates/compose/supabase.yaml index 39d9f5f24..0fd2faf90 100644 --- a/templates/compose/supabase.yaml +++ b/templates/compose/supabase.yaml @@ -942,6 +942,7 @@ services: - GOTRUE_SMS_AUTOCONFIRM=${ENABLE_PHONE_AUTOCONFIRM:-true} supabase-realtime: # This container name looks inconsistent but is correct because realtime constructs tenant id by parsing the subdomain + container_name: realtime-dev.supabase-realtime image: supabase/realtime:v2.25.50 depends_on: supabase-db: @@ -961,7 +962,7 @@ services: - DB_USER=supabase_admin - DB_PASSWORD=${SERVICE_PASSWORD_POSTGRES} - DB_NAME=${POSTGRES_DB:-supabase} - - DB_AFTER_CONNECT_QUERY='SET search_path TO _realtime' + - DB_AFTER_CONNECT_QUERY=SET search_path TO _realtime - DB_ENC_KEY=supabaserealtime - API_JWT_SECRET=${SERVICE_PASSWORD_JWT} - FLY_ALLOC_ID=fly123 From 1894573c2fd4aa6ba4e78faeecff7a2c708e9343 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 15 Mar 2024 09:19:30 +0100 Subject: [PATCH 04/10] Change service name directly --- templates/compose/supabase.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/compose/supabase.yaml b/templates/compose/supabase.yaml index 0fd2faf90..0b2d868e2 100644 --- a/templates/compose/supabase.yaml +++ b/templates/compose/supabase.yaml @@ -940,9 +940,10 @@ services: - GOTRUE_EXTERNAL_PHONE_ENABLED=${ENABLE_PHONE_SIGNUP:-true} - GOTRUE_SMS_AUTOCONFIRM=${ENABLE_PHONE_AUTOCONFIRM:-true} - supabase-realtime: + realtime-dev.supabase-realtime: # This container name looks inconsistent but is correct because realtime constructs tenant id by parsing the subdomain - container_name: realtime-dev.supabase-realtime + # Name of service has to be changed as coolify is generating container names automatically + # container_name: realtime-dev.supabase-realtime image: supabase/realtime:v2.25.50 depends_on: supabase-db: From 350e32326fa79075dad1677281450cc88f87960f Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 15 Mar 2024 13:25:49 +0100 Subject: [PATCH 05/10] Fix app name of realtime for logging --- templates/compose/supabase.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/compose/supabase.yaml b/templates/compose/supabase.yaml index 0b2d868e2..af61c35db 100644 --- a/templates/compose/supabase.yaml +++ b/templates/compose/supabase.yaml @@ -663,7 +663,7 @@ services: kong: 'starts_with(string!(.appname), "supabase-kong")' auth: 'starts_with(string!(.appname), "supabase-auth")' rest: 'starts_with(string!(.appname), "supabase-rest")' - realtime: 'starts_with(string!(.appname), "supabase-realtime")' + realtime: 'starts_with(string!(.appname), "realtime-dev.supabase-realtime")' storage: 'starts_with(string!(.appname), "supabase-storage")' functions: 'starts_with(string!(.appname), "supabase-functions")' db: 'starts_with(string!(.appname), "supabase-db")' From 657c7d8cff3775359bbe26fb9774d3887b0ce0c8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 15 Mar 2024 20:40:50 +0100 Subject: [PATCH 06/10] Refactor form components Update Input and Textarea components to use nullable type declarations and remove unused imports. --- app/View/Components/Forms/Input.php | 22 +++++++++++----------- app/View/Components/Forms/Textarea.php | 26 +++++++++++++------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/View/Components/Forms/Input.php b/app/View/Components/Forms/Input.php index 09cee0338..93598cea5 100644 --- a/app/View/Components/Forms/Input.php +++ b/app/View/Components/Forms/Input.php @@ -10,17 +10,17 @@ class Input extends Component { public function __construct( - public string|null $id = null, - public string|null $name = null, - public string|null $type = 'text', - public string|null $value = null, - public string|null $label = null, - public bool $required = false, - public bool $disabled = false, - public bool $readonly = false, - public string|null $helper = null, - public bool $allowToPeak = true, - public string $defaultClass = "input input-sm bg-coolgray-100 rounded text-white w-full disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" + public ?string $id = null, + public ?string $name = null, + public ?string $type = 'text', + public ?string $value = null, + public ?string $label = null, + public bool $required = false, + public bool $disabled = false, + public bool $readonly = false, + public ?string $helper = null, + public bool $allowToPeak = true, + public string $defaultClass = "input input-sm bg-coolgray-100 rounded text-white w-full disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" ) { } diff --git a/app/View/Components/Forms/Textarea.php b/app/View/Components/Forms/Textarea.php index 50ffe77f7..aa8d874ad 100644 --- a/app/View/Components/Forms/Textarea.php +++ b/app/View/Components/Forms/Textarea.php @@ -4,7 +4,6 @@ use Closure; use Illuminate\Contracts\View\View; -use Illuminate\Support\Str; use Illuminate\View\Component; use Visus\Cuid2\Cuid2; @@ -14,18 +13,19 @@ class Textarea extends Component * Create a new component instance. */ public function __construct( - public string|null $id = null, - public string|null $name = null, - public string|null $type = 'text', - public string|null $value = null, - public string|null $label = null, - public string|null $placeholder = null, - public bool $required = false, - public bool $disabled = false, - public bool $readonly = false, - public string|null $helper = null, - public bool $realtimeValidation = false, - public string $defaultClass = "textarea leading-normal bg-coolgray-100 rounded text-white scrollbar disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" + public ?string $id = null, + public ?string $name = null, + public ?string $type = 'text', + public ?string $value = null, + public ?string $label = null, + public ?string $placeholder = null, + public bool $required = false, + public bool $disabled = false, + public bool $readonly = false, + public ?string $helper = null, + public bool $realtimeValidation = false, + // public bool $allowToPeak = true, + public string $defaultClass = "textarea leading-normal bg-coolgray-100 rounded text-white scrollbar disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" ) { // } From 3ea3674407ee8b57840b93798f3be143443db9ba Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 15 Mar 2024 22:02:37 +0100 Subject: [PATCH 07/10] fix: multiline env variables --- app/Livewire/Project/Edit.php | 5 ++ app/Livewire/Project/EnvironmentEdit.php | 5 ++ .../Shared/EnvironmentVariable/Add.php | 5 ++ .../Shared/EnvironmentVariable/All.php | 11 ++++- app/Livewire/TeamSharedVariablesIndex.php | 5 ++ app/Models/EnvironmentVariable.php | 18 +++++-- app/View/Components/Forms/Textarea.php | 5 +- .../2024_03_14_214402_add_multiline_envs.php | 6 +++ .../views/components/forms/input.blade.php | 6 +-- .../views/components/forms/textarea.blade.php | 47 ++++++++++++++++--- resources/views/layouts/base.blade.php | 4 +- .../shared/environment-variable/add.blade.php | 6 ++- .../environment-variable/show.blade.php | 8 ++-- 13 files changed, 106 insertions(+), 25 deletions(-) diff --git a/app/Livewire/Project/Edit.php b/app/Livewire/Project/Edit.php index b2cda7a47..a80b1af76 100644 --- a/app/Livewire/Project/Edit.php +++ b/app/Livewire/Project/Edit.php @@ -17,9 +17,14 @@ class Edit extends Component public function saveKey($data) { try { + $found = $this->project->environment_variables()->where('key', $data['key'])->first(); + if ($found) { + throw new \Exception('Variable already exists.'); + } $this->project->environment_variables()->create([ 'key' => $data['key'], 'value' => $data['value'], + 'is_multiline' => $data['is_multiline'], 'type' => 'project', 'team_id' => currentTeam()->id, ]); diff --git a/app/Livewire/Project/EnvironmentEdit.php b/app/Livewire/Project/EnvironmentEdit.php index 276aa58df..c5e4ccf11 100644 --- a/app/Livewire/Project/EnvironmentEdit.php +++ b/app/Livewire/Project/EnvironmentEdit.php @@ -21,9 +21,14 @@ class EnvironmentEdit extends Component public function saveKey($data) { try { + $found = $this->environment->environment_variables()->where('key', $data['key'])->first(); + if ($found) { + throw new \Exception('Variable already exists.'); + } $this->environment->environment_variables()->create([ 'key' => $data['key'], 'value' => $data['value'], + 'is_multiline' => $data['is_multiline'], 'type' => 'environment', 'team_id' => currentTeam()->id, ]); diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php index 923f0d455..c04242963 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php @@ -11,17 +11,20 @@ class Add extends Component public string $key; public ?string $value = null; public bool $is_build_time = false; + public bool $is_multiline = false; protected $listeners = ['clearAddEnv' => 'clear']; protected $rules = [ 'key' => 'required|string', 'value' => 'nullable', 'is_build_time' => 'required|boolean', + 'is_multiline' => 'required|boolean', ]; protected $validationAttributes = [ 'key' => 'key', 'value' => 'value', 'is_build_time' => 'build', + 'is_multiline' => 'multiline', ]; public function mount() @@ -43,6 +46,7 @@ public function submit() 'key' => $this->key, 'value' => $this->value, 'is_build_time' => $this->is_build_time, + 'is_multiline' => $this->is_multiline, 'is_preview' => $this->is_preview, ]); $this->clear(); @@ -53,5 +57,6 @@ public function clear() $this->key = ''; $this->value = ''; $this->is_build_time = false; + $this->is_multiline = false; } } diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php index 3a304d3e9..53dd0ffe3 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -11,7 +11,7 @@ class All extends Component { public $resource; public bool $showPreview = false; - public string|null $modalId = null; + public ?string $modalId = null; public ?string $variables = null; public ?string $variablesPreview = null; public string $view = 'normal'; @@ -34,6 +34,9 @@ public function getDevView() if ($item->is_shown_once) { return "$item->key=(locked secret)"; } + if ($item->is_multiline) { + return "$item->key=(multiline, edit in normal view)"; + } return "$item->key=$item->value"; })->sort()->join(' '); @@ -42,6 +45,9 @@ public function getDevView() if ($item->is_shown_once) { return "$item->key=(locked secret)"; } + if ($item->is_multiline) { + return "$item->key=(multiline, edit in normal view)"; + } return "$item->key=$item->value"; })->sort()->join(' '); @@ -67,7 +73,7 @@ public function saveVariables($isPreview) $found = $this->resource->environment_variables()->where('key', $key)->first(); } if ($found) { - if ($found->is_shown_once) { + if ($found->is_shown_once || $found->is_multiline) { continue; } $found->value = $variable; @@ -144,6 +150,7 @@ public function submit($data) $environment->key = $data['key']; $environment->value = $data['value']; $environment->is_build_time = $data['is_build_time']; + $environment->is_multiline = $data['is_multiline']; $environment->is_preview = $data['is_preview']; switch ($this->resource->type()) { diff --git a/app/Livewire/TeamSharedVariablesIndex.php b/app/Livewire/TeamSharedVariablesIndex.php index d2776e8b2..dbb64ab65 100644 --- a/app/Livewire/TeamSharedVariablesIndex.php +++ b/app/Livewire/TeamSharedVariablesIndex.php @@ -13,9 +13,14 @@ class TeamSharedVariablesIndex extends Component public function saveKey($data) { try { + $found = $this->team->environment_variables()->where('key', $data['key'])->first(); + if ($found) { + throw new \Exception('Variable already exists.'); + } $this->team->environment_variables()->create([ 'key' => $data['key'], 'value' => $data['value'], + 'is_multiline' => $data['is_multiline'], 'type' => 'team', 'team_id' => currentTeam()->id, ]); diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index a3611a0c6..41fe40c58 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -49,7 +49,7 @@ protected function value(): Attribute set: fn (?string $value = null) => $this->set_environment_variables($value), ); } - public function realValue(): Attribute + public function resource() { $resource = null; if ($this->application_id) { @@ -71,9 +71,19 @@ public function realValue(): Attribute } } } + return $resource; + } + public function realValue(): Attribute + { + $resource = $this->resource(); return Attribute::make( get: function () use ($resource) { - return $this->get_real_environment_variables($this->value, $resource); + $env = $this->get_real_environment_variables($this->value, $resource); + return data_get($env, 'value', $env); + if (is_string($env)) { + return $env; + } + return $env->value; } ); } @@ -89,7 +99,7 @@ protected function isShared(): Attribute } ); } - private function get_real_environment_variables(?string $environment_variable = null, $resource = null): string|null + private function get_real_environment_variables(?string $environment_variable = null, $resource = null) { if (!$environment_variable || !$resource) { return null; @@ -112,7 +122,7 @@ private function get_real_environment_variables(?string $environment_variable = } $environment_variable_found = SharedEnvironmentVariable::where("type", $type)->where('key', $variable)->where('team_id', $resource->team()->id)->where("{$type}_id", $id)->first(); if ($environment_variable_found) { - return $environment_variable_found->value; + return $environment_variable_found; } } return $environment_variable; diff --git a/app/View/Components/Forms/Textarea.php b/app/View/Components/Forms/Textarea.php index aa8d874ad..8c50af533 100644 --- a/app/View/Components/Forms/Textarea.php +++ b/app/View/Components/Forms/Textarea.php @@ -24,8 +24,9 @@ public function __construct( public bool $readonly = false, public ?string $helper = null, public bool $realtimeValidation = false, - // public bool $allowToPeak = true, - public string $defaultClass = "textarea leading-normal bg-coolgray-100 rounded text-white scrollbar disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" + public bool $allowToPeak = true, + public string $defaultClass = "textarea leading-normal bg-coolgray-100 rounded text-white w-full scrollbar disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50", + public string $defaultClassInput = "input input-sm bg-coolgray-100 rounded text-white w-full disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" ) { // } diff --git a/database/migrations/2024_03_14_214402_add_multiline_envs.php b/database/migrations/2024_03_14_214402_add_multiline_envs.php index c8d809927..b3e869bc3 100644 --- a/database/migrations/2024_03_14_214402_add_multiline_envs.php +++ b/database/migrations/2024_03_14_214402_add_multiline_envs.php @@ -14,6 +14,9 @@ public function up(): void Schema::table('environment_variables', function (Blueprint $table) { $table->boolean('is_multiline')->default(false); }); + Schema::table('shared_environment_variables', function (Blueprint $table) { + $table->boolean('is_multiline')->default(false); + }); } /** @@ -24,5 +27,8 @@ public function down(): void Schema::table('environment_variables', function (Blueprint $table) { $table->dropColumn('is_multiline'); }); + Schema::table('shared_environment_variables', function (Blueprint $table) { + $table->dropColumn('is_multiline'); + }); } }; diff --git a/resources/views/components/forms/input.blade.php b/resources/views/components/forms/input.blade.php index c13de00c1..5cabb3c70 100644 --- a/resources/views/components/forms/input.blade.php +++ b/resources/views/components/forms/input.blade.php @@ -1,4 +1,4 @@ -
+
@if ($label) @endif @if ($type === 'password') -
+
@if ($allowToPeak)
@@ -22,7 +22,7 @@ class="absolute inset-y-0 right-0 flex items-center pr-2 cursor-pointer hover:te
@endif - merge(['class' => $defaultClass]) }} + merge(['class' => $defaultClass]) }} @required($required) @if ($id !== 'null') wire:model={{ $id }} @endif wire:dirty.class.remove='text-white' wire:dirty.class="input-warning" wire:loading.attr="disabled" type="{{ $type }}" @readonly($readonly) @disabled($disabled) id="{{ $id }}" diff --git a/resources/views/components/forms/textarea.blade.php b/resources/views/components/forms/textarea.blade.php index 4ef36c310..74845e5e0 100644 --- a/resources/views/components/forms/textarea.blade.php +++ b/resources/views/components/forms/textarea.blade.php @@ -1,4 +1,4 @@ -
+
@if ($label) @endif - + +
+ @else + + wire:model={{ $value ?? $id }} + wire:dirty.class="input-warning" @endif + @disabled($disabled) @readonly($readonly) @required($required) id="{{ $id }}" + name="{{ $name }}" name={{ $id }}> + @endif + @error($id)
@elseif ($type === 'database')

Logs

@@ -26,7 +28,11 @@ @if ($loop->first)

Logs

@endif - + @if (data_get($servers, '0')) + + @else +
No functional server found for the database.
+ @endif @empty
No containers are not running.
@endforelse @@ -37,7 +43,11 @@ @if ($loop->first)

Logs

@endif - + @if (data_get($servers, '0')) + + @else +
No functional server found for the service.
+ @endif @empty
No containers are not running.
@endforelse