refactor: Update environment variable handling in StartClickhouse.php and ApplicationDeploymentJob.php

This commit is contained in:
Andras Bacsai 2024-08-29 15:11:54 +02:00
parent 0df1163718
commit 301a3596e8
3 changed files with 52 additions and 29 deletions

View File

@ -922,7 +922,7 @@ private function save_environment_variables()
}
}
add_coolify_default_environment_variables($this->application, $environment, $this->application->environment_variables_preview);
add_coolify_default_environment_variables($this->application, $envs, $this->application->environment_variables_preview);
foreach ($sorted_environment_variables_preview as $env) {
$real_value = $env->real_value;

View File

@ -2103,10 +2103,10 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$parsedServiceVariables->put('COOLIFY_APP_NAME', $resource->name);
}
if (! $parsedServiceVariables->has('COOLIFY_SERVER_IP')) {
$parsedServiceVariables->put("COOLIFY_SERVER_IP", $resource->destination->server->ip);
$parsedServiceVariables->put('COOLIFY_SERVER_IP', $resource->destination->server->ip);
}
if (! $parsedServiceVariables->has('COOLIFY_ENVIRONMENT_NAME')) {
$parsedServiceVariables->put("COOLIFY_ENVIRONMENT_NAME", $resource->environment->name);
$parsedServiceVariables->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
}
if (! $parsedServiceVariables->has('COOLIFY_PROJECT_NAME')) {
$parsedServiceVariables->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
@ -3429,6 +3429,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
});
$environment->put('COOLIFY_FQDN', $urls->implode(','));
}
add_coolify_default_environment_variables($resource, $environment, $resource->environment_variables);
$serviceLabels = $labels->merge($defaultLabels);
if (! $isDatabase && $fqdns?->count() > 0) {
@ -3555,7 +3556,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
return $topLevel;
}
function generate_fluentd_configuration() : array {
function generate_fluentd_configuration(): array
{
return [
'driver' => 'fluentd',
'options' => [
@ -3564,7 +3566,7 @@ function generate_fluentd_configuration() : array {
'fluentd-sub-second-precision' => 'true',
// env vars are used in the LogDrain configurations
'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME',
]
],
];
}
@ -3576,25 +3578,46 @@ function generate_fluentd_configuration() : array {
* - COOLIFY_ENVIRONMENT_NAME
*
* Theses variables are added in place to the $where_to_add array.
*
* @param StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|Application $resource
* @param Collection $where_to_add
* @param Collection|null $where_to_check
*
*/
function add_coolify_default_environment_variables(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|Application $resource, Collection &$where_to_add, ?Collection $where_to_check = null) {
function add_coolify_default_environment_variables(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|Application|Service $resource, Collection &$where_to_add, ?Collection $where_to_check = null)
{
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
$where_to_add->put('COOLIFY_APP_NAME', $resource->name);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_APP_NAME', $resource->name);
} else {
$where_to_add->push("COOLIFY_APP_NAME={$resource->name}");
}
}
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
$where_to_add->put('COOLIFY_SERVER_IP', $resource->destination->server->ip);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_SERVER_IP', $resource->server->ip);
} else {
$where_to_add->push("COOLIFY_SERVER_IP={$resource->destination->server->ip}");
}
}
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
$where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_ENVIRONMENT_NAME', $resource->environment->name);
} else {
$where_to_add->push("COOLIFY_ENVIRONMENT_NAME={$resource->environment->name}");
}
}
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
if ($resource instanceof Application && $resource->build_pack === 'dockercompose') {
$where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
} elseif ($resource instanceof Service) {
$where_to_add->put('COOLIFY_PROJECT_NAME', $resource->project()->name);
} else {
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
}
}
}
function convertComposeEnvironmentToArray($environment)
{