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-24 14:48:57 +00:00
|
|
|
public $server = 'testing-host';
|
|
|
|
|
2023-03-24 21:15:36 +00:00
|
|
|
public $servers = [];
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->servers = Server::all()->pluck('name')->toArray();
|
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.run-command');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function runCommand()
|
|
|
|
{
|
2023-03-20 14:04:35 +00:00
|
|
|
$this->isKeepAliveOn = true;
|
|
|
|
|
2023-03-24 14:48:57 +00:00
|
|
|
$this->activity = remoteProcess($this->command, $this->server);
|
2023-03-20 12:04:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:29:03 +00:00
|
|
|
public function runSleepingBeauty()
|
|
|
|
{
|
|
|
|
$this->isKeepAliveOn = true;
|
|
|
|
|
2023-03-24 14:48:57 +00:00
|
|
|
$this->activity = remoteProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', $this->server);
|
2023-03-20 14:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function runDummyProjectBuild()
|
|
|
|
{
|
|
|
|
$this->isKeepAliveOn = true;
|
|
|
|
|
2023-03-21 09:31:16 +00:00
|
|
|
$this->activity = remoteProcess(<<<EOT
|
2023-03-20 14:29:03 +00:00
|
|
|
cd projects/dummy-project
|
|
|
|
~/.docker/cli-plugins/docker-compose build --no-cache
|
2023-03-24 14:48:57 +00:00
|
|
|
EOT, $this->server);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|