diff --git a/app/Livewire/RunCommand.php b/app/Livewire/RunCommand.php deleted file mode 100644 index 290618befe..0000000000 --- a/app/Livewire/RunCommand.php +++ /dev/null @@ -1,101 +0,0 @@ -servers = $servers; - $this->containers = $this->getAllActiveContainers(); - } - - private function getAllActiveContainers() - { - return collect($this->servers)->flatMap(function ($server) { - if (! $server->isFunctional()) { - return []; - } - - return $server->definedResources() - ->filter(function ($resource) { - $status = method_exists($resource, 'realStatus') ? $resource->realStatus() : (method_exists($resource, 'status') ? $resource->status() : 'exited'); - - return str_starts_with($status, 'running:'); - }) - ->map(function ($resource) use ($server) { - if (isDev()) { - if (data_get($resource, 'name') === 'coolify-db') { - $container_name = 'coolify-db'; - - return [ - 'name' => $resource->name, - 'connection_name' => $container_name, - 'uuid' => $resource->uuid, - 'status' => 'running', - 'server' => $server, - 'server_uuid' => $server->uuid, - ]; - } - } - - if (class_basename($resource) === 'Application') { - if (! $server->isSwarm()) { - $current_containers = getCurrentApplicationContainerStatus($server, $resource->id, includePullrequests: true); - } - $status = $resource->status; - } elseif (class_basename($resource) === 'Service') { - $current_containers = getCurrentServiceContainerStatus($server, $resource->id); - $status = $resource->status(); - } else { - $status = getContainerStatus($server, $resource->uuid); - if ($status === 'running') { - $current_containers = collect([ - 'Names' => $resource->name, - ]); - } - } - if ($server->isSwarm()) { - $container_name = $resource->uuid.'_'.$resource->uuid; - } else { - $container_name = data_get($current_containers->first(), 'Names'); - } - - return [ - 'name' => $resource->name, - 'connection_name' => $container_name, - 'uuid' => $resource->uuid, - 'status' => $status, - 'server' => $server, - 'server_uuid' => $server->uuid, - ]; - }); - }); - } - - public function updatedSelectedUuid($value) - { - $this->connectToContainer(); - } - - #[On('connectToContainer')] - public function connectToContainer() - { - $container = collect($this->containers)->firstWhere('uuid', $this->selected_uuid); - - $this->dispatch('send-terminal-command', - isset($container), - $container['connection_name'] ?? $this->selected_uuid, - $container['server_uuid'] ?? $this->selected_uuid - ); - } -} diff --git a/app/Livewire/Terminal/Index.php b/app/Livewire/Terminal/Index.php index 3f777a8ffb..945b25714e 100644 --- a/app/Livewire/Terminal/Index.php +++ b/app/Livewire/Terminal/Index.php @@ -3,15 +3,70 @@ namespace App\Livewire\Terminal; use App\Models\Server; +use Livewire\Attributes\On; use Livewire\Component; class Index extends Component { + public $selected_uuid = 'default'; + public $servers = []; + public $containers = []; + public function mount() { + if (! auth()->user()->isAdmin()) { + abort(403); + } $this->servers = Server::isReachable()->get(); + $this->containers = $this->getAllActiveContainers(); + } + + private function getAllActiveContainers() + { + return collect($this->servers)->flatMap(function ($server) { + if (! $server->isFunctional()) { + return []; + } + + return $server->loadAllContainers()->map(function ($container) use ($server) { + $state = data_get_str($container, 'State')->lower(); + if ($state->contains('running')) { + return [ + 'name' => data_get($container, 'Names'), + 'connection_name' => data_get($container, 'Names'), + 'uuid' => data_get($container, 'Names'), + 'status' => data_get_str($container, 'State')->lower(), + 'server' => $server, + 'server_uuid' => $server->uuid, + ]; + } + + return null; + })->filter(); + }); + } + + public function updatedSelectedUuid() + { + $this->connectToContainer(); + } + + #[On('connectToContainer')] + public function connectToContainer() + { + if ($this->selected_uuid === 'default') { + $this->dispatch('error', 'Please select a server or a container.'); + + return; + } + $container = collect($this->containers)->firstWhere('uuid', $this->selected_uuid); + $this->dispatch('send-terminal-command', + isset($container), + $container['connection_name'] ?? $this->selected_uuid, + $container['server_uuid'] ?? $this->selected_uuid + ); } public function render() diff --git a/app/Models/Server.php b/app/Models/Server.php index 3a11c2206c..e2f52b4e18 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -775,6 +775,18 @@ public function getContainersWithSentinel(): Collection } } + public function loadAllContainers(): Collection + { + if ($this->isFunctional()) { + $containers = instant_remote_process(["docker ps -a --format '{{json .}}'"], $this); + $containers = format_docker_command_output_to_json($containers); + + return collect($containers); + } + + return collect([]); + } + public function loadUnmanagedContainers(): Collection { if ($this->isFunctional()) { diff --git a/config/sentry.php b/config/sentry.php index 8fb0e5cdd7..e112bf2608 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.337', + 'release' => '4.0.0-beta.338', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index aac06d60de..16bc6b80e0 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ { console.error('WebSocket error:', e); }; + socket.onclose = () => { + console.log('WebSocket connection closed'); + setInterval(() => { + $wire.dispatch('error', 'Connection to terminal lost, please refresh the page.'); + }, 2000); + }; } } @@ -209,8 +215,8 @@ function checkIfProcessIsRunningAndKillIt() { term.resize(termWidth, termHeight); socket.send(JSON.stringify({ resize: { - cols: termWidth, - rows: termHeight + cols: 600, + rows: 600 } })); } diff --git a/resources/views/livewire/run-command.blade.php b/resources/views/livewire/run-command.blade.php deleted file mode 100644 index 4330e94cfc..0000000000 --- a/resources/views/livewire/run-command.blade.php +++ /dev/null @@ -1,22 +0,0 @@ -
-
- - @foreach ($servers as $server) - @if ($loop->first) - - @endif - - @foreach ($containers as $container) - @if ($container['server_uuid'] == $server->uuid) - - @endif - @endforeach - @endforeach - - Connect -
- -
diff --git a/resources/views/livewire/terminal/index.blade.php b/resources/views/livewire/terminal/index.blade.php index e2f1c82e48..3572950022 100644 --- a/resources/views/livewire/terminal/index.blade.php +++ b/resources/views/livewire/terminal/index.blade.php @@ -8,11 +8,27 @@ - @if ($servers->count() > 0) - - @else -
-
No servers found. Without a server, you won't be able to do much.
-
- @endif +
+
+ + @foreach ($servers as $server) + @if ($loop->first) + + @endif + + @foreach ($containers as $container) + @if ($container['server_uuid'] == $server->uuid) + + @endif + @endforeach + @endforeach + + Connect +
+ +
+ diff --git a/versions.json b/versions.json index cf7d133430..d4cdd3886f 100644 --- a/versions.json +++ b/versions.json @@ -1,16 +1,16 @@ { "coolify": { "v4": { - "version": "4.0.0-beta.337" + "version": "4.0.0-beta.338" }, "nightly": { - "version": "4.0.0-beta.338" + "version": "4.0.0-beta.339" }, "helper": { "version": "1.0.1" }, "realtime": { - "version": "1.0.0" + "version": "1.0.1" } } } \ No newline at end of file