Add run command of predefined server
This commit is contained in:
parent
f7c615c958
commit
789b699556
@ -14,6 +14,8 @@ class RunCommand extends Component
|
|||||||
|
|
||||||
public $command = 'ls';
|
public $command = 'ls';
|
||||||
|
|
||||||
|
public $server = 'testing-host';
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.run-command');
|
return view('livewire.run-command');
|
||||||
@ -23,14 +25,14 @@ public function runCommand()
|
|||||||
{
|
{
|
||||||
$this->isKeepAliveOn = true;
|
$this->isKeepAliveOn = true;
|
||||||
|
|
||||||
$this->activity = remoteProcess($this->command, 'testing-host');
|
$this->activity = remoteProcess($this->command, $this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runSleepingBeauty()
|
public function runSleepingBeauty()
|
||||||
{
|
{
|
||||||
$this->isKeepAliveOn = true;
|
$this->isKeepAliveOn = true;
|
||||||
|
|
||||||
$this->activity = remoteProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', 'testing-host');
|
$this->activity = remoteProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', $this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runDummyProjectBuild()
|
public function runDummyProjectBuild()
|
||||||
@ -40,7 +42,7 @@ public function runDummyProjectBuild()
|
|||||||
$this->activity = remoteProcess(<<<EOT
|
$this->activity = remoteProcess(<<<EOT
|
||||||
cd projects/dummy-project
|
cd projects/dummy-project
|
||||||
~/.docker/cli-plugins/docker-compose build --no-cache
|
~/.docker/cli-plugins/docker-compose build --no-cache
|
||||||
EOT, 'testing-host');
|
EOT, $this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function polling()
|
public function polling()
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
use App\Actions\RemoteProcess\DispatchRemoteProcess;
|
use App\Actions\RemoteProcess\DispatchRemoteProcess;
|
||||||
use App\Data\RemoteProcessArgs;
|
use App\Data\RemoteProcessArgs;
|
||||||
|
use App\Models\Server;
|
||||||
use Spatie\Activitylog\Contracts\Activity;
|
use Spatie\Activitylog\Contracts\Activity;
|
||||||
|
|
||||||
if (! function_exists('remoteProcess')) {
|
if (!function_exists('remoteProcess')) {
|
||||||
/**
|
/**
|
||||||
* Run a Coolify Process, which SSH's asynchronously into a machine to run the command(s).
|
* Run a Coolify Process, which SSH's asynchronously into a machine to run the command(s).
|
||||||
* @TODO Change 'root' to 'coolify' when it's able to run Docker commands without sudo
|
* @TODO Change 'root' to 'coolify' when it's able to run Docker commands without sudo
|
||||||
@ -12,17 +13,22 @@
|
|||||||
*/
|
*/
|
||||||
function remoteProcess(
|
function remoteProcess(
|
||||||
string $command,
|
string $command,
|
||||||
string $destination,
|
string $destination
|
||||||
?int $port = 22,
|
): Activity {
|
||||||
?string $user = 'root',
|
$found_server = Server::where('name', $destination)->first();
|
||||||
): Activity
|
if (!$found_server) {
|
||||||
{
|
throw new \RuntimeException('Server not found.');
|
||||||
|
}
|
||||||
|
$found_team = auth()->user()->teams->pluck('id')->contains($found_server->team_id);
|
||||||
|
if (!$found_team) {
|
||||||
|
throw new \RuntimeException('You do not have access to this server.');
|
||||||
|
}
|
||||||
return resolve(DispatchRemoteProcess::class, [
|
return resolve(DispatchRemoteProcess::class, [
|
||||||
'remoteProcessArgs' => new RemoteProcessArgs(
|
'remoteProcessArgs' => new RemoteProcessArgs(
|
||||||
destination: $destination,
|
destination: $found_server->ip,
|
||||||
command: $command,
|
command: $command,
|
||||||
port: $port,
|
port: $found_server->port,
|
||||||
user: $user,
|
user: $found_server->user,
|
||||||
),
|
),
|
||||||
])();
|
])();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<label for="command">
|
<label for="command">
|
||||||
<input autofocus class="py-2 rounded ring-1" id="command" wire:model="command" type="text"
|
<input autofocus id="command" wire:model="command" type="text" wire:keydown.enter="runCommand" />
|
||||||
wire:keydown.enter="runCommand" />
|
<input id="command" wire:model="server" type="text" />
|
||||||
</label>
|
</label>
|
||||||
<button wire:click="runCommand">Run command</button>
|
<button wire:click="runCommand">Run command</button>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user