fix: use local versions + service templates and query them every 10 minutes

This commit is contained in:
Andras Bacsai
2024-05-22 09:23:17 +02:00
parent 3237ca0d97
commit 10f3d8aa0f
11 changed files with 95 additions and 1149 deletions

View File

@@ -165,9 +165,12 @@ function get_latest_sentinel_version(): string
function get_latest_version_of_coolify(): string
{
try {
$response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
$versions = $response->json();
$versions = File::get(base_path('versions.json'));
$versions = json_decode($versions, true);
return data_get($versions, 'coolify.v4.version');
// $response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
// $versions = $response->json();
// return data_get($versions, 'coolify.v4.version');
} catch (\Throwable $e) {
//throw $e;
ray($e->getMessage());
@@ -462,24 +465,25 @@ function sslip(Server $server)
return "http://{$server->ip}.sslip.io";
}
function getServiceTemplates()
function get_service_templates()
{
if (isDev()) {
$services = File::get(base_path('templates/service-templates.json'));
$services = collect(json_decode($services))->sortKeys();
} else {
try {
$response = Http::retry(3, 50)->get(config('constants.services.official'));
if ($response->failed()) {
return collect([]);
}
$services = $response->json();
$services = collect($services)->sortKeys();
} catch (\Throwable $e) {
$services = collect([]);
}
}
return $services;
// if (isDev()) {
// $services = File::get(base_path('templates/service-templates.json'));
// $services = collect(json_decode($services))->sortKeys();
// } else {
// try {
// $response = Http::retry(3, 50)->get(config('constants.services.official'));
// if ($response->failed()) {
// return collect([]);
// }
// $services = $response->json();
// $services = collect($services)->sortKeys();
// } catch (\Throwable $e) {
// $services = collect([]);
// }
// }
$services = File::get(base_path('templates/service-templates.json'));
return collect(json_decode($services))->sortKeys();
}
function getResourceByUuid(string $uuid, ?int $teamId = null)
@@ -649,7 +653,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
$allServices = getServiceTemplates();
$allServices = get_service_templates();
$topLevelVolumes = collect(data_get($yaml, 'volumes', []));
$topLevelNetworks = collect(data_get($yaml, 'networks', []));
$services = data_get($yaml, 'services');