Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

add swarm server grouping fixes for swarm

Andras Bacsai798acb8ee5d1
diff --git a/app/Actions/Proxy/CheckProxy.php b/app/Actions/Proxy/CheckProxy.php
index 32673abc9e..ccefa86819 100644
--- a/app/Actions/Proxy/CheckProxy.php
+++ b/app/Actions/Proxy/CheckProxy.php
@@ -21,7 +21,10 @@ class CheckProxy
$status = getContainerStatus($server, 'coolify-proxy_traefik');
$server->proxy->set('status', $status);
$server->save();
- return false;
+ if ($status === 'running') {
+ return false;
+ }
+ return true;
} else {
$status = getContainerStatus($server, 'coolify-proxy');
if ($status === 'running') {
diff --git a/app/Livewire/Project/New/Select.php b/app/Livewire/Project/New/Select.php
index b205467bf9..80a41d7c70 100644
--- a/app/Livewire/Project/New/Select.php
+++ b/app/Livewire/Project/New/Select.php
@@ -123,7 +123,7 @@ class Select extends Component
$this->servers = $this->allServers->where('settings.is_swarm_worker', false)->where('settings.is_swarm_manager', false);
break;
}
- if (str($type)->startsWith('one-click-service')) {
+ if (str($type)->startsWith('one-click-service') || str($type)->startsWith('docker-compose-empty') || str($type)->startsWith('docker-image')) {
$this->isDatabase = true;
$this->includeSwarm = false;
$this->servers = $this->allServers->where('settings.is_swarm_worker', false)->where('settings.is_swarm_manager', false);
diff --git a/app/Livewire/Server/New/ByIp.php b/app/Livewire/Server/New/ByIp.php
index 98e7a99a71..1849cdfbc4 100644
--- a/app/Livewire/Server/New/ByIp.php
+++ b/app/Livewire/Server/New/ByIp.php
@@ -23,8 +23,9 @@ class ByIp extends Component
public int $port = 22;
public bool $is_swarm_manager = false;
public bool $is_swarm_worker = false;
+ public $selected_swarm_cluster = null;
-
+ public $swarm_managers = [];
protected $rules = [
'name' => 'required|string',
'description' => 'nullable|string',
@@ -48,6 +49,10 @@ class ByIp extends Component
{
$this->name = generate_random_name();
$this->private_key_id = $this->private_keys->first()->id;
+ $this->swarm_managers = Server::isUsable()->get()->where('settings.is_swarm_manager', true);
+ if ($this->swarm_managers->count() > 0) {
+ $this->selected_swarm_cluster = $this->swarm_managers->first()->id;
+ }
}
public function setPrivateKey(string $private_key_id)
@@ -57,7 +62,7 @@ class ByIp extends Component
public function instantSave()
{
- $this->dispatch('success', 'Application settings updated!');
+ // $this->dispatch('success', 'Application settings updated!');
}
public function submit()
@@ -67,7 +72,7 @@ class ByIp extends Component
if (is_null($this->private_key_id)) {
return $this->dispatch('error', 'You must select a private key');
}
- $server = Server::create([
+ $payload = [
'name' => $this->name,
'description' => $this->description,
'ip' => $this->ip,
@@ -79,7 +84,11 @@ class ByIp extends Component
"type" => ProxyTypes::TRAEFIK_V2->value,
"status" => ProxyStatus::EXITED->value,
],
- ]);
+ ];
+ if ($this->is_swarm_worker) {
+ $payload['swarm_cluster'] = $this->selected_swarm_cluster;
+ }
+ $server = Server::create($payload);
$server->settings->is_swarm_manager = $this->is_swarm_manager;
$server->settings->is_swarm_worker = $this->is_swarm_worker;
$server->settings->save();
diff --git a/database/migrations/2023_12_19_124111_add_swarm_cluster_grouping.php b/database/migrations/2023_12_19_124111_add_swarm_cluster_grouping.php
new file mode 100644
index 0000000000..668acb6fed
--- /dev/null
+++ b/database/migrations/2023_12_19_124111_add_swarm_cluster_grouping.php
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('servers', function (Blueprint $table) {
+ $table->integer('swarm_cluster')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('servers', function (Blueprint $table) {
+ $table->dropColumn('swarm_cluster');
+ });
+ }
+};
diff --git a/resources/views/components/status/index.blade.php b/resources/views/components/status/index.blade.php
index 050025f944..08d6b3cc24 100644
--- a/resources/views/components/status/index.blade.php
+++ b/resources/views/components/status/index.blade.php
@@ -1,6 +1,6 @@
@if (Str::of($status)->startsWith('running'))
<x-status.running :status="$status" />
-@elseif(Str::of($status)->startsWith('restarting'))
+@elseif(Str::of($status)->startsWith('restarting') || Str::of($status)->startsWith('starting'))
<x-status.restarting :status="$status" />
@else
<x-status.stopped :status="$status" />
diff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.php
index ae638b8eed..0d999aed6a 100644
--- a/resources/views/livewire/project/new/select.blade.php
+++ b/resources/views/livewire/project/new/select.blade.php
@@ -205,7 +205,7 @@
@if ($isDatabase)
<div class="flex items-center justify-center pt-4">
<x-forms.checkbox instantSave wire:model="includeSwarm"
- helper="Swarm clusters are excluded from this list by default. For database (or services with database) to work with Swarm,
+ helper="Swarm clusters are excluded from this list by default. For database, services or complex compose deployments with databases to work with Swarm,
you need to set a few things on the server. Read more <a class='text-white underline' href='https://coolify.io/docs/swarm#database-requirements' target='_blank'>here</a>."
label="Include Swarm Clusters" />
</div>
diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php
index 6219a5136a..a96ff42967 100644
--- a/resources/views/livewire/server/form.blade.php
+++ b/resources/views/livewire/server/form.blade.php
@@ -54,26 +54,28 @@
<x-forms.checkbox instantSave
helper="If you are using Cloudflare Tunnels, enable this. It will proxy all ssh requests to your server through Cloudflare.<span class='text-warning'>Coolify does not install/setup Cloudflare (cloudflared) on your server.</span>"
id="server.settings.is_cloudflare_tunnel" label="Cloudflare Tunnel" />
- {{-- @if ($server->settings->is_swarm_worker)
+ @if ($server->isSwarm())
+ <div class="pt-6"> Swarm support is in alpha version. </div>
+ @endif
+ @if ($server->settings->is_swarm_worker)
<x-forms.checkbox disabled instantSave type="checkbox" id="server.settings.is_swarm_manager"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Manager?<span class='font-bold text-warning'>(alpha)</span>" />
+ label="Is it a Swarm Manager?" />
@else
<x-forms.checkbox instantSave type="checkbox" id="server.settings.is_swarm_manager"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Manager?<span class='font-bold text-warning'>(alpha)</span>"" />
+ label="Is it a Swarm Manager?" />
@endif
@if ($server->settings->is_swarm_manager)
<x-forms.checkbox disabled instantSave type="checkbox" id="server.settings.is_swarm_worker"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Worker?<span class='font-bold text-warning'>(alpha)</span>" />
+ label="Is it a Swarm Worker?" />
@else
<x-forms.checkbox instantSave type="checkbox" id="server.settings.is_swarm_worker"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Worker?<span class='font-bold text-warning'>(alpha)</span>" />
- @endif --}}
+ label="Is it a Swarm Worker?" />
+ @endif
@endif
-
</div>
</div>
diff --git a/resources/views/livewire/server/new/by-ip.blade.php b/resources/views/livewire/server/new/by-ip.blade.php
index 3723ccfabe..3b958c0b30 100644
--- a/resources/views/livewire/server/new/by-ip.blade.php
+++ b/resources/views/livewire/server/new/by-ip.blade.php
@@ -25,26 +25,40 @@
@endif
@endforeach
</x-forms.select>
- {{-- <div class="w-72">
+ <div class="w-72">
+ <div class="pt-6"> Swarm support is in alpha version. </div>
@if ($is_swarm_worker)
<x-forms.checkbox disabled instantSave type="checkbox" id="is_swarm_manager"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Manager?<span class='font-bold text-warning'>(alpha)</span>" />
+ label="Is it a Swarm Manager?" />
@else
- <x-forms.checkbox instantSave type="checkbox" id="is_swarm_manager"
+ <x-forms.checkbox type="checkbox" instantSave id="is_swarm_manager"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Manager?<span class='font-bold text-warning'>(alpha)</span>" />
+ label="Is it a Swarm Manager?" />
@endif
@if ($is_swarm_manager)
<x-forms.checkbox disabled instantSave type="checkbox" id="is_swarm_worker"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Worker?<span class='font-bold text-warning'>(alpha)</span>" />
+ label="Is it a Swarm Worker?" />
@else
- <x-forms.checkbox instantSave type="checkbox" id="is_swarm_worker"
+ <x-forms.checkbox type="checkbox" instantSave id="is_swarm_worker"
helper="For more information, please read the documentation <a class='text-white' href='https://coolify.io/docs/swarm' target='_blank'>here</a>."
- label="Is it a Swarm Worker?<span class='font-bold text-warning'>(alpha)</span>" />
+ label="Is it a Swarm Worker?" />
@endif
- </div> --}}
+ @if ($is_swarm_worker)
+ <div class="py-4">
+ <x-forms.select label="Select a Swarm Cluster" id="selected_swarm_cluster" required>
+ @foreach ($swarm_managers as $server)
+ @if ($loop->first)
+ <option selected value="{{ $server->id }}">{{ $server->name }}</option>
+ @else
+ <option value="{{ $server->id }}">{{ $server->name }}</option>
+ @endif
+ @endforeach
+ </x-forms.select>
+ </div>
+ @endif
+ </div>
<x-forms.button type="submit">
Save New Server
</x-forms.button>