2023-04-14 08:00:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2023-04-27 09:29:02 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2023-04-14 08:00:42 +00:00
|
|
|
use App\Models\PrivateKey;
|
|
|
|
use App\Models\Project;
|
2023-04-14 10:54:29 +00:00
|
|
|
use App\Models\Server;
|
2023-04-14 08:00:42 +00:00
|
|
|
use App\Models\Team;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
class ProductionSeeder extends Seeder
|
|
|
|
{
|
|
|
|
public function run(): void
|
|
|
|
{
|
2023-04-27 09:29:02 +00:00
|
|
|
if (InstanceSettings::find(0) == null) {
|
|
|
|
InstanceSettings::create([
|
|
|
|
'id' => 0
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add first Team if it doesn't exist
|
|
|
|
if (Team::find(0) == null) {
|
|
|
|
Team::create([
|
|
|
|
'id' => 0,
|
|
|
|
'name' => "Root's Team",
|
|
|
|
'personal_team' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-04-14 10:54:29 +00:00
|
|
|
// Save SSH Keys for the Coolify Host
|
2023-04-14 08:30:53 +00:00
|
|
|
$coolify_key_name = "id.root@host.docker.internal";
|
|
|
|
$coolify_key = Storage::disk('local')->get("ssh-keys/{$coolify_key_name}");
|
|
|
|
|
2023-04-27 10:25:32 +00:00
|
|
|
if ($coolify_key) {
|
|
|
|
$private_key = PrivateKey::find(0);
|
|
|
|
if ($private_key == null) {
|
|
|
|
PrivateKey::create([
|
|
|
|
'id' => 0,
|
|
|
|
'name' => 'localhost\'s key',
|
|
|
|
'description' => 'The private key for the Coolify host machine (localhost).',
|
|
|
|
'private_key' => $coolify_key,
|
|
|
|
'team_id' => 0,
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$private_key->private_key = $coolify_key;
|
|
|
|
$private_key->save();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "No SSH key found for the Coolify host machine (localhost).\n";
|
|
|
|
echo "Please generate one and save it in storage/app/ssh-keys/{$coolify_key_name}\n";
|
|
|
|
exit(1);
|
2023-04-14 08:30:53 +00:00
|
|
|
}
|
2023-04-27 09:29:02 +00:00
|
|
|
|
2023-04-14 10:54:29 +00:00
|
|
|
// Add Coolify host (localhost) as Server if it doesn't exist
|
|
|
|
if (Server::find(0) == null) {
|
|
|
|
Server::create([
|
|
|
|
'id' => 0,
|
|
|
|
'name' => "localhost",
|
|
|
|
'description' => "This is the local machine",
|
|
|
|
'user' => 'root',
|
|
|
|
'ip' => "host.docker.internal",
|
|
|
|
'team_id' => 0,
|
|
|
|
'private_key_id' => 0,
|
|
|
|
]);
|
|
|
|
}
|
2023-04-14 08:00:42 +00:00
|
|
|
}
|
|
|
|
}
|