v0.10.0: Docker + Update-Funktion + deploy.sh
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class AppCheckUpdateCommand extends Command
|
||||
{
|
||||
protected $signature = 'app:check-update {--json : Ausgabe als JSON}';
|
||||
protected $description = 'Prüft ob ein Update auf Gitea verfügbar ist und speichert das Ergebnis im Cache';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$current = config('version.current');
|
||||
$giteaUrl = rtrim(config('version.gitea_url'), '/');
|
||||
$repo = config('version.gitea_repo');
|
||||
|
||||
if (empty($giteaUrl)) {
|
||||
$this->warn('GITEA_URL ist nicht konfiguriert.');
|
||||
Cache::put('app_update_available', null, now()->addHours(1));
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(8)
|
||||
->get("{$giteaUrl}/api/v1/repos/{$repo}/releases/latest");
|
||||
|
||||
if (!$response->successful()) {
|
||||
$this->warn("Gitea nicht erreichbar (HTTP {$response->status()}).");
|
||||
Cache::put('app_update_check_error', "HTTP {$response->status()}", now()->addHours(1));
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$latest = $response->json('tag_name', '');
|
||||
$available = !empty($latest) && version_compare(
|
||||
ltrim($latest, 'v'),
|
||||
ltrim($current, 'v'),
|
||||
'>'
|
||||
);
|
||||
|
||||
// Ergebnis 6 Stunden cachen
|
||||
Cache::put('app_update_available', $available ? $latest : false, now()->addHours(6));
|
||||
Cache::put('app_update_checked_at', now()->toDateTimeString(), now()->addHours(6));
|
||||
Cache::forget('app_update_check_error');
|
||||
|
||||
if ($this->option('json')) {
|
||||
$this->line(json_encode([
|
||||
'current' => $current,
|
||||
'latest' => $latest,
|
||||
'available' => $available,
|
||||
]));
|
||||
} else {
|
||||
if ($available) {
|
||||
$this->info("✓ Update verfügbar: {$current} → {$latest}");
|
||||
} else {
|
||||
$this->info("✓ Kein Update — aktuelle Version: {$current}");
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Verbindungsfehler: ' . $e->getMessage());
|
||||
Cache::put('app_update_check_error', $e->getMessage(), now()->addHours(1));
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user