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

This commit is contained in:
Andras Bacsai
2024-09-04 13:37:15 +02:00
parent 59383d3678
commit 25e2b812cb

View File

@@ -3206,6 +3206,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
} }
// convert environment variables to one format // convert environment variables to one format
ray($environment);
$environment = convertComposeEnvironmentToArray($environment); $environment = convertComposeEnvironmentToArray($environment);
// Add Coolify defined environments // Add Coolify defined environments
@@ -3639,36 +3640,21 @@ function add_coolify_default_environment_variables(StandaloneRedis|StandalonePos
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}"); $where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
} }
} }
ray($where_to_add);
} }
function convertComposeEnvironmentToArray($environment) function convertComposeEnvironmentToArray($environment)
{ {
$convertedServiceVariables = collect([]); $convertedServiceVariables = collect([]);
foreach ($environment as $variableName => $variableValue) { if (isAssociativeArray($environment)) {
if (is_array($variableValue)) { $convertedServiceVariables = $environment;
$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 { } else {
if (is_numeric($variableName)) { foreach ($environment as $value) {
$key = str($variableValue); $parts = explode('=', $value, 2);
$value = null; $key = $parts[0];
} else { $realValue = $parts[1] ?? '';
$key = str($variableName);
if ($variableValue) {
$value = str($variableValue);
} else {
$value = null;
}
}
}
}
if ($key) { if ($key) {
$convertedServiceVariables->put($key->value(), $value?->value() ?? null); $convertedServiceVariables->put($key, $realValue);
}
} }
} }