From 30751a60df77b2957d1af209cad4aee194fe799b Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:07:52 +0200 Subject: [PATCH] fix(deployment): resolve shared env vars using main server Use `$this->mainServer` when resolving environment variable values across deployment env generation (runtime, buildtime, nixpacks, args, and secrets hash) so shared server-scoped values are applied consistently. Also add `server_id` to `SharedEnvironmentVariable::$fillable` and normalize the Livewire Blade file newline. --- app/Jobs/ApplicationDeploymentJob.php | 26 +++++++++---------- app/Models/SharedEnvironmentVariable.php | 1 + .../shared-variables/server/index.blade.php | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index b77fa85b8..3c52e03a1 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1282,7 +1282,7 @@ private function generate_runtime_environment_variables() }); foreach ($runtime_environment_variables as $env) { - $envs->push($env->key.'='.$env->getResolvedValueWithServer($this->server)); + $envs->push($env->key.'='.$env->getResolvedValueWithServer($this->mainServer)); } // Check for PORT environment variable mismatch with ports_exposes @@ -1348,7 +1348,7 @@ private function generate_runtime_environment_variables() }); foreach ($runtime_environment_variables_preview as $env) { - $envs->push($env->key.'='.$env->getResolvedValueWithServer($this->server)); + $envs->push($env->key.'='.$env->getResolvedValueWithServer($this->mainServer)); } // Fall back to production env vars for keys not overridden by preview vars, @@ -1362,7 +1362,7 @@ private function generate_runtime_environment_variables() return $env->is_runtime && ! in_array($env->key, $previewKeys); }); foreach ($fallback_production_vars as $env) { - $envs->push($env->key.'='.$env->getResolvedValueWithServer($this->server)); + $envs->push($env->key.'='.$env->getResolvedValueWithServer($this->mainServer)); } } @@ -1604,7 +1604,7 @@ private function generate_buildtime_environment_variables() } foreach ($sorted_environment_variables as $env) { - $resolvedValue = $env->getResolvedValueWithServer($this->server); + $resolvedValue = $env->getResolvedValueWithServer($this->mainServer); // For literal/multiline vars, real_value includes quotes that we need to remove if ($env->is_literal || $env->is_multiline) { // Strip outer quotes from real_value and apply proper bash escaping @@ -1656,7 +1656,7 @@ private function generate_buildtime_environment_variables() } foreach ($sorted_environment_variables as $env) { - $resolvedValue = $env->getResolvedValueWithServer($this->server); + $resolvedValue = $env->getResolvedValueWithServer($this->mainServer); // For literal/multiline vars, real_value includes quotes that we need to remove if ($env->is_literal || $env->is_multiline) { // Strip outer quotes from real_value and apply proper bash escaping @@ -2394,7 +2394,7 @@ private function generate_nixpacks_env_variables() $this->env_nixpacks_args = collect([]); if ($this->pull_request_id === 0) { foreach ($this->application->nixpacks_environment_variables as $env) { - $resolvedValue = $env->getResolvedValueWithServer($this->server); + $resolvedValue = $env->getResolvedValueWithServer($this->mainServer); if (! is_null($resolvedValue) && $resolvedValue !== '') { $value = ($env->is_literal || $env->is_multiline) ? trim($resolvedValue, "'") : $resolvedValue; $this->env_nixpacks_args->push('--env '.escapeShellValue("{$env->key}={$value}")); @@ -2402,7 +2402,7 @@ private function generate_nixpacks_env_variables() } } else { foreach ($this->application->nixpacks_environment_variables_preview as $env) { - $resolvedValue = $env->getResolvedValueWithServer($this->server); + $resolvedValue = $env->getResolvedValueWithServer($this->mainServer); if (! is_null($resolvedValue) && $resolvedValue !== '') { $value = ($env->is_literal || $env->is_multiline) ? trim($resolvedValue, "'") : $resolvedValue; $this->env_nixpacks_args->push('--env '.escapeShellValue("{$env->key}={$value}")); @@ -2543,7 +2543,7 @@ private function generate_env_variables() ->get(); foreach ($envs as $env) { - $resolvedValue = $env->getResolvedValueWithServer($this->server); + $resolvedValue = $env->getResolvedValueWithServer($this->mainServer); if (! is_null($resolvedValue)) { $this->env_args->put($env->key, $resolvedValue); } @@ -2555,7 +2555,7 @@ private function generate_env_variables() ->get(); foreach ($envs as $env) { - $resolvedValue = $env->getResolvedValueWithServer($this->server); + $resolvedValue = $env->getResolvedValueWithServer($this->mainServer); if (! is_null($resolvedValue)) { $this->env_args->put($env->key, $resolvedValue); } @@ -3572,7 +3572,7 @@ private function generate_secrets_hash($variables) } else { $secrets_string = $variables ->map(function ($env) { - return "{$env->key}={$env->getResolvedValueWithServer($this->server)}"; + return "{$env->key}={$env->getResolvedValueWithServer($this->mainServer)}"; }) ->sort() ->implode('|'); @@ -3638,7 +3638,7 @@ private function add_build_env_variables_to_dockerfile() if (data_get($env, 'is_multiline') === true) { $argsToInsert->push("ARG {$env->key}"); } else { - $argsToInsert->push("ARG {$env->key}={$env->getResolvedValueWithServer($this->server)}"); + $argsToInsert->push("ARG {$env->key}={$env->getResolvedValueWithServer($this->mainServer)}"); } } // Add Coolify variables as ARGs @@ -3660,7 +3660,7 @@ private function add_build_env_variables_to_dockerfile() if (data_get($env, 'is_multiline') === true) { $argsToInsert->push("ARG {$env->key}"); } else { - $argsToInsert->push("ARG {$env->key}={$env->getResolvedValueWithServer($this->server)}"); + $argsToInsert->push("ARG {$env->key}={$env->getResolvedValueWithServer($this->mainServer)}"); } } // Add Coolify variables as ARGs @@ -3696,7 +3696,7 @@ private function add_build_env_variables_to_dockerfile() } } $envs_mapped = $envs->mapWithKeys(function ($env) { - return [$env->key => $env->getResolvedValueWithServer($this->server)]; + return [$env->key => $env->getResolvedValueWithServer($this->mainServer)]; }); $secrets_hash = $this->generate_secrets_hash($envs_mapped); $argsToInsert->push("ARG COOLIFY_BUILD_SECRETS_HASH={$secrets_hash}"); diff --git a/app/Models/SharedEnvironmentVariable.php b/app/Models/SharedEnvironmentVariable.php index bb1b29b9e..fa6fd45e0 100644 --- a/app/Models/SharedEnvironmentVariable.php +++ b/app/Models/SharedEnvironmentVariable.php @@ -17,6 +17,7 @@ class SharedEnvironmentVariable extends Model 'team_id', 'project_id', 'environment_id', + 'server_id', // Boolean flags 'is_multiline', diff --git a/resources/views/livewire/shared-variables/server/index.blade.php b/resources/views/livewire/shared-variables/server/index.blade.php index 4183fee5b..f7522eb6a 100644 --- a/resources/views/livewire/shared-variables/server/index.blade.php +++ b/resources/views/livewire/shared-variables/server/index.blade.php @@ -22,4 +22,4 @@ @endforelse - \ No newline at end of file +