fix(ui):show error on terminal if container has no shell (bash/sh)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user