2023-05-16 15:53:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Application;
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Illuminate\Support\Str;
|
2023-05-22 08:34:00 +00:00
|
|
|
use Visus\Cuid2\Cuid2;
|
2023-05-16 15:53:48 +00:00
|
|
|
|
2023-05-17 10:14:18 +00:00
|
|
|
class Rollback extends Component
|
2023-05-16 15:53:48 +00:00
|
|
|
{
|
|
|
|
public Application $application;
|
|
|
|
public $images = [];
|
2023-05-16 19:49:29 +00:00
|
|
|
public string|null $current;
|
2023-05-22 08:34:00 +00:00
|
|
|
public array $parameters;
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-05-24 12:26:50 +00:00
|
|
|
$this->parameters = get_parameters();
|
2023-05-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
public function rollbackImage($tag)
|
2023-05-16 16:20:24 +00:00
|
|
|
{
|
2023-05-22 08:34:00 +00:00
|
|
|
$deployment_uuid = new Cuid2(7);
|
|
|
|
|
2023-05-24 12:26:50 +00:00
|
|
|
queue_application_deployment(
|
|
|
|
application: $this->application,
|
|
|
|
metadata: [
|
|
|
|
'deployment_uuid' => $deployment_uuid,
|
|
|
|
'application_uuid' => $this->application->uuid,
|
|
|
|
'force_rebuild' => false,
|
|
|
|
'commit' => $tag,
|
|
|
|
]
|
|
|
|
);
|
2023-05-22 08:34:00 +00:00
|
|
|
|
2023-05-24 12:26:50 +00:00
|
|
|
return redirect()->route('project.application.deployments', [
|
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'application_uuid' => $this->parameters['application_uuid'],
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
|
|
|
]);
|
2023-05-16 16:20:24 +00:00
|
|
|
}
|
2023-05-16 15:53:48 +00:00
|
|
|
public function loadImages()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$image = $this->application->uuid;
|
2023-05-24 13:25:08 +00:00
|
|
|
$output = instant_remote_process([
|
2023-05-16 15:53:48 +00:00
|
|
|
"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);
|
|
|
|
|
2023-05-24 13:25:08 +00:00
|
|
|
$output = instant_remote_process([
|
2023-05-16 15:53:48 +00:00
|
|
|
"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-24 12:26:50 +00:00
|
|
|
// $is_current = true;
|
2023-05-16 15:53:48 +00:00
|
|
|
}
|
|
|
|
return [
|
|
|
|
'tag' => $item[1],
|
2023-05-16 16:20:24 +00:00
|
|
|
'created_at' => $item[2],
|
|
|
|
'is_current' => $is_current ?? null,
|
2023-05-16 15:53:48 +00:00
|
|
|
];
|
|
|
|
})->toArray();
|
|
|
|
} catch (\Throwable $e) {
|
2023-05-24 12:26:50 +00:00
|
|
|
return general_error_handler($e, $this);
|
2023-05-16 15:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|