This commit is contained in:
Andras Bacsai 2023-05-08 09:16:50 +02:00
parent 117ba360ac
commit 5ed91c05bf
16 changed files with 54 additions and 22 deletions

View File

@ -20,7 +20,7 @@ public function __construct(
public string $type, public string $type,
public ?string $type_uuid = null, public ?string $type_uuid = null,
public ?Model $model = null, public ?Model $model = null,
public string $status = ProcessStatus::HOLDING->value, public string $status = ProcessStatus::QUEUED->value,
) { ) {
} }
} }

View File

@ -4,7 +4,7 @@
enum ProcessStatus: string enum ProcessStatus: string
{ {
case HOLDING = 'holding'; case QUEUED = 'queued';
case IN_PROGRESS = 'in_progress'; case IN_PROGRESS = 'in_progress';
case FINISHED = 'finished'; case FINISHED = 'finished';
case ERROR = 'error'; case ERROR = 'error';

View File

@ -2,6 +2,7 @@
namespace App\Http\Livewire; namespace App\Http\Livewire;
use App\Enums\ProcessStatus;
use Livewire\Component; use Livewire\Component;
use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Models\Activity;
@ -31,12 +32,24 @@ public function newMonitorActivity($activityId)
public function polling() public function polling()
{ {
$this->hydrateActivity(); $this->hydrateActivity();
$this->setStatus(ProcessStatus::IN_PROGRESS);
if (data_get($this->activity, 'properties.exitCode') !== null) { $exit_code = data_get($this->activity, 'properties.exitCode');
if ($exit_code !== null) {
if ($exit_code === 0) {
$this->setStatus(ProcessStatus::FINISHED);
} else {
$this->setStatus(ProcessStatus::ERROR);
}
$this->isPollingActive = false; $this->isPollingActive = false;
} }
} }
protected function setStatus($status)
{
$this->activity->properties = $this->activity->properties->merge([
'status' => $status,
]);
$this->activity->save();
}
public function render() public function render()
{ {
return view('livewire.activity-monitor'); return view('livewire.activity-monitor');

View File

@ -26,7 +26,7 @@ public function mount()
if (request()->query('server_id')) { if (request()->query('server_id')) {
$this->server_id = request()->query('server_id'); $this->server_id = request()->query('server_id');
} else { } else {
$this->server_id = Server::first()->id; $this->server_id = Server::validated()->first()->id;
} }
$this->network = new Cuid2(7); $this->network = new Cuid2(7);
$this->name = generateRandomName(); $this->name = generateRandomName();

View File

@ -20,10 +20,11 @@ class Form extends Component
'server.ip' => 'required', 'server.ip' => 'required',
'server.user' => 'required', 'server.user' => 'required',
'server.port' => 'required', 'server.port' => 'required',
'server.settings.is_validated' => 'required'
]; ];
public function mount() public function mount()
{ {
$this->server = Server::find($this->server_id); $this->server = Server::find($this->server_id)->load(['settings']);
} }
public function installDocker() public function installDocker()
{ {
@ -38,6 +39,11 @@ public function checkServer()
if (!$this->uptime) { if (!$this->uptime) {
$this->uptime = 'Server not reachable.'; $this->uptime = 'Server not reachable.';
throw new \Exception('Server not reachable.'); throw new \Exception('Server not reachable.');
} else {
if (!$this->server->settings->is_validated) {
$this->server->settings->is_validated = true;
$this->server->settings->save();
}
} }
$this->dockerVersion = instantRemoteProcess(['docker version|head -2|grep -i version'], $this->server, false); $this->dockerVersion = instantRemoteProcess(['docker version|head -2|grep -i version'], $this->server, false);
if (!$this->dockerVersion) { if (!$this->dockerVersion) {

View File

@ -52,4 +52,9 @@ public function settings()
{ {
return $this->hasOne(ServerSetting::class); return $this->hasOne(ServerSetting::class);
} }
static public function validated()
{
return Server::where('team_id', session('currentTeam')->id)->whereRelation('settings', 'is_validated', true)->get();
}
} }

View File

@ -15,6 +15,7 @@ public function up(): void
$table->id(); $table->id();
$table->string('uuid')->unique(); $table->string('uuid')->unique();
$table->boolean('is_build_server')->default(false); $table->boolean('is_build_server')->default(false);
$table->boolean('is_validated')->default(false);
$table->foreignId('server_id'); $table->foreignId('server_id');
$table->timestamps(); $table->timestamps();

View File

@ -15,11 +15,12 @@ public function run(): void
{ {
$server_2 = Server::find(1)->load(['settings']); $server_2 = Server::find(1)->load(['settings']);
$server_2->settings->is_build_server = true; $server_2->settings->is_build_server = true;
$server_2->settings->is_validated = true;
$server_2->settings->save(); $server_2->settings->save();
$server_3 = Server::find(2)->load(['settings']); $server_3 = Server::find(2)->load(['settings']);
$server_3->settings->is_build_server = true; $server_3->settings->is_build_server = false;
$server_3->settings->is_validated = false;
$server_3->settings->save(); $server_3->settings->save();
} }
} }

View File

@ -1,8 +1,8 @@
@props([ @props([
'isWarning' => null, 'isWarning' => null,
'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 w-28 h-6', 'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 h-8',
'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 w-28 h-6', 'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 h-8',
'loadingClass' => 'text-black bg-green-500 w-28 h-6', 'loadingClass' => 'text-black bg-green-500 h-8',
'confirm' => null, 'confirm' => null,
'confirmAction' => null, 'confirmAction' => null,
]) ])

View File

@ -9,7 +9,7 @@
]) ])
<span @class([ <span @class([
'flex justify-end' => $type === 'checkbox', 'flex' => $type === 'checkbox',
'flex flex-col' => $type !== 'checkbox', 'flex flex-col' => $type !== 'checkbox',
])> ])>
@if (!$noLabel) @if (!$noLabel)

