Add production seeder

Add ssh-key custom storage
This commit is contained in:
Andras Bacsai 2023-04-14 10:30:53 +02:00
parent bb694cbffd
commit 310cac8233
3 changed files with 30 additions and 11 deletions

View File

@ -59,9 +59,9 @@ function remoteProcess(
if (!function_exists('savePrivateKeyForServer')) {
function savePrivateKeyForServer(Server $server)
{
$temp_file = 'id.rsa_' . 'root' . '@' . $server->ip;
Storage::disk('local')->put($temp_file, $server->privateKey->private_key, 'private');
return '/var/www/html/storage/app/' . $temp_file;
$temp_file = "id.root@{$server->ip}";
Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key, 'private');
return '/var/www/html/storage/app/ssh-keys/' . $temp_file;
}
}

View File

@ -44,6 +44,22 @@
'throw' => false,
],
'ssh-keys' => [
'driver' => 'local',
'root' => storage_path('app/ssh-keys'),
'url' => env('APP_URL').'/storage',
'visibility' => 'private',
'throw' => false,
],
'deployments' => [
'driver' => 'local',
'root' => storage_path('app/deployments'),
'url' => env('APP_URL').'/storage',
'visibility' => 'private',
'throw' => false,
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),

View File

@ -12,16 +12,19 @@ class ProductionSeeder extends Seeder
{
public function run(): void
{
$coolify_key = Storage::disk('local')->get('ssh-keys/coolify.dsa');
if (PrivateKey::where('name', 'Coolify Host')->doesntExist()) {
$coolify_key_name = "id.root@host.docker.internal";
$coolify_key = Storage::disk('local')->get("ssh-keys/{$coolify_key_name}");
$coolify_key_in_database = PrivateKey::where('name', 'Coolify Host');
if (!$coolify_key && $coolify_key_in_database->exists()) {
Storage::disk('local')->put("ssh-keys/{$coolify_key_name}", $coolify_key_in_database->first()->private_key);
}
if ($coolify_key && !$coolify_key_in_database->exists()) {
PrivateKey::create([
"id" => 0,
"name" => "Coolify Host",
"description" => "This is the private key for the server where Coolify is hosted.",
"private_key" => $coolify_key,
'name' => 'Coolify Host',
'description' => 'The private key for the Coolify host machine.',
'private_key' => $coolify_key,
]);
} else {
dump('Coolify SSH Key already exists.');
}
}
}