feat: pull latest images for services

This commit is contained in:
Andras Bacsai 2023-12-14 14:50:38 +01:00
parent a0abde8652
commit 75d1ec4f42
5 changed files with 61 additions and 1 deletions

View File

@ -11,6 +11,7 @@ class StartService
use AsAction;
public function handle(Service $service)
{
ray('Starting service: ' . $service->name);
$network = $service->destination->network;
$service->saveComposeConfigs();
$commands[] = "cd " . $service->workdir();

View File

@ -10,6 +10,7 @@ class StopService
use AsAction;
public function handle(Service $service)
{
ray('Stopping service: ' . $service->name);
$applications = $service->applications()->get();
foreach ($applications as $application) {
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server);

View File

@ -0,0 +1,25 @@
<?php
namespace App\Actions\Shared;
use App\Models\Service;
use Lorisleiva\Actions\Concerns\AsAction;
class PullImage
{
use AsAction;
public function handle(Service $resource)
{
$resource->saveComposeConfigs();
$commands[] = "cd " . $resource->workdir();
$commands[] = "echo 'Saved configuration files to {$resource->workdir()}.'";
$commands[] = "docker compose pull";
$server = data_get($resource, 'server');
if (!$server) return;
instant_remote_process($commands, $resource->server);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Project\Service;
use App\Actions\Shared\PullImage;
use App\Actions\Service\StartService;
use App\Actions\Service\StopService;
use App\Events\ServiceStatusChanged;
@ -69,4 +70,18 @@ public function stop(bool $forceCleanup = false)
}
ServiceStatusChanged::dispatch();
}
public function restart()
{
$this->checkDeployments();
if ($this->isDeploymentProgress) {
$this->dispatch('error', 'There is a deployment in progress.');
return;
}
PullImage::run($this->service);
$this->dispatch('image-pulled');
StopService::run($this->service);
$this->service->parse();
$activity = StartService::run($this->service);
$this->dispatch('newMonitorActivity', $activity->id);
}
}

View File

@ -1,4 +1,4 @@
<div class="navbar-main">
<div class="navbar-main" x-data>
<a wire:navigate class="{{ request()->routeIs('project.service.configuration') ? 'text-white' : '' }}"
href="{{ route('project.service.configuration', $parameters) }}">
<button>Configuration</button>
@ -27,6 +27,16 @@ class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400"
</button>
@endif
@if (serviceStatus($service) === 'running')
<button wire:click='restart' class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400">
<svg class="w-5 h-5 text-warning" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
stroke-width="2">
<path d="M19.933 13.041a8 8 0 1 1-9.925-8.788c3.899-1 7.935 1.007 9.425 4.747" />
<path d="M20 4v5h-5" />
</g>
</svg>
Pull Latest Images & Restart
</button>
<button wire:click='stop' class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400">
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24" stroke-width="2"
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
@ -58,3 +68,11 @@ class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400"
</button>
@endif
</div>
@script
<script>
$wire.on('image-pulled', () => {
startService.showModal();
});
</script>
@endscript