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

This commit is contained in:
Andras Bacsai
2024-09-07 20:56:26 +02:00
parent bb1454d255
commit 5fb560dbbf
3 changed files with 270 additions and 175 deletions

View File

@@ -2864,6 +2864,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
return collect($finalServices); return collect($finalServices);
} }
} }
function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null): Collection function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null): Collection
{ {
$isApplication = $resource instanceof Application; $isApplication = $resource instanceof Application;
@@ -2920,6 +2921,179 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
$parsedServices = collect([]); $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) { foreach ($services as $serviceName => $service) {
$image = data_get_str($service, 'image'); $image = data_get_str($service, 'image');
$restart = data_get_str($service, 'restart', RESTART_MODE); $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', [])); $ports = collect(data_get($service, 'ports', []));
$buildArgs = collect(data_get($service, 'build.args', [])); $buildArgs = collect(data_get($service, 'build.args', []));
$environment = $environment->merge($buildArgs); $environment = $environment->merge($buildArgs);
$environment = convertComposeEnvironmentToArray($environment);
$coolifyEnvironments = collect([]);
$isDatabase = isDatabaseImage(data_get_str($service, 'image')); $isDatabase = isDatabaseImage(data_get_str($service, 'image'));
$volumesParsed = collect([]); $volumesParsed = collect([]);
@@ -3204,176 +3382,86 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
]); ]);
} }
} }
// convert environment variables to one format
$environment = convertComposeEnvironmentToArray($environment);
// Add Coolify defined environments $normalEnvironments = $environment->diffKeys($allMagicEnvironments);
$allEnvironments = $resource->environment_variables()->get(['key', 'value']); $normalEnvironments = $normalEnvironments->filter(function ($value, $key) {
return ! str($value)->startsWith('SERVICE_');
$allEnvironments = $allEnvironments->mapWithKeys(function ($item) {
return [$item['key'] => $item['value']];
}); });
// remove $environment from $allEnvironments // foreach ($normalEnvironments as $key => $value) {
$coolifyDefinedEnvironments = $allEnvironments->diffKeys($environment); // $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,
// ]);
// }
// }
// filter magic environments foreach ($normalEnvironments as $key => $value) {
$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); $key = str($key);
$value = str(replaceVariables(str($value))); $originalKey = $key;
$originalValue = $value; $value = str($value);
$keyCommand = $key->after('SERVICE_')->before('_'); $parsedValue = str(replaceVariables(str($value)));
$valueCommand = $value->after('SERVICE_')->before('_'); // ray($key, $value, $parsedValue);
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 ($key->value() === $parsedValue->value()) {
if ($isApplication) { $value = null;
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}"); $resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
} elseif ($isService) { 'key' => $key,
$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, $nameOfId => $resource->id,
], [ ], [
'value' => $value, 'value' => $value,
'is_build_time' => false, 'is_build_time' => false,
'is_preview' => false, 'is_preview' => false,
]); ]);
} } else {
// Save the original value to the environment variables if ($value->startsWith('$')) {
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);
$value = str($value);
if ($value->startsWith('$') || $value->contains('${')) {
if ($value->contains('${')) {
$value = $value->after('${')->before('}');
}
$value = str(replaceVariables(str($value)));
if ($value->contains(':-')) { if ($value->contains(':-')) {
$value = str(replaceVariables(str($value)));
$key = $value->before(':'); $key = $value->before(':');
$value = $value->after(':-'); $value = $value->after(':-');
} elseif ($value->contains('-')) { } elseif ($value->contains('-')) {
$value = str(replaceVariables(str($value)));
$key = $value->before('-'); $key = $value->before('-');
$value = $value->after('-'); $value = $value->after('-');
} elseif ($value->contains(':?')) { } elseif ($value->contains(':?')) {
$value = str(replaceVariables(str($value)));
$key = $value->before(':'); $key = $value->before(':');
$value = $value->after(':?'); $value = $value->after(':?');
} elseif ($value->contains('?')) { } elseif ($value->contains('?')) {
$value = str(replaceVariables(str($value)));
$key = $value->before('?'); $key = $value->before('?');
$value = $value->after('?'); $value = $value->after('?');
} else {
$key = $value;
$value = null;
} }
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([ $resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
'key' => $key, 'key' => $key,
@@ -3384,6 +3472,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
'is_preview' => false, 'is_preview' => false,
]); ]);
} }
}
} }
if ($isApplication) { if ($isApplication) {
$branch = $originalResource->git_branch; $branch = $originalResource->git_branch;
@@ -3391,13 +3481,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$branch = "pull/{$pullRequestId}/head"; $branch = "pull/{$pullRequestId}/head";
} }
if ($originalResource->environment_variables->where('key', 'COOLIFY_BRANCH')->isEmpty()) { 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 // Add COOLIFY_CONTAINER_NAME to environment
if ($resource->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) { if ($resource->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$environment->put('COOLIFY_CONTAINER_NAME', $containerName); $coolifyEnvironments->put('COOLIFY_CONTAINER_NAME', $containerName);
} }
if ($isApplication) { if ($isApplication) {
@@ -3451,15 +3541,20 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
// Add COOLIFY_FQDN & COOLIFY_URL to environment // Add COOLIFY_FQDN & COOLIFY_URL to environment
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) { 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) { $urls = $fqdns->map(function ($fqdn) {
return str($fqdn)->replace('http://', '')->replace('https://', ''); 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); $serviceLabels = $labels->merge($defaultLabels);
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) { if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
if ($isApplication) { if ($isApplication) {
@@ -3554,8 +3649,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
if ($volumesParsed->count() > 0) { if ($volumesParsed->count() > 0) {
$payload['volumes'] = $volumesParsed; $payload['volumes'] = $volumesParsed;
} }
if ($environment->count() > 0 || $coolifyDefinedEnvironments->count() > 0) { if ($environment->count() > 0 || $coolifyEnvironments->count() > 0) {
$payload['environment'] = $environment->merge($coolifyDefinedEnvironments); $payload['environment'] = $environment->merge($coolifyEnvironments);
} }
if ($logging) { if ($logging) {
$payload['logging'] = $logging; $payload['logging'] = $logging;

View File

@@ -7,7 +7,7 @@ return [
// The release version of your application // The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) // 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 // When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'), 'environment' => config('app.env'),

View File

@@ -1,10 +1,10 @@
{ {
"coolify": { "coolify": {
"v4": { "v4": {
"version": "4.0.0-beta.331" "version": "4.0.0-beta.332"
}, },
"nightly": { "nightly": {
"version": "4.0.0-beta.332" "version": "4.0.0-beta.333"
}, },
"helper": { "helper": {
"version": "1.0.0" "version": "1.0.0"