Merge pull request #1009 from coollabsio/project-basics

Project basics
This commit is contained in:
Andras Bacsai 2023-03-28 08:32:07 +02:00 committed by GitHub
commit 46c2d311e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 689 additions and 33 deletions

View File

@ -13,6 +13,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_PORT=8000
DB_CONNECTION=pgsql
DB_HOST=postgres

View File

@ -7,6 +7,7 @@
use Illuminate\Process\ProcessResult;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Models\Activity;
class RunRemoteProcess
@ -69,13 +70,15 @@ protected function getCommand(): string
$command = $this->activity->getExtraProperty('command');
$delimiter = 'EOF-COOLIFY-SSH';
Storage::disk('local')->makeDirectory('.ssh');
$ssh_command = "ssh "
. "-i {$private_key_location} "
. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
. '-o PasswordAuthentication=no '
. '-o RequestTTY=no '
. "-o LogLevel=ERROR "
. '-o LogLevel=ERROR '
. '-o ControlMaster=auto -o ControlPersist=yes -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/.ssh/ssh_mux_%h_%p_%r '
. "-p {$port} "
. "{$user}@{$destination} "
. " 'bash -se' << \\$delimiter" . PHP_EOL

View File

@ -0,0 +1,12 @@
<?php
namespace App\Http\Controllers;
class HomeController extends Controller
{
public function show()
{
$projects = session('currentTeam')->projects;
return view('home', ['projects' => $projects]);
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Models;
class Application extends BaseModel
{
public function environment()
{
return $this->belongsTo(Environment::class);
}
public function destination()
{
return $this->morphTo();
}
}

15
app/Models/Database.php Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace App\Models;
class Database extends BaseModel
{
public function environment()
{
return $this->belongsTo(Environment::class);
}
public function destination()
{
return $this->morphTo();
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Models;
class Environment extends BaseModel
{
public function applications()
{
return $this->hasMany(Application::class);
}
public function databases()
{
return $this->hasMany(Database::class);
}
public function services()
{
return $this->hasMany(Service::class);
}
}

11
app/Models/Kubernetes.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Kubernetes extends Model
{
use HasFactory;
}

View File

@ -4,13 +4,8 @@
class PrivateKey extends BaseModel
{
public function private_keyables()
{
return $this->hasMany(PrivateKeyable::class);
}
public function servers()
{
return $this->morphedByMany(Server::class, 'private_keyable');
return $this->hasMany(Server::class);
}
}

13
app/Models/Project.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace App\Models;
class Project extends BaseModel
{
public function environments() {
return $this->hasMany(Environment::class);
}
public function settings() {
return $this->hasOne(ProjectSetting::class);
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace App\Models;
class ProjectSetting extends BaseModel
{
}

View File

@ -4,8 +4,8 @@
class Server extends BaseModel
{
public function privateKeys()
public function privateKey()
{
return $this->morphToMany(PrivateKey::class, 'private_keyable');
return $this->belongsTo(PrivateKey::class);
}
}

16
app/Models/Service.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace App\Models;
class Service extends BaseModel
{
public function environment()
{
return $this->belongsTo(Environment::class);
}
public function destination()
{
return $this->morphTo();
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
class StandaloneDocker extends BaseModel
{
public function applications()
{
return $this->morphMany(Application::class, 'destination');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
class SwarmDocker extends BaseModel
{
public function applications()
{
return $this->morphMany(Application::class, 'destination');
}
}

View File

@ -10,4 +10,10 @@ class Team extends BaseModel
protected $fillable = [
'name',
];
public function projects() {
return $this->hasMany(Project::class);
}
public function servers() {
return $this->hasMany(Server::class);
}
}

View File

@ -20,7 +20,7 @@ function remoteProcess(
checkTeam($found_server->team_id);
$temp_file = 'id.rsa_'.'root'.'@'.$found_server->ip;
Storage::disk('local')->put($temp_file, $found_server->privateKeys->first()->private_key, 'private');
Storage::disk('local')->put($temp_file, $found_server->privateKey->private_key, 'private');
$private_key_location = '/var/www/html/storage/app/'.$temp_file;
return resolve(DispatchRemoteProcess::class, [

View File

@ -20,6 +20,7 @@ public function up(): void
$table->integer('port')->default(22);
$table->string('user')->default('root');
$table->foreignId('team_id');
$table->foreignId('private_key_id');
$table->timestamps();
});
}

View File

@ -17,7 +17,6 @@ public function up(): void
$table->string('name');
$table->string('description')->nullable();
$table->longText('private_key');
$table->nullableMorphs('private_keys_morph');
$table->timestamps();
});
}

View File

@ -0,0 +1,33 @@
<?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::create('projects', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name');
$table->string('description')->nullable();
$table->foreignId('team_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('projects');
}
};

View File

@ -11,11 +11,13 @@
*/
public function up(): void
{
Schema::create('private_keyables', function (Blueprint $table) {
Schema::create('project_settings', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('private_key_id');
$table->unsignedBigInteger('private_keyable_id');
$table->string('private_keyable_type');
$table->string('uuid')->unique();
$table->string('wildcard_domain')->nullable();
$table->foreignId('project_id');
$table->timestamps();
});
}
@ -25,6 +27,6 @@ public function up(): void
*/
public function down(): void
{
Schema::dropIfExists('private_keyables');
Schema::dropIfExists('project_settings');
}
};

View File

@ -0,0 +1,30 @@
<?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::create('environments', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name')->unique();
$table->foreignId('project_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('environments');
}
};

View File

@ -0,0 +1,33 @@
<?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::create('applications', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name');
$table->morphs('destination');
$table->foreignId('environment_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('applications');
}
};

View File

@ -0,0 +1,33 @@
<?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::create('databases', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name');
$table->morphs('destination');
$table->foreignId('environment_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('databases');
}
};

View File

@ -0,0 +1,32 @@
<?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::create('services', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name');
$table->morphs('destination');
$table->foreignId('environment_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('services');
}
};

View File

@ -0,0 +1,30 @@
<?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::create('standalone_dockers', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->foreignId('server_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('standalone_dockers');
}
};

View File

@ -0,0 +1,30 @@
<?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::create('swarm_dockers', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->foreignId('server_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('swarm_dockers');
}
};

View File

@ -0,0 +1,27 @@
<?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::create('kubernetes', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('kubernetes');
}
};

View File

@ -0,0 +1,37 @@
<?php
namespace Database\Seeders;
use App\Models\Application;
use App\Models\Environment;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Database\Seeder;
class ApplicationSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$environment_1 = Environment::find(1);
$standalone_docker_1 = StandaloneDocker::find(1);
$swarm_docker_1 = SwarmDocker::find(1);
Application::create([
'id' => 1,
'name' => 'My first application',
'environment_id' => $environment_1->id,
'destination_id' => $standalone_docker_1->id,
'destination_type' => StandaloneDocker::class,
]);
Application::create([
'id' => 2,
'name' => 'My second application (Swarm)',
'environment_id' => $environment_1->id,
'destination_id' => $swarm_docker_1->id,
'destination_type' => SwarmDocker::class,
]);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Seeders;
use App\Models\Database;
use App\Models\Environment;
use App\Models\StandaloneDocker;
use Illuminate\Database\Seeder;
class DBSeeder extends Seeder
{
public function run(): void
{
$environment_1 = Environment::find(1);
$standalone_docker_1 = StandaloneDocker::find(1);
Database::create([
'id' => 1,
'name'=> "My first database",
'environment_id' => $environment_1->id,
'destination_id' => $standalone_docker_1->id,
'destination_type' => StandaloneDocker::class,
]);
}
}

View File

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\StandaloneDocker;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
@ -12,8 +13,17 @@ public function run(): void
$this->call([
UserSeeder::class,
TeamSeeder::class,
ServerSeeder::class,
PrivateKeySeeder::class,
ServerSeeder::class,
ProjectSeeder::class,
ProjectSettingSeeder::class,
EnvironmentSeeder::class,
StandaloneDockerSeeder::class,
SwarmDockerSeeder::class,
KubernetesSeeder::class,
ApplicationSeeder::class,
DBSeeder::class,
ServiceSeeder::class,
]);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Database\Seeders;
use App\Models\Environment;
use App\Models\Project;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class EnvironmentSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$project_1 = Project::find(1);
Environment::create([
'id' => 1,
'name' => 'production',
'project_id' => $project_1->id,
]);
Environment::create([
'id' => 2,
'name' => 'staging',
'project_id' => $project_1->id,
]);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class KubernetesSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}

View File

@ -14,9 +14,7 @@ class PrivateKeySeeder extends Seeder
*/
public function run(): void
{
$server = Server::find(1);
$server2 = Server::find(2);
$private_key = PrivateKey::create([
PrivateKey::create([
"name" => "Testing-host",
"description" => "This is a test docker container",
"private_key" => "-----BEGIN OPENSSH PRIVATE KEY-----
@ -26,9 +24,7 @@ public function run(): void
AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV
uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
-----END OPENSSH PRIVATE KEY-----
",
"
]);
$server->privateKeys()->attach($private_key);
$server2->privateKeys()->attach($private_key);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\Project;
use App\Models\Team;
use Illuminate\Database\Seeder;
class ProjectSeeder extends Seeder
{
public function run(): void
{
$root_team = Team::find(1);
Project::create([
'id' => 1,
'name' => "My first project",
'description' => "This is a test project in development",
'team_id' => $root_team->id,
]);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\Project;
use App\Models\ProjectSetting;
use Illuminate\Database\Seeder;
class ProjectSettingSeeder extends Seeder
{
public function run(): void
{
$first_project = Project::find(1);
ProjectSetting::create([
'id' => 1,
'wildcard_domain' => 'testing-host.localhost',
'project_id' => $first_project->id,
]);
}
}

View File

@ -2,10 +2,12 @@
namespace Database\Seeders;
use App\Models\PrivateKey;
use App\Models\Server;
use App\Models\Team;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ServerSeeder extends Seeder
{
@ -15,12 +17,14 @@ class ServerSeeder extends Seeder
public function run(): void
{
$root_team = Team::find(1);
Server::create([
$private_key_1 = PrivateKey::find(1);
$server_1 = Server::create([
'id' => 1,
'name' => "testing-host",
'description' => "This is a test docker container",
'ip' => "coolify-testing-host",
'team_id' => $root_team->id,
'private_key_id' => $private_key_1->id,
]);
Server::create([
'id' => 2,
@ -28,6 +32,8 @@ public function run(): void
'description' => "This is a test docker container",
'ip' => "coolify-testing-host-2",
'team_id' => $root_team->id,
'private_key_id' => $private_key_1->id,
]);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Database\Seeders;
use App\Models\Environment;
use App\Models\Service;
use App\Models\StandaloneDocker;
use Illuminate\Database\Seeder;
class ServiceSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$environment_1 = Environment::find(1);
$standalone_docker_1 = StandaloneDocker::find(1);
Service::create([
'id' => 1,
'name'=> "My first database",
'environment_id' => $environment_1->id,
'destination_id' => $standalone_docker_1->id,
'destination_type' => StandaloneDocker::class,
]);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Seeders;
use App\Models\Destination;
use App\Models\Server;
use App\Models\StandaloneDocker;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class StandaloneDockerSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$server_1 = Server::find(1);
StandaloneDocker::create([
'id' => 1,
'server_id' => $server_1->id,
]);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Database\Seeders;
use App\Models\Destination;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class SwarmDockerSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$server_1 = Server::find(1);
SwarmDocker::create([
'id' => 1,
'server_id' => $server_1->id,
]);
}
}

View File

@ -1,10 +1,10 @@
<nav>
<a href="/">Home</a>
@guest
<a href="/login">Login</a>
<a href="/register">Register</a>
@endguest
@auth
<a href="/">Home</a>
<a href="/demo">Demo</a>
<a href="/profile">Profile</a>
<form action="/logout" method="POST">

View File

@ -2,9 +2,43 @@
<h1>
Coolify v4 🎉
</h1>
@guest
<p>
To see the demo, please <a href='/login'>login<a> or <a href='/register'>register<a>.
</p>
@endguest
<h1>Projects</h1>
<ul>
@forelse ($projects as $project)
<h2>{{ $project->name }}</h2>
<p>Project Settings:{{ $project->settings }}</p>
<h2>Environments</h2>
@forelse ($project->environments as $environment)
<h1>Environment: {{ $environment->name }}</h1>
<h2>Applications</h2>
@forelse ($environment->applications as $application)
<h3>{{ $application->name }}</h3>
<p>Application: {{ $application }}</p>
<p>Destination Class: {{ $application->destination->getMorphClass() }}</p>
@empty
<li>No application found</li>
@endforelse
<h2>Databases</h2>
@forelse ($environment->databases as $database)
<h3>{{ $database->name }}</h3>
<p>Database: {{ $database }}</p>
<p>Destination Class: {{ $database->destination->getMorphClass() }}</p>
@empty
<li>No database found</li>
@endforelse
<h2>Services</h2>
@forelse ($environment->services as $service)
<h3>{{ $service->name }}</h3>
<p>Service: {{ $service }}</p>
<p>Destination Class: {{ $service->destination->getMorphClass() }}</p>
@empty
<li>No service found</li>
@endforelse
@empty
<p>No environments found</p>
@endforelse
@empty
<li>No projects found</li>
@endforelse
</ul>
</x-layout>

View File

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
/*
@ -13,11 +14,10 @@
|
*/
Route::get('/', function () {
return view('home');
});
Route::middleware(['auth'])->group(function () {
Route::get('/', [HomeController::class, 'show']);
Route::get('/profile', function () {
return view('profile');
});