fix(ui):show error on terminal if container has no shell (bash/sh)

This commit is contained in:
peaklabs-dev
2025-01-21 18:36:38 +01:00
parent 43a4d9b467
commit 31992f4d02
3 changed files with 64 additions and 36 deletions

View File

@@ -27,6 +27,8 @@ class ExecuteContainerCommand extends Component
public Collection $servers;
public bool $hasShell = true;
protected $rules = [
'server' => 'required',
'container' => 'required',
@@ -141,6 +143,16 @@ class ExecuteContainerCommand extends Component
}
}
private function checkShellAvailability(Server $server, string $container): bool
{
$escapedContainer = escapeshellarg($container);
$result = instant_remote_process([
"docker exec {$escapedContainer} which bash || docker exec {$escapedContainer} which sh",
], $server, false);
return ! empty($result);
}
#[On('connectToServer')]
public function connectToServer()
{
@@ -148,6 +160,7 @@ class ExecuteContainerCommand extends Component
if ($this->server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
}
$this->hasShell = true;
$this->dispatch(
'send-terminal-command',
false,
@@ -201,6 +214,11 @@ class ExecuteContainerCommand extends Component
throw new \RuntimeException('Server ownership verification failed.');
}
$this->hasShell = $this->checkShellAvailability($server, data_get($container, 'container.Names'));
if (! $this->hasShell) {
return;
}
$this->dispatch(
'send-terminal-command',
true,