coolify/app/Http/Livewire/Project/Application/Revert.php

49 lines
1.6 KiB
PHP
Raw Normal View History

2023-05-16 17:53:48 +02:00
<?php
namespace App\Http\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Component;
use Illuminate\Support\Str;
class Revert extends Component
{
public Application $application;
public $images = [];
2023-05-16 21:49:29 +02:00
public string|null $current;
2023-05-16 18:20:24 +02:00
public function revertImage($tag)
{
dd("Reverting to {$this->application->uuid}:{$tag}");
}
2023-05-16 17:53:48 +02:00
public function loadImages()
{
try {
$image = $this->application->uuid;
$output = instantRemoteProcess([
"docker inspect --format='{{.Config.Image}}' {$this->application->uuid}",
], $this->application->destination->server, throwError: false);
$current_tag = Str::of($output)->trim()->explode(":");
$this->current = data_get($current_tag, 1);
$output = instantRemoteProcess([
"docker images --format '{{.Repository}}#{{.Tag}}#{{.CreatedAt}}'",
], $this->application->destination->server);
$this->images = Str::of($output)->trim()->explode("\n")->filter(function ($item) use ($image) {
return Str::of($item)->contains($image);
})->map(function ($item) {
$item = Str::of($item)->explode('#');
if ($item[1] === $this->current) {
2023-05-16 18:20:24 +02:00
$is_current = true;
2023-05-16 17:53:48 +02:00
}
return [
'tag' => $item[1],
2023-05-16 18:20:24 +02:00
'created_at' => $item[2],
'is_current' => $is_current ?? null,
2023-05-16 17:53:48 +02:00
];
})->toArray();
} catch (\Throwable $e) {
return generalErrorHandler($e, $this);
}
}
}