2023-03-20 12:04:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
2023-03-24 21:15:36 +00:00
|
|
|
use App\Models\Server;
|
2023-03-20 12:04:22 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class RunCommand extends Component
|
|
|
|
{
|
|
|
|
public $activity;
|
|
|
|
|
|
|
|
public $isKeepAliveOn = false;
|
|
|
|
|
|
|
|
public $manualKeepAlive = false;
|
|
|
|
|
2023-03-20 14:04:35 +00:00
|
|
|
public $command = 'ls';
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-03-28 13:47:37 +00:00
|
|
|
public $server;
|
2023-03-24 14:48:57 +00:00
|
|
|
|
2023-03-24 21:15:36 +00:00
|
|
|
public $servers = [];
|
|
|
|
|
2023-03-29 10:27:02 +00:00
|
|
|
protected $rules = [
|
|
|
|
'server' => 'required',
|
|
|
|
];
|
2023-03-24 21:15:36 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-03-29 10:27:02 +00:00
|
|
|
$this->servers = Server::all();
|
|
|
|
$this->server = $this->servers[0]->uuid;
|
2023-03-24 21:15:36 +00:00
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
|
|
|
|
public function runCommand()
|
|
|
|
{
|
2023-03-20 14:04:35 +00:00
|
|
|
$this->isKeepAliveOn = true;
|
2023-03-29 10:27:02 +00:00
|
|
|
$this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first());
|
2023-03-20 12:04:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:29:03 +00:00
|
|
|
public function runSleepingBeauty()
|
|
|
|
{
|
|
|
|
$this->isKeepAliveOn = true;
|
2023-03-29 10:27:02 +00:00
|
|
|
$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());
|
2023-03-20 14:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function runDummyProjectBuild()
|
|
|
|
{
|
|
|
|
$this->isKeepAliveOn = true;
|
2023-03-29 10:27:02 +00:00
|
|
|
$this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first());
|
2023-03-20 14:29:03 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 12:04:22 +00:00
|
|
|
public function polling()
|
|
|
|
{
|
|
|
|
$this->activity?->refresh();
|
|
|
|
|
2023-03-20 14:04:35 +00:00
|
|
|
if (data_get($this->activity, 'properties.exitCode') !== null) {
|
2023-03-20 12:04:22 +00:00
|
|
|
$this->isKeepAliveOn = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|