feat(services): show template update timestamps

This commit is contained in:
Andras Bacsai committed 2026-06-04 09:34:11 +02:00
1 parent 2833c68af9
commit 981b670eb4
3 files changed
+143 -3

No files matched your search

+56 -1
View File
@@ -4,7 +4,9 @@ namespace App\Livewire\Project\New;
use App\Models\Project;
use App\Models\Server;
use Carbon\CarbonImmutable;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Livewire\Component;
class Select extends Component
@@ -105,7 +107,9 @@ class Select extends Component
public function loadServices()
{
$services = get_service_templates();
$services = collect($services)->map(function ($service, $key) {
$templateLastUpdatedMap = $this->serviceTemplateLastUpdatedMap($services->keys());
$services = collect($services)->map(function ($service, $key) use ($templateLastUpdatedMap) {
$default_logo = 'images/default.webp';
$logo = data_get($service, 'logo', $default_logo);
$local_logo_path = public_path($logo);
@@ -116,6 +120,7 @@ class Select extends Component
'logo_github_url' => file_exists($local_logo_path)
? 'https://raw.githubusercontent.com/coollabsio/coolify/refs/heads/main/public/'.$logo
: asset($default_logo),
'templateLastUpdated' => $templateLastUpdatedMap[(string) $key] ?? null,
] + (array) $service;
})->all();
@@ -247,6 +252,7 @@ class Select extends Component
];
return [
'serviceTemplatesLastUpdated' => $this->serviceTemplatesLastUpdated(),
'services' => $services,
'categories' => $categories,
'gitBasedApplications' => $gitBasedApplications,
@@ -268,6 +274,55 @@ class Select extends Component
}
}
private function serviceTemplatesLastUpdated(): ?string
{
return $this->formatLastModified($this->serviceTemplatesPath());
}
private function serviceTemplateLastUpdatedMap(Collection $serviceNames): array
{
$bundleMtime = file_exists($this->serviceTemplatesPath()) ? filemtime($this->serviceTemplatesPath()) : 0;
return Cache::remember(
"service-template-last-updated-map:{$bundleMtime}",
now()->addDay(),
fn () => $serviceNames
->mapWithKeys(fn ($serviceName) => [
(string) $serviceName => $this->serviceTemplateLastUpdated((string) $serviceName),
])
->all()
);
}
private function serviceTemplateLastUpdated(string $serviceName): ?string
{
foreach (['yaml', 'yml'] as $extension) {
$templatePath = base_path("templates/compose/{$serviceName}.{$extension}");
if (file_exists($templatePath)) {
return $this->formatLastModified($templatePath);
}
}
return null;
}
private function serviceTemplatesPath(): string
{
return base_path('templates/'.config('constants.services.file_name'));
}
private function formatLastModified(string $path): ?string
{
if (! file_exists($path)) {
return null;
}
return CarbonImmutable::createFromTimestamp(filemtime($path))
->timezone(config('app.timezone'))
->format('M j, Y H:i');
}
public function setType(string $type)
{
$type = str($type)->lower()->slug()->value();