Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: Convert environment variables to one format in shared.php

Andras Bacsai25e2b812cb6f
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 7ef02fff9f..b21ceac315 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -3206,6 +3206,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
}
}
// convert environment variables to one format
+ ray($environment);
$environment = convertComposeEnvironmentToArray($environment);
// Add Coolify defined environments
@@ -3639,37 +3640,22 @@ function add_coolify_default_environment_variables(StandaloneRedis|StandalonePos
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
}
}
- ray($where_to_add);
}
function convertComposeEnvironmentToArray($environment)
{
$convertedServiceVariables = collect([]);
- foreach ($environment as $variableName => $variableValue) {
- if (is_array($variableValue)) {
- $key = str(collect($variableValue)->keys()->first());
- $value = str(collect($variableValue)->values()->first());
- } elseif (is_string($variableValue)) {
- if (str($variableValue)->contains('=')) {
- $key = str($variableValue)->before('=');
- $value = str($variableValue)->after('=');
- } else {
- if (is_numeric($variableName)) {
- $key = str($variableValue);
- $value = null;
- } else {
- $key = str($variableName);
- if ($variableValue) {
- $value = str($variableValue);
- } else {
- $value = null;
- }
- }
+ if (isAssociativeArray($environment)) {
+ $convertedServiceVariables = $environment;
+ } else {
+ foreach ($environment as $value) {
+ $parts = explode('=', $value, 2);
+ $key = $parts[0];
+ $realValue = $parts[1] ?? '';
+ if ($key) {
+ $convertedServiceVariables->put($key, $realValue);
}
}
- if ($key) {
- $convertedServiceVariables->put($key->value(), $value?->value() ?? null);
- }
}
return $convertedServiceVariables;