test add_coolif_default_environment_variables

This commit is contained in:
Vahor 2024-08-28 13:30:59 +02:00
parent b51065a003
commit f6d649307c
No known key found for this signature in database
10 changed files with 39 additions and 137 deletions

View File

@ -160,20 +160,7 @@ private function generate_environment_variables()
$environment_variables->push("CLICKHOUSE_ADMIN_PASSWORD={$this->database->clickhouse_admin_password}"); $environment_variables->push("CLICKHOUSE_ADMIN_PASSWORD={$this->database->clickhouse_admin_password}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -163,20 +163,7 @@ private function generate_environment_variables()
$environment_variables->push("REDIS_PASSWORD={$this->database->keydb_password}"); $environment_variables->push("REDIS_PASSWORD={$this->database->keydb_password}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -169,20 +169,7 @@ private function generate_environment_variables()
$environment_variables->push("MARIADB_PASSWORD={$this->database->mariadb_password}"); $environment_variables->push("MARIADB_PASSWORD={$this->database->mariadb_password}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -182,20 +182,7 @@ private function generate_environment_variables()
$environment_variables->push("MONGO_INITDB_DATABASE={$this->database->mongo_initdb_database}"); $environment_variables->push("MONGO_INITDB_DATABASE={$this->database->mongo_initdb_database}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -169,20 +169,7 @@ private function generate_environment_variables()
$environment_variables->push("MYSQL_PASSWORD={$this->database->mysql_password}"); $environment_variables->push("MYSQL_PASSWORD={$this->database->mysql_password}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -191,20 +191,7 @@ private function generate_environment_variables()
$environment_variables->push("POSTGRES_DB={$this->database->postgres_db}"); $environment_variables->push("POSTGRES_DB={$this->database->postgres_db}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -168,20 +168,7 @@ private function generate_environment_variables()
$environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}"); $environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}");
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);
if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
return $environment_variables->all(); return $environment_variables->all();
} }

View File

@ -906,19 +906,7 @@ private function save_environment_variables()
} }
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->application, $environment, $this->application->environment_variables_preview);
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$envs->push("COOLIFY_APP_NAME={$this->application->name}");
}
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$envs->push("COOLIFY_SERVER_IP={$this->application->destination->server->ip}");
}
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$envs->push("COOLIFY_ENVIRONMENT_NAME={$this->application->environment->name}");
}
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$envs->push("COOLIFY_PROJECT_NAME={$this->application->project()->name}");
}
foreach ($sorted_environment_variables_preview as $env) { foreach ($sorted_environment_variables_preview as $env) {
$real_value = $env->real_value; $real_value = $env->real_value;
@ -969,19 +957,7 @@ private function save_environment_variables()
} }
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->application, $envs, $this->application->environment_variables);
if ($this->application->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$envs->push("COOLIFY_APP_NAME={$this->application->name}");
}
if ($this->application->environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$envs->push("COOLIFY_SERVER_IP={$this->application->destination->server->ip}");
}
if ($this->application->environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$envs->push("COOLIFY_ENVIRONMENT_NAME={$this->application->environment->name}");
}
if ($this->application->environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$envs->push("COOLIFY_PROJECT_NAME={$this->application->project()->name}");
}
foreach ($sorted_environment_variables as $env) { foreach ($sorted_environment_variables as $env) {
$real_value = $env->real_value; $real_value = $env->real_value;

View File

@ -1464,19 +1464,7 @@ public function newParser(int $pull_request_id = 0, ?int $preview_id = null)
if ($this->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) { if ($this->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$environment->put('COOLIFY_CONTAINER_NAME', $containerName); $environment->put('COOLIFY_CONTAINER_NAME', $containerName);
} }
// TODO: move this in a shared function add_coolify_default_environment_variables($this->database, $environment, $this->environment_variables);
if ($this->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$environment->push("COOLIFY_APP_NAME={$this->database->name}");
}
if ($this->environment->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$environment->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}");
}
if ($this->environment->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) {
$environment->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}");
}
if ($this->environment->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$environment->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}");
}
// Remove SERVICE_FQDN and SERVICE_URL from environment // Remove SERVICE_FQDN and SERVICE_URL from environment
$environment = $environment->filter(function ($value, $key) { $environment = $environment->filter(function ($value, $key) {

View File

@ -3346,3 +3346,32 @@ function generate_fluentd_configuration() : array {
] ]
]; ];
} }
/**
* This method adds the default environment variables to the resource.
* - COOLIFY_APP_NAME
* - COOLIFY_PROJECT_NAME
* - COOLIFY_SERVER_IP
* - 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) {
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_APP_NAME')->isEmpty()) {
$where_to_add->push("COOLIFY_APP_NAME={$resource->name}");
}
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) {
$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()) {
$where_to_add->push("COOLIFY_ENVIRONMENT_NAME={$resource->environment->name}");
}
if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) {
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
}
}