lasthourcloud/database/seeders/ProductionSeeder.php

185 lines
6.8 KiB
PHP
Raw Normal View History

2023-04-14 08:00:42 +00:00
<?php
namespace Database\Seeders;
2023-05-22 10:47:15 +00:00
use App\Data\ServerMetadata;
use App\Enums\ProxyStatus;
use App\Enums\ProxyTypes;
2023-05-02 12:12:15 +00:00
use App\Models\GithubApp;
use App\Models\GitlabApp;
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\Server;
2023-05-24 12:56:41 +00:00
use App\Models\StandaloneDocker;
2023-09-15 15:57:17 +00:00
use App\Models\Team;
use App\Models\User;
2023-04-14 08:00:42 +00:00
use Illuminate\Database\Seeder;
2023-10-12 10:18:26 +00:00
use Illuminate\Support\Facades\DB;
2023-04-14 08:00:42 +00:00
use Illuminate\Support\Facades\Storage;
class ProductionSeeder extends Seeder
{
public function run(): void
{
2023-10-12 10:18:26 +00:00
if (isCloud()) {
echo "Running in cloud mode.\n";
} else {
echo "Running in self-hosted mode.\n";
}
2023-09-15 15:57:17 +00:00
// Fix for 4.0.0-beta.37
if (User::find(0) !== null && Team::find(0) !== null) {
if (DB::table('team_user')->where('user_id', 0)->first() === null) {
DB::table('team_user')->insert([
'user_id' => 0,
'team_id' => 0,
'role' => 'owner',
'created_at' => now(),
'updated_at' => now(),
]);
}
}
2023-04-27 09:29:02 +00:00
if (InstanceSettings::find(0) == null) {
InstanceSettings::create([
2024-06-10 20:43:34 +00:00
'id' => 0,
2023-04-27 09:29:02 +00:00
]);
}
2023-05-08 07:33:10 +00:00
if (GithubApp::find(0) == null) {
GithubApp::create([
'id' => 0,
'name' => 'Public GitHub',
'api_url' => 'https://api.github.com',
'html_url' => 'https://github.com',
'is_public' => true,
'team_id' => 0,
]);
}
if (GitlabApp::find(0) == null) {
GitlabApp::create([
'id' => 0,
'name' => 'Public GitLab',
'api_url' => 'https://gitlab.com/api/v4',
'html_url' => 'https://gitlab.com',
'is_public' => true,
'team_id' => 0,
]);
}
2023-04-27 09:29:02 +00:00
2024-06-10 20:43:34 +00:00
if (! isCloud() && config('coolify.is_windows_docker_desktop') == false) {
echo "Checking localhost key.\n";
2023-08-28 13:03:44 +00:00
// Save SSH Keys for the Coolify Host
2024-06-10 20:43:34 +00:00
$coolify_key_name = 'id.root@host.docker.internal';
2023-08-28 13:03:44 +00:00
$coolify_key = Storage::disk('ssh-keys')->get("{$coolify_key_name}");
2023-08-28 13:03:44 +00:00
if ($coolify_key) {
PrivateKey::updateOrCreate(
[
'id' => 0,
'team_id' => 0,
],
2023-09-29 08:32:32 +00:00
[
'name' => 'localhost\'s key',
2024-06-10 20:43:34 +00:00
'description' => 'The private key for the Coolify host machine (localhost).', 'private_key' => $coolify_key,
2023-09-29 08:32:32 +00:00
]
2023-08-28 13:03:44 +00:00
);
} else {
echo "No SSH key found for the Coolify host machine (localhost).\n";
echo "Please generate one and save it in /data/coolify/ssh/keys/{$coolify_key_name}\n";
echo "Then try to install again.\n";
exit(1);
}
// Add Coolify host (localhost) as Server if it doesn't exist
if (Server::find(0) == null) {
$server_details = [
2023-04-27 10:25:32 +00:00
'id' => 0,
2024-06-10 20:43:34 +00:00
'name' => 'localhost',
2023-08-28 13:03:44 +00:00
'description' => "This is the server where Coolify is running on. Don't delete this!",
'user' => 'root',
2024-06-10 20:43:34 +00:00
'ip' => 'host.docker.internal',
2023-04-27 10:25:32 +00:00
'team_id' => 0,
2024-06-10 20:43:34 +00:00
'private_key_id' => 0,
2023-08-28 13:03:44 +00:00
];
$server_details['proxy'] = ServerMetadata::from([
'type' => ProxyTypes::TRAEFIK_V2->value,
2024-06-10 20:43:34 +00:00
'status' => ProxyStatus::EXITED->value,
2023-08-28 13:03:44 +00:00
]);
$server = Server::create($server_details);
$server->settings->is_reachable = true;
$server->settings->is_usable = true;
$server->settings->save();
} else {
$server = Server::find(0);
$server->settings->is_reachable = true;
$server->settings->is_usable = true;
$server->settings->save();
}
if (StandaloneDocker::find(0) == null) {
StandaloneDocker::create([
'id' => 0,
'name' => 'localhost-coolify',
'network' => 'coolify',
'server_id' => 0,
]);
}
}
if (config('coolify.is_windows_docker_desktop')) {
PrivateKey::updateOrCreate(
[
'id' => 0,
'team_id' => 0,
],
[
2024-06-10 20:43:34 +00:00
'name' => 'Testing-host',
'description' => 'This is a a docker container with SSH access',
'private_key' => '-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk
hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA
AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV
uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
-----END OPENSSH PRIVATE KEY-----
2024-06-10 20:43:34 +00:00
',
]
);
if (Server::find(0) == null) {
$server_details = [
'id' => 0,
'uuid' => 'coolify-testing-host',
2024-06-10 20:43:34 +00:00
'name' => 'localhost',
'description' => "This is the server where Coolify is running on. Don't delete this!",
'user' => 'root',
2024-06-10 20:43:34 +00:00
'ip' => 'coolify-testing-host',
'team_id' => 0,
2024-06-10 20:43:34 +00:00
'private_key_id' => 0,
];
$server_details['proxy'] = ServerMetadata::from([
'type' => ProxyTypes::TRAEFIK_V2->value,
2024-06-10 20:43:34 +00:00
'status' => ProxyStatus::EXITED->value,
]);
$server = Server::create($server_details);
$server->settings->is_reachable = true;
$server->settings->is_usable = true;
$server->settings->save();
} else {
$server = Server::find(0);
$server->settings->is_reachable = true;
$server->settings->is_usable = true;
$server->settings->save();
}
if (StandaloneDocker::find(0) == null) {
StandaloneDocker::create([
'id' => 0,
'name' => 'localhost-coolify',
2023-08-28 13:03:44 +00:00
'network' => 'coolify',
'server_id' => 0,
]);
}
}
2023-04-27 09:29:02 +00:00
2024-04-25 11:52:52 +00:00
get_public_ips();
2024-07-24 12:27:21 +00:00
$oauth_settings_seeder = new OauthSettingSeeder;
$oauth_settings_seeder->run();
2023-04-14 08:00:42 +00:00
}
}