refactor(deployment): streamline environment variable generation in ApplicationDeploymentJob
- Removed redundant logic for merging COOLIFY_* variables into env_args. - Simplified the process of adding environment variables by directly incorporating generated COOLIFY environment variables. - Enhanced clarity and maintainability of the generate_env_variables method.
This commit is contained in:
parent
c14497303f
commit
158747c8b1
1 changed files with 5 additions and 36 deletions
|
|
@ -1965,10 +1965,14 @@ private function generate_env_variables()
|
|||
{
|
||||
$this->env_args = collect([]);
|
||||
$this->env_args->put('SOURCE_COMMIT', $this->commit);
|
||||
|
||||
$coolify_envs = $this->generate_coolify_env_variables();
|
||||
$coolify_envs->each(function ($value, $key) {
|
||||
$this->env_args->put($key, $value);
|
||||
});
|
||||
|
||||
// For build process, include only environment variables where is_buildtime = true
|
||||
if ($this->pull_request_id === 0) {
|
||||
// Get environment variables that are marked as available during build
|
||||
$envs = $this->application->environment_variables()
|
||||
->where('key', 'not like', 'NIXPACKS_%')
|
||||
->where('is_buildtime', true)
|
||||
|
|
@ -1977,24 +1981,9 @@ private function generate_env_variables()
|
|||
foreach ($envs as $env) {
|
||||
if (! is_null($env->real_value)) {
|
||||
$this->env_args->put($env->key, $env->real_value);
|
||||
if (str($env->real_value)->startsWith('$')) {
|
||||
$variable_key = str($env->real_value)->after('$');
|
||||
if ($variable_key->startsWith('COOLIFY_')) {
|
||||
$variable = $coolify_envs->get($variable_key->value());
|
||||
if (filled($variable)) {
|
||||
$this->env_args->prepend($variable, $variable_key->value());
|
||||
}
|
||||
} else {
|
||||
$variable = $this->application->environment_variables()->where('key', $variable_key)->first();
|
||||
if ($variable) {
|
||||
$this->env_args->prepend($variable->real_value, $env->key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Get preview environment variables that are marked as available during build
|
||||
$envs = $this->application->environment_variables_preview()
|
||||
->where('key', 'not like', 'NIXPACKS_%')
|
||||
->where('is_buildtime', true)
|
||||
|
|
@ -2003,29 +1992,9 @@ private function generate_env_variables()
|
|||
foreach ($envs as $env) {
|
||||
if (! is_null($env->real_value)) {
|
||||
$this->env_args->put($env->key, $env->real_value);
|
||||
if (str($env->real_value)->startsWith('$')) {
|
||||
$variable_key = str($env->real_value)->after('$');
|
||||
if ($variable_key->startsWith('COOLIFY_')) {
|
||||
$variable = $coolify_envs->get($variable_key->value());
|
||||
if (filled($variable)) {
|
||||
$this->env_args->prepend($variable, $variable_key->value());
|
||||
}
|
||||
} else {
|
||||
$variable = $this->application->environment_variables_preview()->where('key', $variable_key)->first();
|
||||
if ($variable) {
|
||||
$this->env_args->prepend($variable->real_value, $env->key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge COOLIFY_* variables into env_args for build process
|
||||
// This ensures they're available for both build args and build secrets
|
||||
$coolify_envs->each(function ($value, $key) {
|
||||
$this->env_args->put($key, $value);
|
||||
});
|
||||
}
|
||||
|
||||
private function generate_compose_file()
|
||||
|
|
|
|||
Loading…
Reference in a new issue