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.

chore: Update versions.json and sentry.php to 4.0.0-beta.332

Andras Bacsai5fb560dbbfbd
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 5f93ce36f3..19f81f5276 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -2864,6 +2864,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
return collect($finalServices);
}
}
+
function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null): Collection
{
$isApplication = $resource instanceof Application;
@@ -2920,6 +2921,179 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
}
$parsedServices = collect([]);
+
+ // parse environments first
+ $allMagicEnvironments = collect([]);
+ ray()->clearAll();
+ foreach ($services as $serviceName => $service) {
+ $magicEnvironments = collect([]);
+ $image = data_get_str($service, 'image');
+ $environment = collect(data_get($service, 'environment', []));
+ $buildArgs = collect(data_get($service, 'build.args', []));
+ $environment = $environment->merge($buildArgs);
+ $isDatabase = isDatabaseImage(data_get_str($service, 'image'));
+
+ if ($isService) {
+ if ($isDatabase) {
+ $savedService = ServiceDatabase::firstOrCreate([
+ 'name' => $serviceName,
+ 'image' => $image,
+ 'service_id' => $resource->id,
+ ]);
+ } else {
+ $savedService = ServiceApplication::firstOrCreate([
+ 'name' => $serviceName,
+ 'image' => $image,
+ 'service_id' => $resource->id,
+ ]);
+ }
+ $environment = collect(data_get($service, 'environment', []));
+ $buildArgs = collect(data_get($service, 'build.args', []));
+ $environment = $environment->merge($buildArgs);
+
+ // convert environment variables to one format
+ $environment = convertComposeEnvironmentToArray($environment);
+
+ // Add Coolify defined environments
+ $allEnvironments = $resource->environment_variables()->get(['key', 'value']);
+
+ $allEnvironments = $allEnvironments->mapWithKeys(function ($item) {
+ return [$item['key'] => $item['value']];
+ });
+ // filter magic environments
+ foreach ($environment as $key => $value) {
+ $regex = '/\$(\{?([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)\}?)/';
+ preg_match_all($regex, $value, $valueMatches);
+ preg_match_all($regex, $key, $keyMatches);
+ if (count($valueMatches[1]) > 0) {
+ foreach ($valueMatches[1] as $match) {
+ if (str($match)->startsWith('SERVICE_')) {
+ if ($magicEnvironments->has($match)) {
+ continue;
+ }
+ $magicEnvironments->put($match, '');
+ }
+ }
+ }
+ if (count($keyMatches[1]) > 0) {
+ foreach ($keyMatches[1] as $match) {
+ if (str($match)->startsWith('SERVICE_')) {
+ if ($magicEnvironments->has($match)) {
+ continue;
+ }
+ $magicEnvironments->put($match, '');
+ }
+ }
+ }
+ if (str($key)->startsWith('SERVICE_')) {
+ $magicEnvironments->put($key, $value);
+ if (substr_count(str($key)->value(), '_') === 3) {
+ $newKey = str($key)->beforeLast('_')->value();
+ if ($newKey) {
+ $magicEnvironments->put($newKey, $value);
+ }
+ }
+ }
+ }
+ $allMagicEnvironments = $allMagicEnvironments->merge($magicEnvironments);
+ if ($magicEnvironments->count() > 0) {
+ foreach ($magicEnvironments as $key => $value) {
+ $key = str($key);
+ $value = str(replaceVariables(str($value)));
+ $originalValue = $value;
+ $keyCommand = $key->after('SERVICE_')->before('_');
+ $valueCommand = $value->after('SERVICE_')->before('_');
+ if ($key->startsWith('SERVICE_FQDN_')) {
+ $fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();
+ if (str($fqdnFor)->contains('_')) {
+ $fqdnFor = str($fqdnFor)->before('_');
+ }
+ } elseif ($value->startsWith('SERVICE_FQDN_')) {
+ $fqdnFor = $value->after('SERVICE_FQDN_')->lower()->value();
+ if (str($fqdnFor)->contains('_')) {
+ $fqdnFor = str($fqdnFor)->before('_');
+ }
+ } else {
+ $fqdnFor = null;
+ }
+ if ($keyCommand->value() === 'FQDN' || $valueCommand->value() === 'FQDN') {
+ if ($isApplication) {
+ $fqdn = generateFqdn($server, "{$resource->name}-$uuid");
+ } elseif ($isService) {
+ if ($fqdnFor) {
+ $fqdn = generateFqdn($server, "$fqdnFor-$uuid");
+ } else {
+ $fqdn = generateFqdn($server, "{$savedService->name}-$uuid");
+ }
+ }
+ if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
+ $path = $value->value();
+ if ($value === '/') {
+ $value = "$fqdn";
+ } else {
+ $value = "$fqdn$path";
+ }
+ } else {
+ $value = $fqdn;
+ }
+ if (! $isDatabase) {
+ if ($key->startsWith('SERVICE_FQDN_') && ($originalValue->value() === '' || $originalValue->startsWith('/'))) {
+ if ($isApplication && is_null($resource->fqdn)) {
+ data_forget($resource, 'environment_variables');
+ data_forget($resource, 'environment_variables_preview');
+ $resource->fqdn = $value;
+ $resource->save();
+ } elseif ($isService && is_null($savedService->fqdn)) {
+ if ($key->startsWith('SERVICE_FQDN_')) {
+ $savedService->fqdn = $value;
+ $savedService->save();
+ }
+ }
+ }
+ }
+
+ } elseif ($keyCommand->value() === 'URL' || $valueCommand->value() === 'URL') {
+ if ($isApplication) {
+ $fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
+ } elseif ($isService) {
+ $fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
+ }
+ if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
+ $path = $value->value();
+ $value = "$fqdn$path";
+ } else {
+ $value = $fqdn;
+ }
+ $value = str($fqdn)->replace('http://', '')->replace('https://', '');
+ } else {
+ $generatedValue = generateEnvValue($keyCommand, $resource);
+ if ($generatedValue) {
+ $value = $generatedValue;
+ }
+ }
+ if (str($fqdnFor)->startsWith('/')) {
+ $fqdnFor = null;
+ }
+ // Lets save the magic value to the environment variables
+ if (! $originalValue->startsWith('/')) {
+ if ($key->startsWith('SERVICE_')) {
+ $originalValue = $key;
+ }
+ $resource->environment_variables()->where('key', $originalValue->value())->where($nameOfId, $resource->id)->firstOrCreate([
+ 'key' => $originalValue->value(),
+ $nameOfId => $resource->id,
+ ], [
+ 'value' => $value,
+ 'is_build_time' => false,
+ 'is_preview' => false,
+ ]);
+ }
+ }
+ }
+ }
+ }
+
+ // Parse the rest of the services
foreach ($services as $serviceName => $service) {
$image = data_get_str($service, 'image');
$restart = data_get_str($service, 'restart', RESTART_MODE);
@@ -2938,6 +3112,10 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$ports = collect(data_get($service, 'ports', []));
$buildArgs = collect(data_get($service, 'build.args', []));
$environment = $environment->merge($buildArgs);
+
+ $environment = convertComposeEnvironmentToArray($environment);
+ $coolifyEnvironments = collect([]);
+
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
$volumesParsed = collect([]);
@@ -3204,177 +3382,57 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
]);
}
}
- // convert environment variables to one format
- $environment = convertComposeEnvironmentToArray($environment);
- // Add Coolify defined environments
- $allEnvironments = $resource->environment_variables()->get(['key', 'value']);
-
- $allEnvironments = $allEnvironments->mapWithKeys(function ($item) {
- return [$item['key'] => $item['value']];
+ $normalEnvironments = $environment->diffKeys($allMagicEnvironments);
+ $normalEnvironments = $normalEnvironments->filter(function ($value, $key) {
+ return ! str($value)->startsWith('SERVICE_');
});
- // remove $environment from $allEnvironments
- $coolifyDefinedEnvironments = $allEnvironments->diffKeys($environment);
-
- // 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) {
- $key = str($key);
- $value = str(replaceVariables(str($value)));
- $originalValue = $value;
- $keyCommand = $key->after('SERVICE_')->before('_');
- $valueCommand = $value->after('SERVICE_')->before('_');
- if ($key->startsWith('SERVICE_FQDN_')) {
- $fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();
- if (str($fqdnFor)->contains('_')) {
- $fqdnFor = str($fqdnFor)->before('_');
- }
- } elseif ($value->startsWith('SERVICE_FQDN_')) {
- $fqdnFor = $value->after('SERVICE_FQDN_')->lower()->value();
- if (str($fqdnFor)->contains('_')) {
- $fqdnFor = str($fqdnFor)->before('_');
- }
- } else {
- $fqdnFor = null;
- }
- if ($keyCommand->value() === 'FQDN' || $valueCommand->value() === 'FQDN') {
- if ($isApplication) {
- $fqdn = generateFqdn($server, "{$resource->name}-$uuid");
- } elseif ($isService) {
- if ($fqdnFor) {
- $fqdn = generateFqdn($server, "$fqdnFor-$uuid");
- } else {
- $fqdn = generateFqdn($server, "{$savedService->name}-$uuid");
- }
- }
- if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
- $path = $value->value();
- if ($value === '/') {
- $value = "$fqdn";
- } else {
- $value = "$fqdn$path";
- }
- } else {
- $value = $fqdn;
- }
- if (! $isDatabase) {
- if ($key->startsWith('SERVICE_FQDN_') && ($originalValue->value() === '' || $originalValue->startsWith('/'))) {
- if ($isApplication && is_null($resource->fqdn)) {
- data_forget($resource, 'environment_variables');
- data_forget($resource, 'environment_variables_preview');
- $resource->fqdn = $value;
- $resource->save();
- } elseif ($isService && is_null($savedService->fqdn)) {
- if ($key->startsWith('SERVICE_FQDN_')) {
- $savedService->fqdn = $value;
- $savedService->save();
- }
- }
- }
- }
+ // foreach ($normalEnvironments as $key => $value) {
+ // $key = str($key);
+ // $value = str($value);
+ // if ($value->startsWith('$') || $value->contains('${')) {
+ // if ($value->contains('${')) {
+ // $value = $value->after('${')->before('}');
+ // }
+ // $value = str(replaceVariables(str($value)));
+ // if ($value->contains(':-')) {
+ // $key = $value->before(':');
+ // $value = $value->after(':-');
+ // } elseif ($value->contains('-')) {
+ // $key = $value->before('-');
+ // $value = $value->after('-');
+ // } elseif ($value->contains(':?')) {
+ // $key = $value->before(':');
+ // $value = $value->after(':?');
+ // } elseif ($value->contains('?')) {
+ // $key = $value->before('?');
+ // $value = $value->after('?');
+ // } else {
+ // $key = $value;
+ // $value = null;
+ // }
+ // ray($key, $value);
+ // $resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
+ // 'key' => $key,
+ // $nameOfId => $resource->id,
+ // ], [
+ // 'value' => $value,
+ // 'is_build_time' => false,
+ // 'is_preview' => false,
+ // ]);
+ // }
+ // }
- } elseif ($keyCommand->value() === 'URL' || $valueCommand->value() === 'URL') {
- if ($isApplication) {
- $fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
- } elseif ($isService) {
- $fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
- }
- if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
- $path = $value->value();
- $value = "$fqdn$path";
- } else {
- $value = $fqdn;
- }
- $value = str($fqdn)->replace('http://', '')->replace('https://', '');
- } else {
- $generatedValue = generateEnvValue($valueCommand, $resource);
- if ($generatedValue) {
- $value = $generatedValue;
- }
- }
- if (str($fqdnFor)->startsWith('/')) {
- $fqdnFor = null;
- }
- // Lets save the magic value to the environment variables
- if (! $originalValue->startsWith('/')) {
- if ($key->startsWith('SERVICE_')) {
- $originalValue = $key;
- }
- $resource->environment_variables()->where('key', $originalValue->value())->where($nameOfId, $resource->id)->firstOrCreate([
- 'key' => $originalValue->value(),
- $nameOfId => $resource->id,
- ], [
- 'value' => $value,
- 'is_build_time' => false,
- 'is_preview' => false,
- ]);
- }
- // Save the original value to the environment variables
- if ($originalValue->startsWith('SERVICE_')) {
- $value = "$$originalValue";
- }
- $resource->environment_variables()->where('key', $key->value())->where($nameOfId, $resource->id)->firstOrCreate([
- 'key' => $key->value(),
- $nameOfId => $resource->id,
- ], [
- 'value' => "$value",
- 'is_build_time' => false,
- 'is_preview' => false,
- ]);
- }
- }
foreach ($normalEnvironments as $key => $value) {
$key = str($key);
+ $originalKey = $key;
$value = str($value);
- if ($value->startsWith('$') || $value->contains('${')) {
- if ($value->contains('${')) {
- $value = $value->after('${')->before('}');
- }
- $value = str(replaceVariables(str($value)));
- if ($value->contains(':-')) {
- $key = $value->before(':');
- $value = $value->after(':-');
- } elseif ($value->contains('-')) {
- $key = $value->before('-');
- $value = $value->after('-');
- } elseif ($value->contains(':?')) {
- $key = $value->before(':');
- $value = $value->after(':?');
- } elseif ($value->contains('?')) {
- $key = $value->before('?');
- $value = $value->after('?');
- } else {
- $key = $value;
- $value = null;
- }
+ $parsedValue = str(replaceVariables(str($value)));
+ // ray($key, $value, $parsedValue);
+
+ if ($key->value() === $parsedValue->value()) {
+ $value = null;
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
'key' => $key,
$nameOfId => $resource->id,
@@ -3383,6 +3441,38 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
'is_build_time' => false,
'is_preview' => false,
]);
+ } else {
+ if ($value->startsWith('$')) {
+ if ($value->contains(':-')) {
+ $value = str(replaceVariables(str($value)));
+ $key = $value->before(':');
+ $value = $value->after(':-');
+ } elseif ($value->contains('-')) {
+ $value = str(replaceVariables(str($value)));
+
+ $key = $value->before('-');
+ $value = $value->after('-');
+ } elseif ($value->contains(':?')) {
+ $value = str(replaceVariables(str($value)));
+
+ $key = $value->before(':');
+ $value = $value->after(':?');
+ } elseif ($value->contains('?')) {
+ $value = str(replaceVariables(str($value)));
+
+ $key = $value->before('?');
+ $value = $value->after('?');
+ }
+ $resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
+ 'key' => $key,
+ $nameOfId => $resource->id,
+ ], [
+ 'value' => $value,
+ 'is_build_time' => false,
+ 'is_preview' => false,
+ ]);
+ }
+
}
}
if ($isApplication) {
@@ -3391,13 +3481,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$branch = "pull/{$pullRequestId}/head";
}
if ($originalResource->environment_variables->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
- $environment->put('COOLIFY_BRANCH', $branch);
+ $coolifyEnvironments->put('COOLIFY_BRANCH', $branch);
}
}
// Add COOLIFY_CONTAINER_NAME to environment
if ($resource->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
- $environment->put('COOLIFY_CONTAINER_NAME', $containerName);
+ $coolifyEnvironments->put('COOLIFY_CONTAINER_NAME', $containerName);
}
if ($isApplication) {
@@ -3451,15 +3541,20 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
}
// Add COOLIFY_FQDN & COOLIFY_URL to environment
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
- $environment->put('COOLIFY_URL', $fqdns->implode(','));
+ $coolifyEnvironments->put('COOLIFY_URL', $fqdns->implode(','));
$urls = $fqdns->map(function ($fqdn) {
return str($fqdn)->replace('http://', '')->replace('https://', '');
});
- $environment->put('COOLIFY_FQDN', $urls->implode(','));
+ $coolifyEnvironments->put('COOLIFY_FQDN', $urls->implode(','));
}
- add_coolify_default_environment_variables($resource, $environment, $resource->environment_variables);
+ add_coolify_default_environment_variables($resource, $coolifyEnvironments, $resource->environment_variables);
+ if ($environment->count() > 0) {
+ $environment = $environment->filter(function ($value, $key) {
+ return ! str($key)->startsWith('SERVICE_FQDN_');
+ });
+ }
$serviceLabels = $labels->merge($defaultLabels);
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
if ($isApplication) {
@@ -3554,8 +3649,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
if ($volumesParsed->count() > 0) {
$payload['volumes'] = $volumesParsed;
}
- if ($environment->count() > 0 || $coolifyDefinedEnvironments->count() > 0) {
- $payload['environment'] = $environment->merge($coolifyDefinedEnvironments);
+ if ($environment->count() > 0 || $coolifyEnvironments->count() > 0) {
+ $payload['environment'] = $environment->merge($coolifyEnvironments);
}
if ($logging) {
$payload['logging'] = $logging;
diff --git a/config/sentry.php b/config/sentry.php
index f48995f010..a978caa5ea 100644
--- a/config/sentry.php
+++ b/config/sentry.php
@@ -7,7 +7,7 @@ return [
// The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
- 'release' => '4.0.0-beta.331',
+ 'release' => '4.0.0-beta.332',
// When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'),
diff --git a/versions.json b/versions.json
index 42f692ed1c..2040250c9c 100644
--- a/versions.json
+++ b/versions.json
@@ -1,13 +1,13 @@
{
"coolify": {
"v4": {
- "version": "4.0.0-beta.331"
+ "version": "4.0.0-beta.332"
},
"nightly": {
- "version": "4.0.0-beta.332"
+ "version": "4.0.0-beta.333"
},
"helper": {
"version": "1.0.0"
}
}
-}
+}
\ No newline at end of file