Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Add servers and privatekeys to database

Andras Bacsaif7c615c95852
diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php
new file mode 100644
index 0000000000..6da73fc879
--- /dev/null
+++ b/app/Models/PrivateKey.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+class PrivateKey extends BaseModel
+{
+ public function private_key_morph()
+ {
+ return $this->morphTo();
+ }
+}
diff --git a/app/Models/Server.php b/app/Models/Server.php
new file mode 100644
index 0000000000..8e025a75e1
--- /dev/null
+++ b/app/Models/Server.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+class Server extends BaseModel
+{
+ public function private_key()
+ {
+ return $this->morphMany(PrivateKey::class, 'private_key_morph');
+ }
+}
diff --git a/database/migrations/2023_03_24_140711_create_servers_table.php b/database/migrations/2023_03_24_140711_create_servers_table.php
new file mode 100644
index 0000000000..0cbd2419a8
--- /dev/null
+++ b/database/migrations/2023_03_24_140711_create_servers_table.php
@@ -0,0 +1,34 @@
+<?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('servers', function (Blueprint $table) {
+ $table->id();
+ $table->string('uuid')->unique();
+ $table->string('name');
+ $table->string('description')->nullable();
+ $table->string('ip');
+ $table->integer('port')->default(22);
+ $table->string('user')->default('root');
+ $table->foreignId('team_id');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('servers');
+ }
+};
diff --git a/database/migrations/2023_03_24_140853_create_private_keys_table.php b/database/migrations/2023_03_24_140853_create_private_keys_table.php
new file mode 100644
index 0000000000..3304ed9186
--- /dev/null
+++ b/database/migrations/2023_03_24_140853_create_private_keys_table.php
@@ -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('private_keys', function (Blueprint $table) {
+ $table->id();
+ $table->string('uuid')->unique();
+ $table->string('name');
+ $table->string('description')->nullable();
+ $table->longText('private_key');
+ $table->nullableMorphs('private_key_morph');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('private_keys');
+ }
+};
diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php
index 7b2f6bbcd6..19606f85a7 100644
--- a/database/seeders/DatabaseSeeder.php
+++ b/database/seeders/DatabaseSeeder.php
@@ -12,6 +12,8 @@ class DatabaseSeeder extends Seeder
$this->call([
UserSeeder::class,
TeamSeeder::class,
+ ServerSeeder::class,
+ PrivateKeySeeder::class,
]);
}
}
diff --git a/database/seeders/PrivateKeySeeder.php b/database/seeders/PrivateKeySeeder.php
new file mode 100644
index 0000000000..522c4c703f
--- /dev/null
+++ b/database/seeders/PrivateKeySeeder.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\Models\PrivateKey;
+use App\Models\Server;
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+
+class PrivateKeySeeder extends Seeder
+{
+ /**
+ * Run the database seeds.
+ */
+ public function run(): void
+ {
+ $server = Server::find(1);
+ PrivateKey::create([
+ "name" => "Testing-host",
+ "description" => "This is a test docker container",
+ "private_key" => "-----BEGIN OPENSSH PRIVATE KEY-----\
+ b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\
+ QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk\
+ hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA\
+ AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV\
+ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==\
+ -----END OPENSSH PRIVATE KEY-----",
+ ])->private_key_morph()->associate($server)->save();
+ }
+}
diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php
new file mode 100644
index 0000000000..8d14996890
--- /dev/null
+++ b/database/seeders/ServerSeeder.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\Models\Server;
+use App\Models\Team;
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+
+class ServerSeeder extends Seeder
+{
+ /**
+ * Run the database seeds.
+ */
+ public function run(): void
+ {
+ $root_team = Team::find(1);
+ Server::create([
+ 'id' => 1,
+ 'name' => "testing-host",
+ 'description' => "This is a test docker container",
+ 'ip' => "coolify-testing-host",
+ 'team_id' => $root_team->id,
+ ]);
+ }
+}