@if ($resource?->additional_networks?->count() > 0)
@@ -76,7 +79,6 @@
@if ($resource->getMorphClass() === 'App\Models\Application' && data_get($resource, 'build_pack') !== 'dockercompose')
@if (count($networks) > 0)
Choose another server
-
(experimental)
@foreach ($networks as $network)
Date: Mon, 5 Aug 2024 16:09:49 +0200
Subject: [PATCH 48/59] chore: add pull_request image builds to GH actions
---
.github/workflows/development-build.yml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/.github/workflows/development-build.yml b/.github/workflows/development-build.yml
index 268b885ac..b30b191ba 100644
--- a/.github/workflows/development-build.yml
+++ b/.github/workflows/development-build.yml
@@ -6,6 +6,13 @@ on:
paths-ignore:
- .github/workflows/coolify-helper.yml
- docker/coolify-helper/Dockerfile
+ pull_request:
+ types:
+ - opened
+ branches-ignore: ["main", "v3"]
+ paths-ignore:
+ - .github/workflows/coolify-helper.yml
+ - docker/coolify-helper/Dockerfile
env:
REGISTRY: ghcr.io
From 2725a93bfdd6d0b0cb1f28953232210355531f09 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 16:44:50 +0200
Subject: [PATCH 49/59] fix: only run logdrain if necessary
---
app/Jobs/ServerCheckJob.php | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index 6b90c976c..3cdeb12bd 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -78,7 +78,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
return 'No containers found.';
}
GetContainersStatus::run($this->server, $this->containers, $containerReplicates);
- // $this->containerStatus();
$this->checkLogDrainContainer();
$this->checkSentinel();
}
@@ -163,7 +162,15 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
InstallLogDrain::dispatch($this->server);
}
} else {
- InstallLogDrain::dispatch($this->server);
+ if ($this->server->settings->is_logdrain_newrelic_enabled) {
+ InstallLogDrain::dispatch($this->server);
+ } elseif ($this->server->settings->is_logdrain_highlight_enabled) {
+ InstallLogDrain::dispatch($this->server);
+ } elseif ($this->server->settings->is_logdrain_axiom_enabled) {
+ InstallLogDrain::dispatch($this->server);
+ } elseif ($this->server->settings->is_logdrain_custom_enabled) {
+ InstallLogDrain::dispatch($this->server);
+ }
}
}
From ddb4b4d2155e84747924dc40a5e9e898441142d5 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 16:45:30 +0200
Subject: [PATCH 50/59] refactor: Simplify log drain installation in
ServerCheckJob
---
app/Jobs/ServerCheckJob.php | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index 3cdeb12bd..d78642a3f 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -162,15 +162,7 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
InstallLogDrain::dispatch($this->server);
}
} else {
- if ($this->server->settings->is_logdrain_newrelic_enabled) {
- InstallLogDrain::dispatch($this->server);
- } elseif ($this->server->settings->is_logdrain_highlight_enabled) {
- InstallLogDrain::dispatch($this->server);
- } elseif ($this->server->settings->is_logdrain_axiom_enabled) {
- InstallLogDrain::dispatch($this->server);
- } elseif ($this->server->settings->is_logdrain_custom_enabled) {
- InstallLogDrain::dispatch($this->server);
- }
+ InstallLogDrain::dispatch($this->server);
}
}
From 012d660886c3b9e276d1cb78231520a127fd8a19 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 18:16:29 +0200
Subject: [PATCH 51/59] fix: remove network if it is only connected to coolify
proxy itself
---
app/Console/Commands/Init.php | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index f397d8861..754b95e6b 100644
--- a/app/Console/Commands/Init.php
+++ b/app/Console/Commands/Init.php
@@ -104,6 +104,15 @@ class Init extends Command
if (empty($out)) {
$commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm $network >/dev/null 2>&1 || true");
+ } else {
+ $data = collect(json_decode($out, true));
+ if ($data->count() === 1) {
+ $isCoolifyProxyItself = data_get($data->first(), 'Name') === 'coolify-proxy';
+ if ($isCoolifyProxyItself) {
+ $commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
+ $commands->push("docker network rm $network >/dev/null 2>&1 || true");
+ }
+ }
}
}
if ($commands->isNotEmpty()) {
From 3269ca3eb88c5c7054e9dd3a8ba5a6f2dc16d65b Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 18:27:54 +0200
Subject: [PATCH 52/59] chore: Add comment explaining the purpose of
disconnecting the network in cleanup_unused_network_from_coolify_proxy()
---
app/Console/Commands/Init.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index 754b95e6b..5789d32fc 100644
--- a/app/Console/Commands/Init.php
+++ b/app/Console/Commands/Init.php
@@ -107,6 +107,7 @@ class Init extends Command
} else {
$data = collect(json_decode($out, true));
if ($data->count() === 1) {
+ // If only coolify-proxy itself is connected to that network (it should not be possible, but who knows)
$isCoolifyProxyItself = data_get($data->first(), 'Name') === 'coolify-proxy';
if ($isCoolifyProxyItself) {
$commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
From 8133a8b770e1d891153981bbe5c02465723d4b7e Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 18:38:13 +0200
Subject: [PATCH 53/59] fix: dir mounts should have proper dirs
---
app/Livewire/Project/Shared/Storages/Add.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/app/Livewire/Project/Shared/Storages/Add.php b/app/Livewire/Project/Shared/Storages/Add.php
index d22f3b05f..c576e2eb9 100644
--- a/app/Livewire/Project/Shared/Storages/Add.php
+++ b/app/Livewire/Project/Shared/Storages/Add.php
@@ -54,7 +54,11 @@ class Add extends Component
public function mount()
{
- $this->file_storage_directory_source = application_configuration_dir()."/{$this->resource->uuid}";
+ if (str($this->resource->getMorphClass())->contains('Standalone')) {
+ $this->file_storage_directory_source = database_configuration_dir()."/{$this->resource->uuid}";
+ } else {
+ $this->file_storage_directory_source = application_configuration_dir()."/{$this->resource->uuid}";
+ }
$this->uuid = $this->resource->uuid;
$this->parameters = get_route_parameters();
if (data_get($this->parameters, 'application_uuid')) {
From ea5101c81498e97b799870cef69008f4065766a2 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 20:00:57 +0200
Subject: [PATCH 54/59] fix: file storages (dir/file mount) handled properly
---
app/Events/FileStorageChanged.php | 32 +++++++++++++++++
app/Livewire/Project/Application/General.php | 2 +-
app/Livewire/Project/Service/FileStorage.php | 19 ++++++++---
app/Livewire/Project/Service/Storage.php | 25 ++++++++++++--
app/Livewire/Project/Shared/Storages/Add.php | 4 +--
app/Livewire/Project/Shared/Storages/All.php | 2 +-
app/Livewire/Project/Shared/Storages/Show.php | 2 +-
app/Models/LocalFileVolume.php | 34 ++++++++++++-------
.../project/service/file-storage.blade.php | 22 +++++++++---
.../project/service/storage.blade.php | 10 +++---
10 files changed, 118 insertions(+), 34 deletions(-)
create mode 100644 app/Events/FileStorageChanged.php
diff --git a/app/Events/FileStorageChanged.php b/app/Events/FileStorageChanged.php
new file mode 100644
index 000000000..27fdc6b5c
--- /dev/null
+++ b/app/Events/FileStorageChanged.php
@@ -0,0 +1,32 @@
+teamId = $teamId;
+ }
+
+ public function broadcastOn(): array
+ {
+ return [
+ new PrivateChannel("team.{$this->teamId}"),
+ ];
+ }
+}
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php
index 395c45524..77593bf0a 100644
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@ -214,7 +214,7 @@ class General extends Component
}
$this->dispatch('success', 'Docker compose file loaded.');
$this->dispatch('compose_loaded');
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
$this->dispatch('refreshEnvs');
} catch (\Throwable $e) {
$this->application->docker_compose_location = $this->initialDockerComposeLocation;
diff --git a/app/Livewire/Project/Service/FileStorage.php b/app/Livewire/Project/Service/FileStorage.php
index 2eea0891f..2d9c95daa 100644
--- a/app/Livewire/Project/Service/FileStorage.php
+++ b/app/Livewire/Project/Service/FileStorage.php
@@ -26,6 +26,8 @@ class FileStorage extends Component
public ?string $workdir = null;
+ public bool $permanently_delete = true;
+
protected $rules = [
'fileStorage.is_directory' => 'required',
'fileStorage.fs_path' => 'required',
@@ -56,7 +58,7 @@ class FileStorage extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
}
}
@@ -71,20 +73,27 @@ class FileStorage extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
}
}
public function delete()
{
try {
- $this->fileStorage->deleteStorageOnServer();
+ $message = 'File deleted.';
+ if ($this->fileStorage->is_directory) {
+ $message = 'Directory deleted.';
+ }
+ if ($this->permanently_delete) {
+ $message = 'Directory deleted from the server.';
+ $this->fileStorage->deleteStorageOnServer();
+ }
$this->fileStorage->delete();
- $this->dispatch('success', 'File deleted.');
+ $this->dispatch('success', $message);
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
}
}
diff --git a/app/Livewire/Project/Service/Storage.php b/app/Livewire/Project/Service/Storage.php
index 161c38097..beccb2677 100644
--- a/app/Livewire/Project/Service/Storage.php
+++ b/app/Livewire/Project/Service/Storage.php
@@ -9,14 +9,35 @@ class Storage extends Component
{
public $resource;
+ public $fileStorage;
+
public function getListeners()
{
+ $teamId = auth()->user()->currentTeam()->id;
+
return [
+ "echo-private:team.{$teamId},FileStorageChanged" => 'refreshStoragesFromEvent',
+ 'refreshStorages' => '$refresh',
'addNewVolume',
- 'refresh_storages' => '$refresh',
];
}
+ public function mount()
+ {
+ $this->refreshStorages();
+ }
+
+ public function refreshStoragesFromEvent()
+ {
+ $this->refreshStorages();
+ $this->dispatch('warning', 'File storage changed. Usually it means that the file / directory is already defined on the server, so Coolify set it up for you properly on the UI.');
+ }
+
+ public function refreshStorages()
+ {
+ $this->fileStorage = $this->resource->fileStorages()->get();
+ }
+
public function addNewVolume($data)
{
try {
@@ -30,7 +51,7 @@ class Storage extends Component
$this->resource->refresh();
$this->dispatch('success', 'Storage added successfully');
$this->dispatch('clearAddStorage');
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
} catch (\Throwable $e) {
return handleError($e, $this);
}
diff --git a/app/Livewire/Project/Shared/Storages/Add.php b/app/Livewire/Project/Shared/Storages/Add.php
index c576e2eb9..27e0c6e44 100644
--- a/app/Livewire/Project/Shared/Storages/Add.php
+++ b/app/Livewire/Project/Shared/Storages/Add.php
@@ -96,7 +96,7 @@ class Add extends Component
'resource_type' => get_class($this->resource),
],
);
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
} catch (\Throwable $e) {
return handleError($e, $this);
}
@@ -123,7 +123,7 @@ class Add extends Component
'resource_type' => get_class($this->resource),
],
);
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
} catch (\Throwable $e) {
return handleError($e, $this);
}
diff --git a/app/Livewire/Project/Shared/Storages/All.php b/app/Livewire/Project/Shared/Storages/All.php
index d2014694e..c26315d3b 100644
--- a/app/Livewire/Project/Shared/Storages/All.php
+++ b/app/Livewire/Project/Shared/Storages/All.php
@@ -8,5 +8,5 @@ class All extends Component
{
public $resource;
- protected $listeners = ['refresh_storages' => '$refresh'];
+ protected $listeners = ['refreshStorages' => '$refresh'];
}
diff --git a/app/Livewire/Project/Shared/Storages/Show.php b/app/Livewire/Project/Shared/Storages/Show.php
index b64cbfa11..08f51ce08 100644
--- a/app/Livewire/Project/Shared/Storages/Show.php
+++ b/app/Livewire/Project/Shared/Storages/Show.php
@@ -39,6 +39,6 @@ class Show extends Component
public function delete()
{
$this->storage->delete();
- $this->dispatch('refresh_storages');
+ $this->dispatch('refreshStorages');
}
}
diff --git a/app/Models/LocalFileVolume.php b/app/Models/LocalFileVolume.php
index decfb1a8d..a436f5797 100644
--- a/app/Models/LocalFileVolume.php
+++ b/app/Models/LocalFileVolume.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use App\Events\FileStorageChanged;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class LocalFileVolume extends BaseModel
@@ -33,16 +34,23 @@ class LocalFileVolume extends BaseModel
$workdir = $this->resource->workdir();
$server = $this->resource->destination->server;
}
- $commands = collect([
- "cd $workdir",
- ]);
+ $commands = collect([]);
$fs_path = data_get($this, 'fs_path');
+ $isFile = instant_remote_process(["test -f $fs_path && echo OK || echo NOK"], $server);
+ $isDir = instant_remote_process(["test -d $fs_path && echo OK || echo NOK"], $server);
if ($fs_path && $fs_path != '/' && $fs_path != '.' && $fs_path != '..') {
- $commands->push("rm -rf $fs_path");
- }
- ray($commands);
+ ray($isFile, $isDir);
+ if ($isFile === 'OK') {
+ $commands->push("rm -rf $fs_path > /dev/null 2>&1 || true");
- return instant_remote_process($commands, $server);
+ } elseif ($isDir === 'OK') {
+ $commands->push("rm -rf $fs_path > /dev/null 2>&1 || true");
+ $commands->push("rmdir $fs_path > /dev/null 2>&1 || true");
+ }
+ }
+ if ($commands->count() > 0) {
+ return instant_remote_process($commands, $server);
+ }
}
public function saveStorageOnServer()
@@ -55,13 +63,10 @@ class LocalFileVolume extends BaseModel
$workdir = $this->resource->workdir();
$server = $this->resource->destination->server;
}
- $commands = collect([
- "mkdir -p $workdir > /dev/null 2>&1 || true",
- "cd $workdir",
- ]);
- $is_directory = $this->is_directory;
- if ($is_directory) {
+ $commands = collect([]);
+ if ($this->is_directory) {
$commands->push("mkdir -p $this->fs_path > /dev/null 2>&1 || true");
+ $commands->push("cd $workdir");
}
if (str($this->fs_path)->startsWith('.') || str($this->fs_path)->startsWith('/') || str($this->fs_path)->startsWith('~')) {
$parent_dir = str($this->fs_path)->beforeLast('/');
@@ -79,8 +84,11 @@ class LocalFileVolume extends BaseModel
$isFile = instant_remote_process(["test -f $path && echo OK || echo NOK"], $server);
$isDir = instant_remote_process(["test -d $path && echo OK || echo NOK"], $server);
if ($isFile == 'OK' && $fileVolume->is_directory) {
+ $content = instant_remote_process(["cat $path"], $server, false);
$fileVolume->is_directory = false;
+ $fileVolume->content = $content;
$fileVolume->save();
+ FileStorageChanged::dispatch(data_get($server, 'team_id'));
throw new \Exception('The following file is a file on the server, but you are trying to mark it as a directory. Please delete the file on the server or mark it as directory.');
} elseif ($isDir == 'OK' && ! $fileVolume->is_directory) {
$fileVolume->is_directory = true;
diff --git a/resources/views/livewire/project/service/file-storage.blade.php b/resources/views/livewire/project/service/file-storage.blade.php
index 12e4901b4..5680c94b3 100644
--- a/resources/views/livewire/project/service/file-storage.blade.php
+++ b/resources/views/livewire/project/service/file-storage.blade.php
@@ -14,16 +14,30 @@
@if ($fileStorage->is_directory)
- This will delete all files in this directory. It is not reversible.
Please think again.
+ This will delete all files in this directory. It is not reversible. Please think
+ again.
@else
- This will convert this to a directory. If it was a file, it will be deleted. It is not reversible.
-
Please think again.
+ This will delete the file and make a directory instead. It is not reversible.
+ Please think
+ again.
+
@endif
- This file / directory will be deleted. It is not reversible.
Please think again.
+ This resource will be deleted. It is not reversible. Please think
+ again.
+ Actions
+ @if ($fileStorage->is_directory)
+
+ @else
+
+ @endif
@if (!$fileStorage->is_directory)
diff --git a/resources/views/livewire/project/service/storage.blade.php b/resources/views/livewire/project/service/storage.blade.php
index b71d7ea94..3a37f8091 100644
--- a/resources/views/livewire/project/service/storage.blade.php
+++ b/resources/views/livewire/project/service/storage.blade.php
@@ -25,7 +25,7 @@
Please modify storage layout in your Docker Compose
file or reload the compose file to reread the storage layout.
@else
- @if ($resource->persistentStorages()->get()->count() === 0 && $resource->fileStorages()->get()->count() == 0)
+ @if ($resource->persistentStorages()->get()->count() === 0 && $fileStorage->count() == 0)
No storage found.
@endif
@endif
@@ -33,9 +33,9 @@
@if ($resource->persistentStorages()->get()->count() > 0)
@endif
- @if ($resource->fileStorages()->get()->count() > 0)
+ @if ($fileStorage->count() > 0)
- @foreach ($resource->fileStorages()->get()->sort() as $fileStorage)
+ @foreach ($fileStorage->sort() as $fileStorage)
@endforeach
@@ -48,9 +48,9 @@
@if ($resource->persistentStorages()->get()->count() > 0)
@endif
- @if ($resource->fileStorages()->get()->count() > 0)
+ @if ($fileStorage->count() > 0)
- @foreach ($resource->fileStorages()->get()->sort() as $fileStorage)
+ @foreach ($fileStorage->sort() as $fileStorage)
@endforeach
From 3e0821e47142d1ab0b13b737c40d98169e8a46d6 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 20:07:08 +0200
Subject: [PATCH 55/59] refactor
---
app/Livewire/Project/Service/Storage.php | 3 ++-
.../views/livewire/project/service/file-storage.blade.php | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/app/Livewire/Project/Service/Storage.php b/app/Livewire/Project/Service/Storage.php
index beccb2677..4b64a8b5e 100644
--- a/app/Livewire/Project/Service/Storage.php
+++ b/app/Livewire/Project/Service/Storage.php
@@ -17,7 +17,7 @@ class Storage extends Component
return [
"echo-private:team.{$teamId},FileStorageChanged" => 'refreshStoragesFromEvent',
- 'refreshStorages' => '$refresh',
+ 'refreshStorages',
'addNewVolume',
];
}
@@ -36,6 +36,7 @@ class Storage extends Component
public function refreshStorages()
{
$this->fileStorage = $this->resource->fileStorages()->get();
+ $this->dispatch('$refresh');
}
public function addNewVolume($data)
diff --git a/resources/views/livewire/project/service/file-storage.blade.php b/resources/views/livewire/project/service/file-storage.blade.php
index 5680c94b3..96590cada 100644
--- a/resources/views/livewire/project/service/file-storage.blade.php
+++ b/resources/views/livewire/project/service/file-storage.blade.php
@@ -27,8 +27,9 @@
@endif
- This resource will be deleted. It is not reversible.
Please think
+ This storage will be deleted. It is not reversible. Please
+ think
again.
Actions
@if ($fileStorage->is_directory)
From 92ebc3f0c60c1e91a3e170e564091a556022e98a Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 5 Aug 2024 20:08:37 +0200
Subject: [PATCH 56/59] refactor
---
app/Livewire/Project/Service/Configuration.php | 4 +---
app/Livewire/Server/Proxy/DynamicConfigurations.php | 3 +--
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.php
index 47534ded1..c82012aaa 100644
--- a/app/Livewire/Project/Service/Configuration.php
+++ b/app/Livewire/Project/Service/Configuration.php
@@ -25,7 +25,6 @@ class Configuration extends Component
return [
"echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',
'check_status',
- 'refresh' => '$refresh',
];
}
@@ -76,8 +75,7 @@ class Configuration extends Component
{
try {
GetContainersStatus::run($this->service->server);
- // dispatch_sync(new ContainerStatusJob($this->service->server));
- $this->dispatch('refresh')->self();
+ $this->dispatch('$refresh');
} catch (\Exception $e) {
return handleError($e, $this);
}
diff --git a/app/Livewire/Server/Proxy/DynamicConfigurations.php b/app/Livewire/Server/Proxy/DynamicConfigurations.php
index c858481db..6277a24bd 100644
--- a/app/Livewire/Server/Proxy/DynamicConfigurations.php
+++ b/app/Livewire/Server/Proxy/DynamicConfigurations.php
@@ -21,7 +21,6 @@ class DynamicConfigurations extends Component
return [
"echo-private:team.{$teamId},ProxyStatusChanged" => 'loadDynamicConfigurations',
'loadDynamicConfigurations',
- 'refresh' => '$refresh',
];
}
@@ -42,7 +41,7 @@ class DynamicConfigurations extends Component
$contents[$without_extension] = instant_remote_process(["cat {$proxy_path}/dynamic/{$file}"], $this->server);
}
$this->contents = $contents;
- $this->dispatch('refresh');
+ $this->dispatch('$refresh');
}
public function mount()
From c5de1a25c35bfa96ab3b4eed89b67b504e84ace2 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 09:45:48 +0200
Subject: [PATCH 57/59] refactor: Remove unnecessary debug statement in
ServerCheckJob
---
app/Jobs/ServerCheckJob.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index d78642a3f..88caaacc4 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -72,7 +72,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
return 'Server is not ready.';
}
if (! $this->server->isSwarmWorker() && ! $this->server->isBuildServer()) {
- ray('Server is not a worker or build server.');
['containers' => $this->containers, 'containerReplicates' => $containerReplicates] = $this->server->getContainers();
if (is_null($this->containers)) {
return 'No containers found.';
From 74e8a4a70368979c4647beb82fb4f106b3a4f269 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 10:52:47 +0200
Subject: [PATCH 58/59] refactor: Simplify log drain installation and stop log
drain if necessary
---
app/Actions/Server/InstallLogDrain.php | 7 +------
app/Actions/Server/StopLogDrain.php | 20 ++++++++++++++++++++
app/Livewire/Server/LogDrains.php | 4 ++++
3 files changed, 25 insertions(+), 6 deletions(-)
create mode 100644 app/Actions/Server/StopLogDrain.php
diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php
index 6f74e020b..034d89fe7 100644
--- a/app/Actions/Server/InstallLogDrain.php
+++ b/app/Actions/Server/InstallLogDrain.php
@@ -24,12 +24,7 @@ class InstallLogDrain
}
try {
if ($type === 'none') {
- $command = [
- "echo 'Stopping old Fluent Bit'",
- 'docker rm -f coolify-log-drain || true',
- ];
-
- return instant_remote_process($command, $server);
+ return 'No log drain is enabled.';
} elseif ($type === 'newrelic') {
if (! $server->settings->is_logdrain_newrelic_enabled) {
throw new \Exception('New Relic log drain is not enabled.');
diff --git a/app/Actions/Server/StopLogDrain.php b/app/Actions/Server/StopLogDrain.php
new file mode 100644
index 000000000..a5bce94a5
--- /dev/null
+++ b/app/Actions/Server/StopLogDrain.php
@@ -0,0 +1,20 @@
+ false,
]);
}
+ if (! $this->server->isLogDrainEnabled()) {
+ StopLogDrain::dispatch($this->server);
+ }
$this->server->settings->save();
$this->dispatch('success', 'Settings saved.');
From e3c7c615c67d18df0bf1d18a494f2c88aa7ff6c2 Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Tue, 6 Aug 2024 10:53:13 +0200
Subject: [PATCH 59/59] refactor: Cleanup unnecessary dynamic proxy
configuration in Init command
---
app/Console/Commands/Init.php | 37 +++++++++++++++++++++++++++--------
app/Jobs/ServerCheckJob.php | 13 ------------
2 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index 5789d32fc..f5d5a892e 100644
--- a/app/Console/Commands/Init.php
+++ b/app/Console/Commands/Init.php
@@ -21,13 +21,15 @@ class Init extends Command
protected $description = 'Cleanup instance related stuffs';
+ public $servers = null;
+
public function handle()
{
+ $this->servers = Server::all();
$this->alive();
get_public_ips();
if (version_compare('4.0.0-beta.312', config('version'), '<=')) {
- $servers = Server::all();
- foreach ($servers as $server) {
+ foreach ($this->servers as $server) {
if ($server->settings->is_metrics_enabled === true) {
$server->settings->update(['is_metrics_enabled' => false]);
}
@@ -57,14 +59,15 @@ class Init extends Command
// Required for falsely deleted coolify db
$this->restore_coolify_db_backup();
$this->cleanup_unused_network_from_coolify_proxy();
+ $this->cleanup_unnecessary_dynamic_proxy_configuration();
$this->cleanup_in_progress_application_deployments();
$this->cleanup_stucked_helper_containers();
$this->call('cleanup:queue');
$this->call('cleanup:stucked-resources');
if (! isCloud()) {
try {
- $server = Server::find(0)->first();
- $server->setupDynamicProxyConfiguration();
+ $localhost = $this->servers->where('id', 0)->first();
+ $localhost->setupDynamicProxyConfiguration();
} catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
}
@@ -85,11 +88,30 @@ class Init extends Command
$this->call('cleanup:stucked-resources');
}
+ private function cleanup_unnecessary_dynamic_proxy_configuration()
+ {
+ if (isCloud()) {
+ foreach ($this->servers as $server) {
+ if (! $server->isFunctional()) {
+ continue;
+ }
+ if ($server->id === 0) {
+ continue;
+ }
+ $file = $server->proxyPath().'/dynamic/coolify.yaml';
+
+ return instant_remote_process([
+ "rm -f $file",
+ ], $server, false);
+
+ }
+ }
+ }
+
private function cleanup_unused_network_from_coolify_proxy()
{
ray()->clearAll();
- $servers = Server::all();
- foreach ($servers as $server) {
+ foreach ($this->servers as $server) {
if (! $server->isFunctional()) {
continue;
}
@@ -150,8 +172,7 @@ class Init extends Command
private function cleanup_stucked_helper_containers()
{
- $servers = Server::all();
- foreach ($servers as $server) {
+ foreach ($this->servers as $server) {
if ($server->isFunctional()) {
CleanupHelperContainersJob::dispatch($server);
}
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index 88caaacc4..6a2233726 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -106,7 +106,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
private function serverStatus()
{
- $this->removeUnnevessaryCoolifyYaml();
['uptime' => $uptime] = $this->server->validateConnection();
if ($uptime) {
if ($this->server->unreachable_notification_sent === true) {
@@ -138,18 +137,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
}
- private function removeUnnevessaryCoolifyYaml()
- {
- // This will remote the coolify.yaml file from the server as it is not needed on cloud servers
- if (isCloud() && $this->server->id !== 0) {
- $file = $this->server->proxyPath().'/dynamic/coolify.yaml';
-
- return instant_remote_process([
- "rm -f $file",
- ], $this->server, false);
- }
- }
-
private function checkLogDrainContainer()
{
$foundLogDrainContainer = $this->containers->filter(function ($value, $key) {