View File

@ -1,7 +1,9 @@
<div> <div>
@isset($this->activity) @isset($this->activity)
<span>Status: {{ $this->activity?->properties->get('status') }}</span> <span>Status: {{ $this->activity?->properties->get('status') }}</span>
<pre class="flex flex-col-reverse w-full overflow-y-scroll" <pre class="flex flex-col-reverse w-full overflow-y-hidden"
@if ($isPollingActive) wire:poll.750ms="polling" @endif>{{ \App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($this->activity) }}</pre> @if ($isPollingActive) wire:poll.750ms="polling" @endif>{{ \App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($this->activity) }}</pre>
@else
<span>Output will be here...</span>
@endisset @endisset
</div> </div>

View File

@ -1,6 +1,6 @@
<div> <div>
<x-inputs.button class="w-32 text-white bg-neutral-800 hover:bg-violet-600" wire:click='checkUpdate' type="submit"> <x-inputs.button wire:click='checkUpdate' type="submit">
Check for updates</x-inputs.button> Check Update</x-inputs.button>
@if ($updateAvailable) @if ($updateAvailable)
Update available Update available
@endif @endif

View File

@ -1,5 +1,5 @@
<div> <div>
<a @if ($status === 'in_progress' || $status === 'holding') wire:poll='polling' @endif href="{{ url()->current() }}/{{ $deployment_uuid }}"> <a @if ($status === 'in_progress' || $status === 'queued') wire:poll='polling' @endif href="{{ url()->current() }}/{{ $deployment_uuid }}">
{{ $created_at }} {{ $created_at }}
{{ $deployment_uuid }}</a> {{ $deployment_uuid }}</a>
{{ $status }} {{ $status }}

View File

@ -1,6 +1,6 @@
<div> <div>
<form class="flex gap-2" wire:submit.prevent='runCommand'> <form class="flex items-end justify-center gap-2" wire:submit.prevent='runCommand'>
<x-inputs.input autofocus id="command" label="Command" required /> <x-inputs.input noDirty noLabel autofocus id="command" label="Command" required />
<select wire:model.defer="server"> <select wire:model.defer="server">
@foreach ($servers as $server) @foreach ($servers as $server)
<option value="{{ $server->uuid }}">{{ $server->name }}</option> <option value="{{ $server->uuid }}">{{ $server->name }}</option>
@ -8,5 +8,7 @@
</select> </select>
<x-inputs.button type="submit">Run</x-inputs.button> <x-inputs.button type="submit">Run</x-inputs.button>
</form> </form>
<div class="container w-full pt-10 mx-auto">
<livewire:activity-monitor /> <livewire:activity-monitor />
</div> </div>
</div>

View File

@ -18,7 +18,7 @@
@endif @endif
</div> </div>
</div> </div>
<div> <div class="flex">
<x-inputs.button type="submit">Submit</x-inputs.button> <x-inputs.button type="submit">Submit</x-inputs.button>
<x-inputs.button wire:click.prevent='checkServer'>Check Server</x-inputs.button> <x-inputs.button wire:click.prevent='checkServer'>Check Server</x-inputs.button>
<x-inputs.button wire:click.prevent='installDocker'>Install Docker</x-inputs.button> <x-inputs.button wire:click.prevent='installDocker'>Install Docker</x-inputs.button>
@ -26,7 +26,9 @@
Delete Delete
</x-inputs.button> </x-inputs.button>
</div> </div>
<x-inputs.input class="" disabled type="checkbox" id="server.settings.is_validated" label="Validated" />
</form> </form>
@isset($uptime) @isset($uptime)
<p>Uptime: {{ $uptime }}</p> <p>Uptime: {{ $uptime }}</p>
@endisset @endisset

View File

@ -93,7 +93,7 @@
Route::middleware(['auth'])->group(function () { Route::middleware(['auth'])->group(function () {
Route::get('/destination/new', function () { Route::get('/destination/new', function () {
$servers = Server::where('team_id', session('currentTeam')->id)->get(); $servers = Server::validated();
return view('destination.new', [ return view('destination.new', [
"servers" => $servers, "servers" => $servers,
]); ]);