Skip to content

Commit

Permalink
Merge pull request #3463 from coollabsio/next
Browse files Browse the repository at this point in the history
v4.0.0-beta.388
  • Loading branch information
andrasbacsai authored Sep 17, 2024
2 parents b2bab45 + 8967315 commit 6f57885
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 145 deletions.
101 changes: 0 additions & 101 deletions app/Livewire/RunCommand.php

This file was deleted.

55 changes: 55 additions & 0 deletions app/Livewire/Terminal/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Expand Down
2 changes: 1 addition & 1 deletion config/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

return '4.0.0-beta.337';
return '4.0.0-beta.338';
4 changes: 2 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ services:
retries: 10
timeout: 2s
soketi:
image: 'ghcr.io/coollabsio/coolify-realtime:1.0.0'
image: 'ghcr.io/coollabsio/coolify-realtime:1.0.1'
ports:
- "${SOKETI_PORT:-6001}:6001"
- "6002:6002"
Expand All @@ -123,7 +123,7 @@ services:
SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"
SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:6001/ready && wget -qO- http://127.0.0.1:6002/ready || exit 1"]
test: [ "CMD-SHELL", "wget -qO- http://127.0.0.1:6001/ready && wget -qO- http://127.0.0.1:6002/ready || exit 1" ]
interval: 5s
retries: 10
timeout: 2s
Expand Down
1 change: 0 additions & 1 deletion docker/coolify-realtime/terminal-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ async function handleCommand(ws, command, userId) {
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
};

// NOTE: - Initiates a process within the Terminal container
Expand Down
4 changes: 2 additions & 2 deletions other/nightly/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ services:
retries: 10
timeout: 2s
soketi:
image: 'ghcr.io/coollabsio/coolify-realtime:1.0.0'
image: 'ghcr.io/coollabsio/coolify-realtime:1.0.1'
ports:
- "${SOKETI_PORT:-6001}:6001"
- "6002:6002"
Expand All @@ -123,7 +123,7 @@ services:
SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"
SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:6001/ready && wget -qO- http://127.0.0.1:6002/ready || exit 1"]
test: [ "CMD-SHELL", "wget -qO- http://127.0.0.1:6001/ready && wget -qO- http://127.0.0.1:6002/ready || exit 1" ]
interval: 5s
retries: 10
timeout: 2s
Expand Down
6 changes: 3 additions & 3 deletions other/nightly/versions.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
10 changes: 8 additions & 2 deletions resources/views/livewire/project/shared/terminal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ function initializeWebSocket() {
socket.onerror = (e) => {
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);
};
}
}
Expand Down Expand Up @@ -209,8 +215,8 @@ function checkIfProcessIsRunningAndKillIt() {
term.resize(termWidth, termHeight);
socket.send(JSON.stringify({
resize: {
cols: termWidth,
rows: termHeight
cols: 600,
rows: 600
}
}));
}
Expand Down
22 changes: 0 additions & 22 deletions resources/views/livewire/run-command.blade.php

This file was deleted.

30 changes: 23 additions & 7 deletions resources/views/livewire/terminal/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,27 @@
<x-helper
helper="If you're having trouble connecting to your server, make sure that the port is open.<br><br><a class='underline' href='https://coolify.io/docs/knowledge-base/server/firewall/#terminal' target='_blank'>Documentation</a>"></x-helper>
</div>
@if ($servers->count() > 0)
<livewire:run-command :servers="$servers" />
@else
<div>
<div>No servers found. Without a server, you won't be able to do much.</div>
</div>
@endif
<div>
<form class="flex flex-col gap-2 justify-center xl:items-end xl:flex-row"
wire:submit="$dispatchSelf('connectToContainer')">
<x-forms.select id="server" required wire:model.live="selected_uuid">
@foreach ($servers as $server)
@if ($loop->first)
<option disabled value="default">Select a server or container</option>
@endif
<option value="{{ $server->uuid }}">{{ $server->name }}</option>
@foreach ($containers as $container)
@if ($container['server_uuid'] == $server->uuid)
<option value="{{ $container['uuid'] }}">
{{ $server->name }} -> {{ $container['name'] }}
</option>
@endif
@endforeach
@endforeach
</x-forms.select>
<x-forms.button type="submit">Connect</x-forms.button>
</form>
<livewire:project.shared.terminal />
</div>

</div>
6 changes: 3 additions & 3 deletions versions.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 6f57885

Please sign in to comment.