This commit is contained in:
Joao Patricio 2023-05-03 06:23:45 +01:00
parent e7763f3b73
commit 00a8c847e9
17 changed files with 621 additions and 2 deletions

3
.gitignore vendored
View File

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

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

@ -62,6 +62,7 @@ public function deployment()
if (!$application) {
return redirect()->route('home');
}
$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()
@ -12,10 +15,21 @@ protected static function booted()
]);
});
}
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",
@ -16,6 +17,7 @@
"spatie/laravel-activitylog": "^4.7.3",
"spatie/laravel-data": "^3.4.3",
"spatie/laravel-ray": "^1.32.4",
"spatie/laravel-schemaless-attributes": "^2.4",
"symfony/yaml": "^6.2",
"visus/cuid2": "^2.0.0"
},

423
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d7ed21949975efcb1891e098e4d2abfa",
"content-hash": "4d4a58970bcb8990e0fa643bef8c8243",
"packages": [
{
"name": "bacon/bacon-qr-code",
@ -241,6 +241,211 @@
},
"time": "2022-10-27T11:44:00+00:00"
},
{
"name": "doctrine/cache",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/1ca8f21980e770095a31456042471a57bc4c68fb",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb",
"shasum": ""
},
"require": {
"php": "~7.1 || ^8.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
"cache/integration-tests": "dev-master",
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/cache": "^4.4 || ^5.4 || ^6",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
"homepage": "https://www.doctrine-project.org/projects/cache.html",
"keywords": [
"abstraction",
"apcu",
"cache",
"caching",
"couchdb",
"memcached",
"php",
"redis",
"xcache"
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
"source": "https://github.com/doctrine/cache/tree/2.2.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2022-05-20T20:07:39+00:00"
},
{
"name": "doctrine/dbal",
"version": "3.6.2",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "b4bd1cfbd2b916951696d82e57d054394d84864c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/b4bd1cfbd2b916951696d82e57d054394d84864c",
"reference": "b4bd1cfbd2b916951696d82e57d054394d84864c",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1|^2",
"php": "^7.4 || ^8.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "11.1.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2022.3",
"phpstan/phpstan": "1.10.9",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "9.6.6",
"psalm/plugin-phpunit": "0.18.4",
"squizlabs/php_codesniffer": "3.7.2",
"symfony/cache": "^5.4|^6.0",
"symfony/console": "^4.4|^5.4|^6.0",
"vimeo/psalm": "4.30.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.",
"homepage": "https://www.doctrine-project.org/projects/dbal.html",
"keywords": [
"abstraction",
"database",
"db2",
"dbal",
"mariadb",
"mssql",
"mysql",
"oci8",
"oracle",
"pdo",
"pgsql",
"postgresql",
"queryobject",
"sasql",
"sql",
"sqlite",
"sqlserver",
"sqlsrv"
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.6.2"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2023-04-14T07:25:38+00:00"
},
{
"name": "doctrine/deprecations",
"version": "v1.0.0",
@ -284,6 +489,97 @@
},
"time": "2022-05-02T15:47:09+00:00"
},
{
"name": "doctrine/event-manager",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/event-manager.git",
"reference": "750671534e0241a7c50ea5b43f67e23eb5c96f32"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/750671534e0241a7c50ea5b43f67e23eb5c96f32",
"reference": "750671534e0241a7c50ea5b43f67e23eb5c96f32",
"shasum": ""
},
"require": {
"php": "^8.1"
},
"conflict": {
"doctrine/common": "<2.9"
},
"require-dev": {
"doctrine/coding-standard": "^10",
"phpstan/phpstan": "^1.8.8",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.28"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
},
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
}
],
"description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.",
"homepage": "https://www.doctrine-project.org/projects/event-manager.html",
"keywords": [
"event",
"event dispatcher",
"event manager",
"event system",
"events"
],
"support": {
"issues": "https://github.com/doctrine/event-manager/issues",
"source": "https://github.com/doctrine/event-manager/tree/2.0.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2022-10-12T20:59:15+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.6",
@ -2960,6 +3256,55 @@
},
"time": "2022-06-13T21:57:56+00:00"
},
{
"name": "psr/cache",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/3.0.0"
},
"time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/clock",
"version": "1.0.0",
@ -4054,6 +4399,82 @@
],
"time": "2023-03-23T08:04:54+00:00"
},
{
"name": "spatie/laravel-schemaless-attributes",
"version": "2.4.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-schemaless-attributes.git",
"reference": "ae19842763fe8d5a5059f8a7c0802bee6662b00c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-schemaless-attributes/zipball/ae19842763fe8d5a5059f8a7c0802bee6662b00c",
"reference": "ae19842763fe8d5a5059f8a7c0802bee6662b00c",
"shasum": ""
},
"require": {
"illuminate/contracts": "^7.0|^8.0|^9.0|^10.0",
"illuminate/database": "^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^7.0|^8.0|^9.0|^10.0",
"php": "^8.0",
"spatie/laravel-package-tools": "^1.4.3"
},
"require-dev": {
"brianium/paratest": "^6.2",
"mockery/mockery": "^1.4",
"nunomaduro/collision": "^5.3|^6.0",
"orchestra/testbench": "^6.15|^7.0|^8.0",
"pestphp/pest-plugin-laravel": "^1.3",
"phpunit/phpunit": "^9.5.4"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\SchemalessAttributes\\SchemalessAttributesServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Spatie\\SchemalessAttributes\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Add schemaless attributes to Eloquent models",
"homepage": "https://github.com/spatie/laravel-schemaless-attributes",
"keywords": [
"laravel-schemaless-attributes",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-schemaless-attributes/issues",
"source": "https://github.com/spatie/laravel-schemaless-attributes/tree/2.4.0"
},
"funding": [
{
"url": "https://spatie.be/open-source/support-us",
"type": "custom"
},
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-01-14T20:58:52+00:00"
},
{
"name": "spatie/macroable",
"version": "2.0.0",

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,6 +18,7 @@ public function run(): void
{
$root_team = Team::find(0);
$private_key_1 = PrivateKey::find(1);
Server::create([
'id' => 1,
'name' => "testing-local-docker-container",
@ -23,6 +26,9 @@ public function run(): void
'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([
'id' => 2,
@ -31,6 +37,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

@ -1,7 +1,7 @@
<x-layout>
<h1>Servers</h1>
@forelse ($servers as $server)
<a href="{{ route('project.environments', [$server->uuid]) }}">{{ data_get($server, 'name') }}</a>
<a href="{{ route('server.show', [$server->uuid]) }}">{{ data_get($server, 'name') }}</a>
@empty
<p>No servers found.</p>
@endforelse

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

@ -0,0 +1,5 @@
<x-layout>
<h1> {{ $server->name }}</h1>
<livewire:server.proxy :server="$server"/>
</x-layout>

View File

@ -2,6 +2,7 @@
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\ServerController;
use Illuminate\Support\Facades\Route;
/*
@ -26,6 +27,8 @@
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('/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database');
// Route::get('//service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service');