An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: database custom environment variables
Andras Bacsaiea3e4f318831
diff --git a/app/Http/Controllers/Api/EnvironmentVariablesController.php b/app/Http/Controllers/Api/EnvironmentVariablesController.phpdeleted file mode 100644index d127d05253..0000000000--- a/app/Http/Controllers/Api/EnvironmentVariablesController.php+++ /dev/null@@ -1,35 +0,0 @@-<?php--namespace App\Http\Controllers\Api;--use App\Http\Controllers\Controller;-use App\Models\EnvironmentVariable;-use Illuminate\Http\Request;--class EnvironmentVariablesController extends Controller-{- public function delete_env_by_uuid(Request $request)- {- $teamId = getTeamIdFromToken();- if (is_null($teamId)) {- return invalidTokenResponse();- }- $env = EnvironmentVariable::where('uuid', $request->env_uuid)->first();- if (! $env) {- return response()->json([- 'message' => 'Environment variable not found.',- ], 404);- }- $found_app = $env->resource()->whereRelation('environment.project.team', 'id', $teamId)->first();- if (! $found_app) {- return response()->json([- 'message' => 'Environment variable not found.',- ], 404);- }- $env->delete();-- return response()->json([- 'message' => 'Environment variable deleted.',- ]);- }-}diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.phpindex 5e1d8ae139..3cd8c31406 100644--- a/app/Models/EnvironmentVariable.php+++ b/app/Models/EnvironmentVariable.php@@ -6,7 +6,6 @@ use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Model;use OpenApi\Attributes as OA;-use Symfony\Component\Yaml\Yaml;use Visus\Cuid2\Cuid2;#[OA\Schema(@@ -97,8 +96,22 @@ class EnvironmentVariable extends Model$resource = Application::find($this->application_id);} elseif ($this->service_id) {$resource = Service::find($this->service_id);- } elseif ($this->database_id) {- $resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id'));+ } elseif ($this->standalone_postgresql_id) {+ $resource = StandalonePostgresql::find($this->standalone_postgresql_id);+ } elseif ($this->standalone_redis_id) {+ $resource = StandaloneRedis::find($this->standalone_redis_id);+ } elseif ($this->standalone_mongodb_id) {+ $resource = StandaloneMongodb::find($this->standalone_mongodb_id);+ } elseif ($this->standalone_mysql_id) {+ $resource = StandaloneMysql::find($this->standalone_mysql_id);+ } elseif ($this->standalone_mariadb_id) {+ $resource = StandaloneMariadb::find($this->standalone_mariadb_id);+ } elseif ($this->standalone_keydb_id) {+ $resource = StandaloneKeydb::find($this->standalone_keydb_id);+ } elseif ($this->standalone_dragonfly_id) {+ $resource = StandaloneDragonfly::find($this->standalone_dragonfly_id);+ } elseif ($this->standalone_clickhouse_id) {+ $resource = StandaloneClickhouse::find($this->standalone_clickhouse_id);}return $resource;@@ -122,63 +135,6 @@ class EnvironmentVariable extends Model);}- protected function isFoundInCompose(): Attribute- {- return Attribute::make(- get: function () {- if (! $this->application_id) {- return true;- }- $found_in_compose = false;- $found_in_args = false;- $resource = $this->resource();- $compose = data_get($resource, 'docker_compose_raw');- if (! $compose) {- return true;- }- $yaml = Yaml::parse($compose);- $services = collect(data_get($yaml, 'services'));- if ($services->isEmpty()) {- return false;- }- foreach ($services as $service) {- $environments = collect(data_get($service, 'environment'));- $args = collect(data_get($service, 'build.args'));- if ($environments->isEmpty() && $args->isEmpty()) {- $found_in_compose = false;- break;- }-- $found_in_compose = $environments->contains(function ($item) {- if (str($item)->contains('=')) {- $item = str($item)->before('=');- }-- return strpos($item, $this->key) !== false;- });-- if ($found_in_compose) {- break;- }-- $found_in_args = $args->contains(function ($item) {- if (str($item)->contains('=')) {- $item = str($item)->before('=');- }-- return strpos($item, $this->key) !== false;- });-- if ($found_in_args) {- break;- }- }-- return $found_in_compose || $found_in_args;- }- );- }-protected function isShared(): Attribute{return Attribute::make(@@ -195,14 +151,17 @@ class EnvironmentVariable extends Modelprivate function get_real_environment_variables(?string $environment_variable = null, $resource = null){+ ray($environment_variable, $resource);if ((is_null($environment_variable) && $environment_variable == '') || is_null($resource)) {return null;}$environment_variable = trim($environment_variable);$sharedEnvsFound = str($environment_variable)->matchAll('/{{(.*?)}}/');if ($sharedEnvsFound->isEmpty()) {+return $environment_variable;}+foreach ($sharedEnvsFound as $sharedEnv) {$type = str($sharedEnv)->match('/(.*?)\./');if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.phpindex 1cb2f222c1..3499d8c00f 100644--- a/resources/views/livewire/project/shared/environment-variable/show.blade.php+++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php@@ -1,15 +1,6 @@<div><form wire:submit='submit'class="flex flex-col items-center gap-4 p-4 bg-white border lg:items-start dark:bg-base dark:border-coolgray-300">- {{-- @if (!$env->isFoundInCompose && !$isSharedVariable)- <div class="flex items-center justify-center gap-2 dark:text-warning text-coollabs"> <svg- class="hidden w-4 h-4 dark:text-warning lg:block" viewBox="0 0 256 256"- xmlns="http://www.w3.org/2000/svg">- <path fill="currentColor"- d="M240.26 186.1L152.81 34.23a28.74 28.74 0 0 0-49.62 0L15.74 186.1a27.45 27.45 0 0 0 0 27.71A28.31 28.31 0 0 0 40.55 228h174.9a28.31 28.31 0 0 0 24.79-14.19a27.45 27.45 0 0 0 .02-27.71m-20.8 15.7a4.46 4.46 0 0 1-4 2.2H40.55a4.46 4.46 0 0 1-4-2.2a3.56 3.56 0 0 1 0-3.73L124 46.2a4.77 4.77 0 0 1 8 0l87.44 151.87a3.56 3.56 0 0 1 .02 3.73M116 136v-32a12 12 0 0 1 24 0v32a12 12 0 0 1-24 0m28 40a16 16 0 1 1-16-16a16 16 0 0 1 16 16">- </path>- </svg>This variable is not found in the compose file, so it won't be used.</div>- @endif --}}@if ($isLocked)<div class="flex flex-1 w-full gap-2"><x-forms.input disabled id="env.key" />diff --git a/routes/api.php b/routes/api.phpindex 93db2001f8..c2c2f12ef4 100644--- a/routes/api.php+++ b/routes/api.php@@ -120,8 +120,6 @@ Route::group([Route::match(['get', 'post'], '/services/{uuid}/restart', [ServicesController::class, 'action_restart'])->middleware([IgnoreReadOnlyApiToken::class]);Route::match(['get', 'post'], '/services/{uuid}/stop', [ServicesController::class, 'action_stop'])->middleware([IgnoreReadOnlyApiToken::class]);- // Route::delete('/envs/{env_uuid}', [EnvironmentVariablesController::class, 'delete_env_by_uuid'])->middleware([IgnoreReadOnlyApiToken::class]);-});Route::any('/{any}', function () {