add swarm server grouping

fixes for swarm
This commit is contained in:
Andras Bacsai 2023-12-19 13:47:12 +01:00
parent ef595dd4c2
commit 798acb8ee5
8 changed files with 79 additions and 23 deletions

View File

@ -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') {

View File

@ -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);

View File

@ -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();

View File

@ -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');
});
}
};

View File

@ -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" />

View File

@ -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>

View File

@ -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>

View File

@ -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>