forked from coollabsio/coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update SSH key generation in install.sh script
- Loading branch information
1 parent
f1881d5
commit be8573c
Showing
3 changed files
with
77 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,18 @@ class PopulateSshKeysAndClearMuxDirectory extends Migration | |
{ | ||
public function up() | ||
{ | ||
Storage::disk('ssh-keys')->deleteDirectory(''); | ||
Storage::disk('ssh-keys')->makeDirectory(''); | ||
// Storage::disk('ssh-keys')->deleteDirectory(''); | ||
// Storage::disk('ssh-keys')->makeDirectory(''); | ||
|
||
Storage::disk('ssh-mux')->deleteDirectory(''); | ||
Storage::disk('ssh-mux')->makeDirectory(''); | ||
PrivateKey::chunk(100, function ($keys) { | ||
foreach ($keys as $key) { | ||
$key->storeInFileSystem(); | ||
if ($key->id === 0) { | ||
Storage::disk('ssh-keys')->put('[email protected]', $key->private_key); | ||
} | ||
} | ||
}); | ||
// Storage::disk('ssh-mux')->deleteDirectory(''); | ||
// Storage::disk('ssh-mux')->makeDirectory(''); | ||
// PrivateKey::chunk(100, function ($keys) { | ||
// foreach ($keys as $key) { | ||
// $key->storeInFileSystem(); | ||
// if ($key->id === 0) { | ||
// Storage::disk('ssh-keys')->put('[email protected]', $key->private_key); | ||
// } | ||
// } | ||
// }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,27 +64,67 @@ public function run(): void | |
'team_id' => 0, | ||
]); | ||
} | ||
// Add Coolify host (localhost) as Server if it doesn't exist | ||
if (Server::find(0) == null) { | ||
$server_details = [ | ||
'id' => 0, | ||
'name' => 'localhost', | ||
'description' => "This is the server where Coolify is running on. Don't delete this!", | ||
'user' => 'root', | ||
'ip' => 'host.docker.internal', | ||
'team_id' => 0, | ||
'private_key_id' => 0, | ||
]; | ||
$server_details['proxy'] = ServerMetadata::from([ | ||
'type' => ProxyTypes::TRAEFIK->value, | ||
'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', | ||
'network' => 'coolify', | ||
'server_id' => 0, | ||
]); | ||
} | ||
|
||
if (! isCloud() && config('coolify.is_windows_docker_desktop') == false) { | ||
echo "Checking localhost key.\n"; | ||
$coolify_key_name = '@host.docker.internal'; | ||
$ssh_keys_directory = Storage::disk('ssh-keys')->files(); | ||
$coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name)); | ||
|
||
$found = PrivateKey::find(0); | ||
if ($found) { | ||
echo 'Private Key found in database.'; | ||
if ($coolify_key) { | ||
echo "SSH key found for the Coolify host machine (localhost).\n"; | ||
Storage::disk('ssh-keys')->delete($coolify_key); | ||
} | ||
} else { | ||
$coolify_key_name = '[email protected]'; | ||
$coolify_key = Storage::disk('ssh-keys')->get("{$coolify_key_name}"); | ||
|
||
if ($coolify_key) { | ||
PrivateKey::create( | ||
[ | ||
'id' => 0, | ||
'team_id' => 0, | ||
'name' => 'localhost\'s key', | ||
'description' => 'The private key for the Coolify host machine (localhost).', | ||
'private_key' => $coolify_key, | ||
] | ||
); | ||
$coolify_key = Storage::disk('ssh-keys')->get($coolify_key); | ||
$user = str($coolify_key)->before('@')->after('id.'); | ||
PrivateKey::create([ | ||
'id' => 0, | ||
'team_id' => 0, | ||
'name' => 'localhost\'s key', | ||
'description' => 'The private key for the Coolify host machine (localhost).', | ||
'private_key' => $coolify_key, | ||
]); | ||
$server->update(['user' => $user]); | ||
echo "SSH key found for the Coolify host machine (localhost).\n"; | ||
Storage::disk('ssh-keys')->delete($coolify_key); | ||
} else { | ||
PrivateKey::create( | ||
[ | ||
|
@@ -101,39 +141,6 @@ public function run(): void | |
} | ||
} | ||
|
||
// Add Coolify host (localhost) as Server if it doesn't exist | ||
if (Server::find(0) == null) { | ||
$server_details = [ | ||
'id' => 0, | ||
'name' => 'localhost', | ||
'description' => "This is the server where Coolify is running on. Don't delete this!", | ||
'user' => 'root', | ||
'ip' => 'host.docker.internal', | ||
'team_id' => 0, | ||
'private_key_id' => 0, | ||
]; | ||
$server_details['proxy'] = ServerMetadata::from([ | ||
'type' => ProxyTypes::TRAEFIK->value, | ||
'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', | ||
'network' => 'coolify', | ||
'server_id' => 0, | ||
]); | ||
} | ||
} | ||
if (config('coolify.is_windows_docker_desktop')) { | ||
PrivateKey::updateOrCreate( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters