This commit is contained in:
Andras Bacsai 2023-09-21 21:30:13 +02:00
parent 6b75ff7de4
commit e1a1490911
10 changed files with 139 additions and 40 deletions

View File

@ -23,7 +23,7 @@ public function handle(Service $service)
}
$commands[] = "docker compose pull";
$commands[] = "docker compose up -d";
$commands[] = "docker network connect $service->uuid coolify-proxy";
$commands[] = "docker network connect $service->uuid coolify-proxy 2>/dev/null || true";
$activity = remote_process($commands, $service->server);
return $activity;
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Actions\Service;
use Lorisleiva\Actions\Concerns\AsAction;
use App\Models\Service;
class StopService
{
use AsAction;
public function handle(Service $service)
{
$applications = $service->applications()->get();
foreach ($applications as $application) {
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server);
$application->update(['status' => 'exited']);
}
$dbs = $service->databases()->get();
foreach ($dbs as $db) {
instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server);
$db->update(['status' => 'exited']);
}
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Livewire\Project\Service;
use App\Actions\Service\StartService;
use App\Actions\Service\StopService;
use App\Jobs\ContainerStatusJob;
use App\Models\Service;
use Illuminate\Support\Collection;
@ -15,7 +16,7 @@ class Index extends Component
public array $parameters;
public array $query;
public Collection $services;
protected $listeners = ['serviceStatusUpdated'];
protected $rules = [
'services.*.fqdn' => 'nullable',
];
@ -39,11 +40,14 @@ public function render()
{
return view('livewire.project.service.index')->layout('layouts.app');
}
public function serviceStatusUpdated() {
ray('serviceStatusUpdated');
$this->check_status();
}
public function check_status()
{
dispatch_sync(new ContainerStatusJob($this->service->server));
$this->service->refresh();
}
public function submit()
{
@ -76,4 +80,8 @@ public function deploy()
$activity = StartService::run($this->service);
$this->emit('newMonitorActivity', $activity->id);
}
public function stop() {
StopService::run($this->service);
$this->service->refresh();
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Http\Livewire\Project\Service;
use Livewire\Component;
class Modal extends Component
{
public function serviceStatusUpdated() {
$this->emit('serviceStatusUpdated');
}
public function render()
{
return view('livewire.project.service.modal');
}
}

View File

@ -44,9 +44,12 @@ protected function value(): Attribute
);
}
private function get_environment_variables(string $environment_variable): string|null
private function get_environment_variables(?string $environment_variable = null): string|null
{
// $team_id = currentTeam()->id;
if (!$environment_variable) {
return null;
}
$environment_variable = trim(decrypt($environment_variable));
if (Str::startsWith($environment_variable, '{{') && Str::endsWith($environment_variable, '}}') && Str::contains($environment_variable, 'global.')) {
$variable = Str::after($environment_variable, 'global.');

View File

@ -16,31 +16,7 @@ public function __construct(
public Service $service,
public string $complexStatus = 'exited',
) {
$foundRunning = false;
$isDegraded = false;
$applications = $service->applications;
$databases = $service->databases;
foreach ($applications as $application) {
if ($application->status === 'running') {
$foundRunning = true;
} else {
$isDegraded = true;
}
}
foreach ($databases as $database) {
if ($database->status === 'running') {
$foundRunning = true;
} else {
$isDegraded = true;
}
}
if ($foundRunning && !$isDegraded) {
$this->complexStatus = 'running';
} else if ($foundRunning && $isDegraded) {
$this->complexStatus = 'degraded';
} else if (!$foundRunning && $isDegraded) {
$this->complexStatus = 'exited';
}
$this->complexStatus = serviceStatus($service);
}
/**

View File

@ -208,3 +208,32 @@ function replaceVariables($variable)
{
return $variable->replaceFirst('$', '')->replaceFirst('{', '')->replaceLast('}', '');
}
function serviceStatus(Service $service)
{
$foundRunning = false;
$isDegraded = false;
$applications = $service->applications;
$databases = $service->databases;
foreach ($applications as $application) {
if ($application->status === 'running') {
$foundRunning = true;
} else {
$isDegraded = true;
}
}
foreach ($databases as $database) {
if ($database->status === 'running') {
$foundRunning = true;
} else {
$isDegraded = true;
}
}
if ($foundRunning && !$isDegraded) {
return 'running';
} else if ($foundRunning && $isDegraded) {
return 'degraded';
} else if (!$foundRunning && $isDegraded) {
return 'exited';
}
}

View File

@ -0,0 +1,31 @@
<div class="navbar-main">
<a class="{{ request()->routeIs('project.service') ? 'text-white' : '' }}"
href="{{ route('project.service', $parameters) }}">
<button>Configuration</button>
</a>
<div class="flex-1"></div>
{{-- <x-applications.links :application="$application" />
<x-applications.advanced :application="$application" /> --}}
@if (serviceStatus($service) !== 'exited')
<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">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"></path>
<path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"></path>
</svg>
Stop
</button>
@else
<button wire:click='deploy' onclick="startService.showModal()"
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-warning" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M7 4v16l13 -8z" />
</svg>
Deploy
</button>
@endif
</div>

View File

@ -1,16 +1,19 @@
<div x-init="$wire.check_status">
<livewire:project.service.modal />
<h1>Configuration</h1>
<x-resources.breadcrumbs :resource="$service" :parameters="$parameters" />
<x-services.navbar :service="$service" :parameters="$parameters" />
<h3>Applications</h3>
@foreach ($service->applications as $application)
<form wire:submit.prevent='submit'>
<p>{{ $application->name }}</p>
<p>{{ $application->status }}</p>
<x-forms.input id="services.{{$application->name}}.fqdn"></x-forms.input>
<x-forms.button type="submit">Save</x-forms.button>
</form>
<form class="box" wire:submit.prevent='submit'>
<p>{{ $application->name }}</p>
<x-forms.input id="services.{{ $application->name }}.fqdn"></x-forms.input>
<x-forms.button type="submit">Save</x-forms.button>
</form>
@endforeach
<h3>Databases</h3>
@if ($service->databases->count() > 0)
<h3>Databases</h3>
@endif
@foreach ($service->databases as $database)
<p>{{ $database->name }}</p>
<p>{{ $database->status }}</p>
@ -19,8 +22,4 @@
@foreach ($service->environment_variables as $variable)
<p>{{ $variable->key }}={{ $variable->value }}</p>
@endforeach
<x-forms.button wire:click='deploy'>Deploy</x-forms.button>
<div class="container w-full py-10 mx-auto">
<livewire:activity-monitor header="Service Startup Logs" />
</div>
</div>

View File

@ -0,0 +1,12 @@
<div>
<x-modal submitWireAction="serviceStatusUpdated" modalId="startService">
<x-slot:modalBody>
<livewire:activity-monitor header="Service Startup Logs" />
</x-slot:modalBody>
<x-slot:modalSubmit>
<x-forms.button onclick="startService.close()" type="submit">
Close
</x-forms.button>
</x-slot:modalSubmit>
</x-modal>
</div>