add destinations
This commit is contained in:
parent
77c86400c0
commit
1a9f360132
51
app/Http/Livewire/Destination/New/StandaloneDocker.php
Normal file
51
app/Http/Livewire/Destination/New/StandaloneDocker.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Livewire\Destination\New;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\StandaloneDocker as ModelsStandaloneDocker;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class StandaloneDocker extends Component
|
||||||
|
{
|
||||||
|
public string $name;
|
||||||
|
public string $network;
|
||||||
|
|
||||||
|
public $servers;
|
||||||
|
public int|null $server_id = null;
|
||||||
|
|
||||||
|
protected $rules = [
|
||||||
|
'name' => 'required|string',
|
||||||
|
'network' => 'required|string',
|
||||||
|
'server_id' => 'required|integer'
|
||||||
|
];
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
$this->name = generateRandomName();
|
||||||
|
$this->servers = Server::where('team_id', session('currentTeam')->id)->get();
|
||||||
|
}
|
||||||
|
public function setServerId($server_id)
|
||||||
|
{
|
||||||
|
$this->server_id = $server_id;
|
||||||
|
}
|
||||||
|
public function submit()
|
||||||
|
{
|
||||||
|
$this->validate();
|
||||||
|
$found = ModelsStandaloneDocker::where('server_id', $this->server_id)->where('network', $this->network)->first();
|
||||||
|
if ($found) {
|
||||||
|
$this->addError('network', 'Network already added to this server.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$docker = ModelsStandaloneDocker::create([
|
||||||
|
'name' => $this->name,
|
||||||
|
'network' => $this->network,
|
||||||
|
'server_id' => $this->server_id,
|
||||||
|
'team_id' => session('currentTeam')->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$server = Server::find($this->server_id);
|
||||||
|
|
||||||
|
runRemoteCommandSync($server, ['docker network create --attachable ' . $this->network], throwError: false);
|
||||||
|
return redirect()->route('destination.show', $docker->uuid);
|
||||||
|
}
|
||||||
|
}
|
@ -20,9 +20,13 @@ class Server extends BaseModel
|
|||||||
'team_id',
|
'team_id',
|
||||||
'private_key_id',
|
'private_key_id',
|
||||||
];
|
];
|
||||||
public function destinations()
|
public function standaloneDockers()
|
||||||
{
|
{
|
||||||
return $this->hasMany(PrivateKey::class);
|
return $this->hasMany(StandaloneDocker::class);
|
||||||
|
}
|
||||||
|
public function swarmDockers()
|
||||||
|
{
|
||||||
|
return $this->hasMany(SwarmDocker::class);
|
||||||
}
|
}
|
||||||
public function privateKey()
|
public function privateKey()
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,11 @@ namespace App\Models;
|
|||||||
|
|
||||||
class StandaloneDocker extends BaseModel
|
class StandaloneDocker extends BaseModel
|
||||||
{
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'network',
|
||||||
|
'server_id',
|
||||||
|
];
|
||||||
public function applications()
|
public function applications()
|
||||||
{
|
{
|
||||||
return $this->morphMany(Application::class, 'destination');
|
return $this->morphMany(Application::class, 'destination');
|
||||||
|
@ -8,4 +8,8 @@ class SwarmDocker extends BaseModel
|
|||||||
{
|
{
|
||||||
return $this->morphMany(Application::class, 'destination');
|
return $this->morphMany(Application::class, 'destination');
|
||||||
}
|
}
|
||||||
|
public function server()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Server::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ if (!function_exists('formatDockerLabelsToJson')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!function_exists('runRemoteCommandSync')) {
|
if (!function_exists('runRemoteCommandSync')) {
|
||||||
function runRemoteCommandSync($server, array $command)
|
function runRemoteCommandSync(Server $server, array $command, $throwError = true)
|
||||||
{
|
{
|
||||||
$command_string = implode("\n", $command);
|
$command_string = implode("\n", $command);
|
||||||
$private_key_location = savePrivateKeyForServer($server);
|
$private_key_location = savePrivateKeyForServer($server);
|
||||||
@ -128,6 +128,9 @@ if (!function_exists('runRemoteCommandSync')) {
|
|||||||
$output = trim($process->output());
|
$output = trim($process->output());
|
||||||
$exitCode = $process->exitCode();
|
$exitCode = $process->exitCode();
|
||||||
if ($exitCode !== 0) {
|
if ($exitCode !== 0) {
|
||||||
|
if (!$throwError) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Log::error($output);
|
Log::error($output);
|
||||||
throw new \RuntimeException('There was an error running the command.');
|
throw new \RuntimeException('There was an error running the command.');
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,12 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('standalone_dockers', function (Blueprint $table) {
|
Schema::create('standalone_dockers', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
$table->string('uuid')->unique();
|
$table->string('uuid')->unique();
|
||||||
$table->string('network');
|
$table->string('network');
|
||||||
|
|
||||||
$table->foreignId('server_id');
|
$table->foreignId('server_id');
|
||||||
|
$table->unique(['server_id', 'network']);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('swarm_dockers', function (Blueprint $table) {
|
Schema::create('swarm_dockers', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
$table->string('uuid')->unique();
|
$table->string('uuid')->unique();
|
||||||
|
|
||||||
$table->foreignId('server_id');
|
$table->foreignId('server_id');
|
||||||
|
@ -17,7 +17,7 @@ class StandaloneDockerSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
$server_1 = Server::find(1);
|
$server_1 = Server::find(1);
|
||||||
StandaloneDocker::create([
|
StandaloneDocker::create([
|
||||||
'id' => 1,
|
'name' => 'Standalone Docker 1',
|
||||||
'network' => 'coolify',
|
'network' => 'coolify',
|
||||||
'server_id' => $server_1->id,
|
'server_id' => $server_1->id,
|
||||||
]);
|
]);
|
||||||
|
@ -16,10 +16,10 @@ class SwarmDockerSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$server_1 = Server::find(1);
|
$server_2 = Server::find(2);
|
||||||
SwarmDocker::create([
|
SwarmDocker::create([
|
||||||
'id' => 1,
|
'name' => 'Swarm Docker 1',
|
||||||
'server_id' => $server_1->id,
|
'server_id' => $server_2->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,10 @@
|
|||||||
@empty
|
@empty
|
||||||
<p>No servers found.</p>
|
<p>No servers found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
<h1>Destinations <a href="{{ route('destination.new') }}"><button>New</button></a></h1>
|
||||||
|
@forelse ($destinations as $destination)
|
||||||
|
<a href="{{ route('destination.show', [$destination->uuid]) }}">{{ data_get($destination, 'name') }}</a>
|
||||||
|
@empty
|
||||||
|
<p>No servers found.</p>
|
||||||
|
@endforelse
|
||||||
</x-layout>
|
</x-layout>
|
||||||
|
4
resources/views/destination/new.blade.php
Normal file
4
resources/views/destination/new.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>New Destination</h1>
|
||||||
|
<livewire:destination.new.standalone-docker />
|
||||||
|
</x-layout>
|
11
resources/views/destination/show.blade.php
Normal file
11
resources/views/destination/show.blade.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>Destination</h1>
|
||||||
|
<p>Name: {{ data_get($destination, 'name') }}</p>
|
||||||
|
<p>Server:{{ data_get($destination, 'server.ip') }}:{{ data_get($destination, 'server.port') }} </p>
|
||||||
|
@if ($destination->getMorphClass() === 'App\Models\StandaloneDocker')
|
||||||
|
<p>Network: {{ data_get($destination, 'network') }}</p>
|
||||||
|
@endif
|
||||||
|
@if ($destination->getMorphClass() === 'App\Models\SwarmDocker')
|
||||||
|
<p>Uuid: {{ data_get($destination, 'uuid') }}</p>
|
||||||
|
@endif
|
||||||
|
</x-layout>
|
@ -0,0 +1,15 @@
|
|||||||
|
<div>
|
||||||
|
<form class="flex flex-col" wire:submit.prevent='submit'>
|
||||||
|
<x-form-input id="name" label="Name" required />
|
||||||
|
<x-form-input id="network" label="Network" required />
|
||||||
|
<x-form-input id="server_id" label="Server ID" required />
|
||||||
|
@foreach ($servers as $key)
|
||||||
|
<button @if ($server_id == $key->id) class="bg-green-500" @endif
|
||||||
|
wire:click.prevent="setServerId('{{ $key->id }}')">{{ $key->name }}</button>
|
||||||
|
@endforeach
|
||||||
|
<button class="mt-4" type="submit">
|
||||||
|
Submit
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
@ -1,4 +1,10 @@
|
|||||||
<x-layout>
|
<x-layout>
|
||||||
<h1>Server</h1>
|
<h1>Server</h1>
|
||||||
<livewire:server.form :server_id="$server_id" />
|
<livewire:server.form :server_id="$server->id" />
|
||||||
|
<h2>Destinations</h2>
|
||||||
|
@if ($server->standaloneDockers)
|
||||||
|
@foreach ($server->standaloneDockers as $docker)
|
||||||
|
<p>Network: {{ data_get($docker, 'network') }}</p>
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
</x-layout>
|
</x-layout>
|
||||||
|
@ -4,6 +4,8 @@ use App\Http\Controllers\ApplicationController;
|
|||||||
use App\Http\Controllers\HomeController;
|
use App\Http\Controllers\HomeController;
|
||||||
use App\Http\Controllers\ProjectController;
|
use App\Http\Controllers\ProjectController;
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
|
use App\Models\StandaloneDocker;
|
||||||
|
use App\Models\SwarmDocker;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -23,9 +25,13 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
$projects = session('currentTeam')->load(['projects'])->projects;
|
$projects = session('currentTeam')->load(['projects'])->projects;
|
||||||
$servers = session('currentTeam')->load(['servers'])->servers;
|
$servers = session('currentTeam')->load(['servers'])->servers;
|
||||||
|
$destinations = $servers->map(function ($server) {
|
||||||
|
return $server->standaloneDockers->merge($server->swarmDockers);
|
||||||
|
})->flatten();
|
||||||
return view('dashboard', [
|
return view('dashboard', [
|
||||||
'servers' => $servers->sortBy('name'),
|
'servers' => $servers->sortBy('name'),
|
||||||
'projects' => $projects->sortBy('name')
|
'projects' => $projects->sortBy('name'),
|
||||||
|
'destinations' => $destinations->sortBy('name'),
|
||||||
]);
|
]);
|
||||||
})->name('dashboard');
|
})->name('dashboard');
|
||||||
|
|
||||||
@ -62,11 +68,26 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
return view('server.show', [
|
return view('server.show', [
|
||||||
'server_id' => $server->id,
|
'server' => $server,
|
||||||
]);
|
]);
|
||||||
})->name('server.show');
|
})->name('server.show');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::middleware(['auth'])->group(function () {
|
||||||
|
Route::get('/destination/new', fn () => view('destination.new'))->name('destination.new');
|
||||||
|
Route::get('/destination/{destination_uuid}', function () {
|
||||||
|
$standalone_dockers = StandaloneDocker::where('uuid', request()->destination_uuid)->first();
|
||||||
|
$swarm_dockers = SwarmDocker::where('uuid', request()->destination_uuid)->first();
|
||||||
|
if (!$standalone_dockers && !$swarm_dockers) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
$destination = $standalone_dockers ? $standalone_dockers : $swarm_dockers;
|
||||||
|
return view('destination.show', [
|
||||||
|
'destination' => $destination,
|
||||||
|
]);
|
||||||
|
})->name('destination.show');
|
||||||
|
});
|
||||||
|
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::get('/project/new', fn () => view('project.new', ['type' => 'project']))->name('project.new');
|
Route::get('/project/new', fn () => view('project.new', ['type' => 'project']))->name('project.new');
|
||||||
Route::get(
|
Route::get(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user