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.

feat: Refactor shared.php to improve environment variable handling

Andras Bacsai5c7b9473f8db
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index cc5c134070..dc16a216ad 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -3219,10 +3219,31 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
// filter magic environments
$magicEnvironments = $environment->filter(function ($value, $key) {
+ $regex = '/\$\{(.*?)\}/';
+ preg_match_all($regex, $value, $matches);
+ if (count($matches[1]) > 0) {
+ foreach ($matches[1] as $match) {
+ if (str($match)->startsWith('SERVICE_') || str($match)->startsWith('SERVICE_')) {
+ return $match;
+ }
+ }
+ }
$value = str(replaceVariables(str($value)));
return str($key)->startsWith('SERVICE_') || str($value)->startsWith('SERVICE_');
});
+ foreach ($environment as $key => $value) {
+ $regex = '/\$\{(.*?)\}/';
+ preg_match_all($regex, $value, $matches);
+ if (count($matches[1]) > 0) {
+ foreach ($matches[1] as $match) {
+ if (str($match)->startsWith('SERVICE_') || str($match)->startsWith('SERVICE_')) {
+ $magicEnvironments->put($match, '$'.$match);
+ }
+ }
+ $magicEnvironments->forget($key);
+ }
+ }
$normalEnvironments = $environment->diffKeys($magicEnvironments);
if ($magicEnvironments->count() > 0) {
foreach ($magicEnvironments as $key => $value) {