From 003f97af24714cf1fa052ace85b1abb29493117a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sat, 22 Jun 2024 12:55:26 +0200 Subject: [PATCH] fix: you can now add env variable from ui to services --- app/Models/Service.php | 19 +++++++++++--- .../shared/environment-variable/all.blade.php | 25 ++++++++++++------- .../environment-variable/show.blade.php | 4 +-- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/Models/Service.php b/app/Models/Service.php index 8adca3424..795b9a421 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -839,20 +839,33 @@ public function saveComposeConfigs() $commands[] = "cd $workdir"; $json = Yaml::parse($this->docker_compose); + $envs_from_coolify = $this->environment_variables()->get(); foreach ($json['services'] as $service => $config) { $envs = collect($config['environment']); $envs->push("COOLIFY_CONTAINER_NAME=$service-{$this->uuid}"); + foreach ($envs_from_coolify as $env) { + $envs = $envs->map(function ($value) use ($env) { + if (str($value)->startsWith($env->key)) { + return "{$env->key}={$env->real_value}"; + } + + return $value; + }); + } + $envs = $envs->unique(); data_set($json, "services.$service.environment", $envs->toArray()); } + $this->docker_compose = Yaml::dump($json); $docker_compose_base64 = base64_encode($this->docker_compose); + $commands[] = "echo $docker_compose_base64 | base64 -d | tee docker-compose.yml > /dev/null"; - $envs = $this->environment_variables()->get(); $commands[] = 'rm -f .env || true'; - foreach ($envs as $env) { + + foreach ($envs_from_coolify as $env) { $commands[] = "echo '{$env->key}={$env->real_value}' >> .env"; } - if ($envs->count() === 0) { + if ($envs_from_coolify->count() === 0) { $commands[] = 'touch .env'; } instant_remote_process($commands, $this->server); diff --git a/resources/views/livewire/project/shared/environment-variable/all.blade.php b/resources/views/livewire/project/shared/environment-variable/all.blade.php index 42a2b48a7..649d59a20 100644 --- a/resources/views/livewire/project/shared/environment-variable/all.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/all.blade.php @@ -2,13 +2,11 @@

Environment Variables

- @if ($resource->type() !== 'service') - - - - {{ $view === 'normal' ? 'Developer view' : 'Normal view' }} - @endif + + + + {{ $view === 'normal' ? 'Developer view' : 'Normal view' }}
Environment variables (secrets) for this resource.
@if ($this->resourceClass === 'App\Models\Application' && data_get($this->resource, 'build_pack') !== 'dockercompose') @@ -19,8 +17,17 @@
@endif @if ($resource->type() === 'service' || $resource?->build_pack === 'dockercompose') -
Hardcoded variables are not shown here.
-
If you would like to add a variable, you must add it to your compose file (General tab).
+
+ + Hardcoded variables are not shown here. +
+ {{--
If you would like to add a variable, you must add it to + your compose file.
--}} @endif @if ($view === 'normal') 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 b23148547..0b5e767c0 100644 --- a/resources/views/livewire/project/shared/environment-variable/show.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php @@ -1,7 +1,7 @@
- @if (!$env->isFoundInCompose && !$isSharedVariable) + {{-- @if (!$env->isFoundInCompose && !$isSharedVariable)
This variable is not found in the compose file, so it won't be used.
- @endif + @endif --}} @if ($isLocked)