Skip to content

Commit d3a6576

Browse files
committed
fix: create the private key before the server in the prod seeder
1 parent 973429d commit d3a6576

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

database/seeders/ProductionSeeder.php

+33-32
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ProductionSeeder extends Seeder
2121
{
2222
public function run(): void
2323
{
24+
25+
$user = 'root';
2426
echo "Starting ProductionSeeder...\n";
2527

2628
if (isCloud()) {
@@ -79,6 +81,36 @@ public function run(): void
7981
]);
8082
}
8183

84+
if (! isCloud() && config('constants.coolify.is_windows_docker_desktop') == false) {
85+
echo "Setting up SSH keys for non-Windows environment...\n";
86+
$coolify_key_name = '@host.docker.internal';
87+
$ssh_keys_directory = Storage::disk('ssh-keys')->files();
88+
echo ' Found '.count($ssh_keys_directory)." SSH keys\n";
89+
$coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name));
90+
91+
$server = Server::find(0);
92+
$found = $server->privateKey;
93+
if (! $found) {
94+
if ($coolify_key) {
95+
echo " Found Coolify SSH key\n";
96+
$user = str($coolify_key)->before('@')->after('id.');
97+
$coolify_key = Storage::disk('ssh-keys')->get($coolify_key);
98+
PrivateKey::create([
99+
'id' => 0,
100+
'team_id' => 0,
101+
'name' => 'localhost\'s key',
102+
'description' => 'The private key for the Coolify host machine (localhost).',
103+
'private_key' => $coolify_key,
104+
]);
105+
echo "SSH key found for the Coolify host machine (localhost).\n";
106+
} else {
107+
echo "No SSH key found for the Coolify host machine (localhost).\n";
108+
echo "Please read the following documentation (point 3) to fix it: https://coolify.io/docs/knowledge-base/server/openssh/\n";
109+
echo "Your localhost connection won't work until then.";
110+
}
111+
}
112+
}
113+
82114
// Add Coolify host (localhost) as Server if it doesn't exist
83115
if (! isCloud()) {
84116
echo "Setting up localhost server...\n";
@@ -88,7 +120,7 @@ public function run(): void
88120
'id' => 0,
89121
'name' => 'localhost',
90122
'description' => "This is the server where Coolify is running on. Don't delete this!",
91-
'user' => 'root',
123+
'user' => $user,
92124
'ip' => 'host.docker.internal',
93125
'team_id' => 0,
94126
'private_key_id' => 0,
@@ -121,37 +153,6 @@ public function run(): void
121153
}
122154
}
123155

124-
if (! isCloud() && config('constants.coolify.is_windows_docker_desktop') == false) {
125-
echo "Setting up SSH keys for non-Windows environment...\n";
126-
$coolify_key_name = '@host.docker.internal';
127-
$ssh_keys_directory = Storage::disk('ssh-keys')->files();
128-
echo ' Found '.count($ssh_keys_directory)." SSH keys\n";
129-
$coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name));
130-
131-
$server = Server::find(0);
132-
$found = $server->privateKey;
133-
if (! $found) {
134-
if ($coolify_key) {
135-
echo " Found Coolify SSH key\n";
136-
$user = str($coolify_key)->before('@')->after('id.');
137-
$coolify_key = Storage::disk('ssh-keys')->get($coolify_key);
138-
PrivateKey::create([
139-
'id' => 0,
140-
'team_id' => 0,
141-
'name' => 'localhost\'s key',
142-
'description' => 'The private key for the Coolify host machine (localhost).',
143-
'private_key' => $coolify_key,
144-
]);
145-
$server->update(['user' => $user]);
146-
echo "SSH key found for the Coolify host machine (localhost).\n";
147-
} else {
148-
echo "No SSH key found for the Coolify host machine (localhost).\n";
149-
echo "Please read the following documentation (point 3) to fix it: https://coolify.io/docs/knowledge-base/server/openssh/\n";
150-
echo "Your localhost connection won't work until then.";
151-
}
152-
}
153-
}
154-
155156
if (config('constants.coolify.is_windows_docker_desktop')) {
156157
echo "Setting up Windows Docker Desktop environment...\n";
157158
echo " Creating/updating private key\n";

0 commit comments

Comments
 (0)