command center

This commit is contained in:
Andras Bacsai 2023-05-04 10:00:08 +02:00
parent 135f9ab048
commit b8b0d2243f
7 changed files with 30 additions and 91 deletions

View File

@ -8,51 +8,24 @@ use Livewire\Component;
class RunCommand extends Component class RunCommand extends Component
{ {
public $activity; public $command;
public $isKeepAliveOn = false;
public $manualKeepAlive = false;
public $command = 'ls';
public $server; public $server;
public $servers = []; public $servers = [];
protected $rules = [ protected $rules = [
'server' => 'required', 'server' => 'required',
'command' => 'required',
]; ];
public function mount() public function mount()
{ {
$this->servers = Server::all(); $this->servers = Server::where('team_id', session('currentTeam')->id)->get();
$this->server = $this->servers[0]->uuid; $this->server = $this->servers[0]->uuid;
} }
public function runCommand() public function runCommand()
{ {
$this->isKeepAliveOn = true; $this->validate();
$this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value); $activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
} $this->emit('newMonitorActivity', $activity->id);
public function runSleepingBeauty()
{
$this->isKeepAliveOn = true;
$this->activity = remoteProcess(['x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
}
public function runDummyProjectBuild()
{
$this->isKeepAliveOn = true;
$this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
}
public function polling()
{
$this->activity?->refresh();
if (data_get($this->activity, 'properties.exitCode') !== null) {
$this->isKeepAliveOn = false;
}
} }
} }

View File

@ -1,32 +1,19 @@
@props([ @props([
'id' => null, 'id' => null,
'type' => 'text',
'required' => false, 'required' => false,
'readonly' => false, 'readonly' => false,
'label' => null, 'label' => null,
'type' => 'text',
'class' => '',
'instantSave' => false, 'instantSave' => false,
'disabled' => false, 'disabled' => false,
'hidden' => false, 'hidden' => false,
]) ])
@if ($type === 'checkbox')
<label for={{ $id }}> <span @class([
@if ($label) 'flex justify-end' => $type === 'checkbox',
{{ $label }} 'flex flex-col' => $type !== 'checkbox',
@else ])>
{{ $id }}
@endif
@if ($required)
*
@endif
<input type="checkbox" id={{ $id }}
@if ($instantSave) wire:click='instantSave' wire:model.defer={{ $id }} @else wire:model.defer={{ $id }} @endif>
</label>
@error($id)
<span class="text-red-500">{{ $message }}</span>
@enderror
@else
<label for={{ $id }}> <label for={{ $id }}>
@if ($label) @if ($label)
{{ $label }} {{ $label }}
@ -38,17 +25,13 @@
@endif @endif
</label> </label>
@if ($type === 'textarea') @if ($type === 'textarea')
<textarea class={{ $class }} type={{ $type }} id={{ $id }} <textarea {{ $attributes }} type={{ $type }} id={{ $id }} wire:model.defer={{ $id }}></textarea>
wire:model.defer={{ $id }} @if ($required) required @endif
@if ($disabled) disabled @endif @if ($readonly) readOnly disabled @endif></textarea>
@else @else
<input class={{ $class }} type={{ $type }} id={{ $id }} <input {{ $attributes }} type={{ $type }} id={{ $id }}
wire:model.defer={{ $id }} @if ($required) required @endif @if ($instantSave) wire:click='instantSave' wire:model.defer={{ $id }} @else wire:model.defer={{ $id }} @endif />
@if ($disabled) disabled @endif
@if ($readonly) readOnly disabled @endif />
@endif @endif
@error($id) @error($id)
<div class="text-red-500">{{ $message }}</div> <div class="text-red-500">{{ $message }}</div>
@enderror @enderror
@endif </span>

View File

@ -2,9 +2,7 @@
<div>v{{ config('coolify.version') }}</div> <div>v{{ config('coolify.version') }}</div>
@auth @auth
<a href="/">Home</a> <a href="/">Home</a>
@env('local') <a href="/command-center">Command Center</a>
<a href="/demo">Demo</a>
@endenv
<a href="/profile">Profile</a> <a href="/profile">Profile</a>
@if (auth()->user()->isRoot()) @if (auth()->user()->isRoot())
<a href="/settings">Settings</a> <a href="/settings">Settings</a>

View File

@ -1,6 +1,5 @@
<div> <div>
@isset($this->activity) @isset($this->activity)
<span>Activity: {{ $this->activity?->id }}</span>
<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-scroll"
@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>

View File

@ -1,26 +1,12 @@
<div> <div>
<div> <form class="flex gap-2" wire:submit.prevent='runCommand'>
<label for="command"> <x-inputs.input autofocus id="command" label="Command" required />
<input autofocus id="command" wire:model.defer="command" type="text" wire:keydown.enter="runCommand" />
<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>
@endforeach @endforeach
</select> </select>
</label> <x-inputs.button type="submit">Run</x-inputs.button>
<x-inputs.button wire:click="runCommand">Run command</x-inputs.button> </form>
<x-inputs.button wire:click="runSleepingBeauty">Run sleeping beauty</x-inputs.button> <livewire:activity-monitor />
<x-inputs.button wire:click="runDummyProjectBuild">Build DummyProject</x-inputs.button>
</div>
<div>
<input id="manualKeepAlive" name="manualKeepAlive" type="checkbox" wire:model="manualKeepAlive">
<label for="manualKeepAlive">Real-time logs</label>
@if ($isKeepAliveOn || $manualKeepAlive)
Polling...
@endif
</div>
@isset($activity?->id)
<pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>{{ \App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($activity) }}</pre>
@endisset
</div> </div>

View File

@ -60,9 +60,9 @@ Route::middleware(['auth'])->group(function () {
return view('update'); return view('update');
})->name('update'); })->name('update');
Route::get('/demo', function () { Route::get('/command-center', function () {
return view('demo'); return view('command-center');
})->name('demo'); })->name('command-center');
}); });
Route::middleware(['auth'])->group(function () { Route::middleware(['auth'])->group(function () {