This commit is contained in:
Andras Bacsai 2023-05-25 12:55:34 +02:00
parent acaacec82d
commit 2834d7f342
8 changed files with 17 additions and 58 deletions

View File

@ -4,10 +4,8 @@ namespace App\Http\Livewire\Server;
use App\Models\PrivateKey as ModelsPrivateKey; use App\Models\PrivateKey as ModelsPrivateKey;
use App\Models\Server; use App\Models\Server;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Livewire\Component; use Livewire\Component;
use LocalStorage;
class PrivateKey extends Component class PrivateKey extends Component
{ {
@ -20,7 +18,7 @@ class PrivateKey extends Component
'private_key_id' => $private_key_id 'private_key_id' => $private_key_id
]); ]);
// Delete the old ssh mux file to force a new one to be created // Delete the old ssh mux file to force a new one to be created
LocalStorage::ssh_mux()->delete("{$server->first()->ip}_{$server->first()->port}_{$server->first()->user}"); Storage::disk('ssh-mux')->delete("{$server->first()->ip}_{$server->first()->port}_{$server->first()->user}");
return redirect()->route('server.show', $this->parameters['server_uuid']); return redirect()->route('server.show', $this->parameters['server_uuid']);
} }
public function mount() public function mount()

View File

@ -18,8 +18,6 @@ use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Models\Activity;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use LocalStorage;
use Log;
use Spatie\Url\Url; use Spatie\Url\Url;
class ApplicationDeploymentJob implements ShouldQueue class ApplicationDeploymentJob implements ShouldQueue
@ -205,7 +203,7 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap
$this->fail(); $this->fail();
} finally { } finally {
if (isset($this->docker_compose)) { if (isset($this->docker_compose)) {
LocalStorage::deployments()->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose); Storage::disk('deployments')->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose);
} }
$this->execute_now(["docker rm -f {$this->deployment_uuid} >/dev/null 2>&1"], hideFromOutput: true); $this->execute_now(["docker rm -f {$this->deployment_uuid} >/dev/null 2>&1"], hideFromOutput: true);
} }

View File

@ -4,11 +4,8 @@ namespace App\Providers;
use App\Jobs\CoolifyTask; use App\Jobs\CoolifyTask;
use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use LocalStorage;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {

View File

@ -46,20 +46,18 @@ function remote_process(
function save_private_key_for_server(Server $server) function save_private_key_for_server(Server $server)
{ {
$temp_file = "id.root@{$server->ip}"; $temp_file = "id.root@{$server->ip}";
LocalStorage::ssh_keys()->put($temp_file, $server->privateKey->private_key); Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key);
return '/var/www/html/storage/app/private/ssh/keys/' . $temp_file; Storage::disk('ssh-mux')->makeDirectory('.');
return '/var/www/html/storage/app/ssh/keys/' . $temp_file;
} }
function generate_ssh_command(string $private_key_location, string $server_ip, string $user, string $port, string $command, bool $isMux = true) function generate_ssh_command(string $private_key_location, string $server_ip, string $user, string $port, string $command, bool $isMux = true)
{ {
LocalStorage::ssh_keys();
LocalStorage::ssh_mux();
$delimiter = 'EOF-COOLIFY-SSH'; $delimiter = 'EOF-COOLIFY-SSH';
$ssh_command = "ssh "; $ssh_command = "ssh ";
if ($isMux && config('coolify.mux_enabled')) { if ($isMux && config('coolify.mux_enabled')) {
$ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/private/ssh/mux/%h_%p_%r '; $ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/ssh/mux/%h_%p_%r ';
} }
$ssh_command .= "-i {$private_key_location} " $ssh_command .= "-i {$private_key_location} "
. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ' . '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '

View File

@ -1,38 +0,0 @@
<?php
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Storage;
class LocalStorage extends Facade
{
public static function deployments()
{
$storage = Storage::build([
'driver' => 'local',
'root' => storage_path("app/private/deployments"),
'visibility' => 'private',
]);
$storage->makeDirectory('.');
return $storage;
}
public static function ssh_keys()
{
$storage = Storage::build([
'driver' => 'local',
'root' => storage_path("app/private/ssh/keys"),
'visibility' => 'private'
]);
$storage->makeDirectory('.');
return $storage;
}
public static function ssh_mux()
{
$storage = Storage::build([
'driver' => 'local',
'root' => storage_path("app/private/ssh/mux"),
'visibility' => 'private',
]);
$storage->makeDirectory('.');
return $storage;
}
}

View File

@ -43,9 +43,15 @@ return [
'throw' => false, 'throw' => false,
], ],
'ssh-mux' => [
'driver' => 'local',
'root' => storage_path('app/ssh/mux'),
'visibility' => 'private',
'throw' => false,
],
'ssh-keys' => [ 'ssh-keys' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app/ssh-keys'), 'root' => storage_path('app/ssh/keys'),
'visibility' => 'private', 'visibility' => 'private',
'throw' => false, 'throw' => false,
], ],

View File

@ -14,7 +14,6 @@ use App\Models\StandaloneDocker;
use App\Models\Team; use App\Models\Team;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use LocalStorage;
class ProductionSeeder extends Seeder class ProductionSeeder extends Seeder
{ {
@ -57,7 +56,7 @@ class ProductionSeeder extends Seeder
// Save SSH Keys for the Coolify Host // Save SSH Keys for the Coolify Host
$coolify_key_name = "id.root@host.docker.internal"; $coolify_key_name = "id.root@host.docker.internal";
$coolify_key = LocalStorage::ssh_keys()->get("{$coolify_key_name}"); $coolify_key = Storage::disk('ssh-keys')->get("{$coolify_key_name}");
if ($coolify_key) { if ($coolify_key) {
$private_key = PrivateKey::find(0); $private_key = PrivateKey::find(0);
@ -76,7 +75,7 @@ class ProductionSeeder extends Seeder
} else { } else {
// TODO: Add a command to generate a new SSH key for the Coolify host machine (localhost). // TODO: Add a command to generate a new SSH key for the Coolify host machine (localhost).
echo "No SSH key found for the Coolify host machine (localhost).\n"; 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"; echo "Please generate one and save it in storage/app/ssh/keys/{$coolify_key_name}\n";
} }
// Add Coolify host (localhost) as Server if it doesn't exist // Add Coolify host (localhost) as Server if it doesn't exist

View File

@ -7,7 +7,8 @@ services:
source: /data/coolify/source/.env source: /data/coolify/source/.env
target: /var/www/html/.env target: /var/www/html/.env
read_only: true read_only: true
- /data/coolify:/var/www/html/storage/app/ - /data/coolify/ssh:/var/www/html/storage/app/ssh
- /data/coolify/deployments:/var/www/html/storage/app/deployments
environment: environment:
- APP_ENV=production - APP_ENV=production
- APP_DEBUG - APP_DEBUG