This commit is contained in:
Joao Patricio 2023-05-03 07:40:12 +01:00
commit f50e850774
16 changed files with 709 additions and 144 deletions

1
.gitignore vendored
View File

@ -21,6 +21,7 @@ yarn-error.log
/.bash_history
/_volumes
# Temp while developing Proxy deployment
resources/recipes
.lesshst

View File

@ -0,0 +1,13 @@
<?php
namespace App\Data;
use App\Enums\ProxyTypes;
use Spatie\LaravelData\Data;
class ServerMetadata extends Data
{
public function __construct(
public ?ProxyTypes $proxy,
) {}
}

10
app/Enums/ProxyTypes.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App\Enums;
enum ProxyTypes: string
{
case TRAEFIK_V2 = 'TRAEFIK_V2';
case NGINX = 'NGINX';
case CADDY = 'CADDY';
}

View File

@ -93,6 +93,7 @@ public function application_deployment()
if (!$application) {
return redirect()->route('dashboard');
}
$activity = Activity::query()
->where('properties->type', '=', 'deployment')
->where('properties->uuid', '=', $deployment_uuid)

View File

@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers;
use App\Models\Server;
use Illuminate\Http\Request;
class ServerController extends Controller
{
public function show(Server $server)
{
return view('server.show', [
'server' => $server,
]);
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;
class ActivityMonitor extends Component
{
public $activityId;
public $isPollingActive = false;
protected $activity;
protected $listeners = ['newMonitorActivity'];
public function hydrateActivity()
{
$this->activity = Activity::query()
->find($this->activityId);
}
public function newMonitorActivity($activityId)
{
$this->activityId = $activityId;
$this->hydrateActivity();
$this->isPollingActive = true;
}
public function polling()
{
$this->hydrateActivity();
if (data_get($this->activity, 'properties.exitCode') !== null) {
$this->isPollingActive = false;
}
}
public function render()
{
return view('livewire.activity-monitor');
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Livewire\Server;
use App\Models\Server;
use Livewire\Component;
class Proxy extends Component
{
public Server $server;
protected string $selectedProxy = '';
public function mount(Server $server)
{
$this->server = $server;
}
public function runInstallProxy()
{
$activity = remoteProcess(['ls -alh'], $this->server);
$this->emit('newMonitorActivity', $activity->id);
}
public function render()
{
return view('livewire.server.proxy');
}
}

View File

@ -2,6 +2,9 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
class Server extends BaseModel
{
protected static function booted()
@ -28,10 +31,18 @@ public function swarmDockers()
{
return $this->hasMany(SwarmDocker::class);
}
public $casts = [
'extra_attributes' => SchemalessAttributes::class,
];
public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
}
public function privateKey()
{
return $this->belongsTo(PrivateKey::class);
}
public function settings()
{
return $this->hasOne(ServerSetting::class);

View File

@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.2",
"doctrine/dbal": "^3.6",
"guzzlehttp/guzzle": "^7.5.0",
"laravel/fortify": "^v1.16.0",
"laravel/framework": "^v10.7.1",
@ -18,6 +19,7 @@
"spatie/laravel-data": "^3.4.3",
"spatie/laravel-ray": "^1.32.4",
"spatie/url": "^2.2",
"spatie/laravel-schemaless-attributes": "^2.4",
"symfony/yaml": "^6.2",
"visus/cuid2": "^2.0.0"
},

655
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@ public function up(): void
$table->string('user')->default('root');
$table->foreignId('team_id');
$table->foreignId('private_key_id');
$table->schemalessAttributes('extra_attributes');
$table->timestamps();
});
}

View File

@ -2,6 +2,8 @@
namespace Database\Seeders;
use App\Data\ServerMetadata;
use App\Enums\ProxyTypes;
use App\Models\PrivateKey;
use App\Models\Server;
use App\Models\Team;
@ -16,12 +18,16 @@ public function run(): void
{
$root_team = Team::find(0);
$private_key_1 = PrivateKey::find(1);
Server::create([
'name' => "testing-local-docker-container",
'description' => "This is a test docker container",
'ip' => "coolify-testing-host",
'team_id' => $root_team->id,
'private_key_id' => $private_key_1->id,
'extra_attributes' => ServerMetadata::from([
'proxy' => ProxyTypes::TRAEFIK_V2->value
]),
]);
Server::create([
'name' => "testing-local-docker-container-2",
@ -29,6 +35,9 @@ public function run(): void
'ip' => "coolify-testing-host-2",
'team_id' => $root_team->id,
'private_key_id' => $private_key_1->id,
'extra_attributes' => ServerMetadata::from([
//
]),
]);
}
}

View File

@ -0,0 +1,17 @@
<div class="mt-8">
@isset($this->activity)
<span>Activity: {{ $this->activity?->id }}</span>
<span>Status: {{ $this->activity?->properties->get('status') }}</span>
<pre
class="h-[400px] flex flex-col-reverse w-full bg-[#cbcbcb] overflow-y-scroll"
@if($isPollingActive)
wire:poll.750ms="polling"
@endif
>{{
\App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($this->activity)
}}</pre>
@else
Not monitoring any activity.
@endisset
</div>

View File

@ -0,0 +1,30 @@
<div>
<h2> Proxy </h2>
@if($this->server->extra_attributes->proxy)
<div class="mt-12">
<div>
Proxy type: {{ $this->server->extra_attributes->proxy }}
</div>
<div class="mt-12"> Features in W11.</div>
<ul>
<li>Edit config file</li>
<li>Enable dashboard (blocking port by firewall)</li>
<li>Dashboard access - login/password</li>
<li>Setup host for Traefik Dashboard</li>
<li>Visit (nav to traefik dashboard)</li>
</ul>
</div>
@else
No proxy installed.
<select wire:model="selectedProxy">
<option value="{{ \App\Enums\ProxyTypes::TRAEFIK_V2 }}">
{{ \App\Enums\ProxyTypes::TRAEFIK_V2 }}
</option>
</select>
<button wire:click="runInstallProxy">Install Proxy</button>
@endif
<livewire:activity-monitor />
</div>

View File

@ -7,4 +7,7 @@
<p>Network: {{ data_get($docker, 'network') }}</p>
@endforeach
@endif
<h1> {{ $server->name }}</h1>
<livewire:server.proxy :server="$server"/>
</x-layout>

View File

@ -6,6 +6,7 @@
use App\Models\InstanceSettings;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use App\Http\Controllers\ServerController;
use Illuminate\Support\Facades\Route;
/*
@ -34,6 +35,15 @@
'destinations' => $destinations->sortBy('name'),
]);
})->name('dashboard');
Route::get('/project/{project_uuid}', [ProjectController::class, 'environments'])->name('project.environments');
Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources');
Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application');
Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment');
Route::get('/server/{server:uuid}', [ServerController::class, 'show'])->name('server.show');
Route::get('/profile', function () {
return view('profile');