Merge branch 'next' into fix-ssh-keys

This commit is contained in:
Andras Bacsai
2024-09-19 11:45:12 +02:00
committed by GitHub
70 changed files with 1693 additions and 498 deletions

View File

@@ -4,6 +4,8 @@ namespace App\Livewire\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
class Delete extends Component
{
@@ -11,8 +13,12 @@ class Delete extends Component
public $server;
public function delete()
public function delete($password)
{
if (!Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return;
}
try {
$this->authorize('delete', $this->server);
if ($this->server->hasDefinedResources()) {

View File

@@ -7,6 +7,8 @@ use App\Actions\Proxy\StartProxy;
use App\Events\ProxyStatusChanged;
use App\Models\Server;
use Livewire\Component;
use Illuminate\Support\Facades\Process;
use Illuminate\Process\InvokedProcess;
class Deploy extends Component
{
@@ -94,21 +96,43 @@ class Deploy extends Component
public function stop(bool $forceStop = true)
{
try {
if ($this->server->isSwarm()) {
instant_remote_process([
'docker service rm coolify-proxy_traefik',
], $this->server);
} else {
instant_remote_process([
'docker rm -f coolify-proxy',
], $this->server);
$containerName = $this->server->isSwarm() ? 'coolify-proxy_traefik' : 'coolify-proxy';
$timeout = 30;
$process = $this->stopContainer($containerName, $timeout);
$startTime = time();
while ($process->running()) {
if (time() - $startTime >= $timeout) {
$this->forceStopContainer($containerName);
break;
}
usleep(100000);
}
$this->server->proxy->status = 'exited';
$this->server->proxy->force_stop = $forceStop;
$this->server->save();
$this->dispatch('proxyStatusUpdated');
$this->removeContainer($containerName);
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
$this->server->proxy->force_stop = $forceStop;
$this->server->proxy->status = 'exited';
$this->server->save();
$this->dispatch('proxyStatusUpdated');
}
}
private function stopContainer(string $containerName, int $timeout): InvokedProcess
{
return Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
}
private function forceStopContainer(string $containerName)
{
instant_remote_process(["docker kill $containerName"], $this->server, throwError: false);
}
private function removeContainer(string $containerName)
{
instant_remote_process(["docker rm -f $containerName"], $this->server, throwError: false);
}
}