An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
wip
Andras Bacsaia275ac5f4178
diff --git a/app/Data/ServerMetadata.php b/app/Data/ServerMetadata.phpindex af4340b389..06f11f2060 100644--- a/app/Data/ServerMetadata.php+++ b/app/Data/ServerMetadata.php@@ -2,12 +2,15 @@namespace App\Data;+use App\Enums\ProxyStatus;use App\Enums\ProxyTypes;use Spatie\LaravelData\Data;class ServerMetadata extends Data{public function __construct(- public ?ProxyTypes $proxy,- ) {}+ public ?ProxyTypes $proxy_type,+ public ?ProxyStatus $proxy_status+ ) {+ }}diff --git a/app/Enums/ProxyTypes.php b/app/Enums/ProxyTypes.phpindex f664e80066..e947921888 100644--- a/app/Enums/ProxyTypes.php+++ b/app/Enums/ProxyTypes.php@@ -8,3 +8,8 @@ enum ProxyTypes: stringcase NGINX = 'NGINX';case CADDY = 'CADDY';}+enum ProxyStatus: string+{+ case EXITED = 'exited';+ case RUNNING = 'running';+}diff --git a/app/Http/Livewire/PrivateKey/Create.php b/app/Http/Livewire/PrivateKey/Create.phpindex 9dfd6b40c8..ef6c969b6f 100644--- a/app/Http/Livewire/PrivateKey/Create.php+++ b/app/Http/Livewire/PrivateKey/Create.php@@ -8,27 +8,26 @@ use Livewire\Component;class Create extends Component{+ protected string|null $from = null;public string $name;public string|null $description = null;public string $value;- public string $currentRoute;- public function mount()- {- $this->currentRoute = Route::current()->uri();- }public function createPrivateKey(){$this->value = trim($this->value);if (!str_ends_with($this->value, "\n")) {$this->value .= "\n";}- $new_private_key = PrivateKey::create([+ $private_key = PrivateKey::create(['name' => $this->name,'description' => $this->description,'private_key' => $this->value,'team_id' => session('currentTeam')->id]);- redirect()->route('server.new');+ if ($this->from === 'server') {+ return redirect()->route('server.new');+ }+ return redirect()->route('private-key.show', ['private_key_uuid' => $private_key->uuid]);}}diff --git a/app/Http/Livewire/Server/PrivateKey.php b/app/Http/Livewire/Server/PrivateKey.phpindex dbc0474e8d..e9d6cf0720 100644--- a/app/Http/Livewire/Server/PrivateKey.php+++ b/app/Http/Livewire/Server/PrivateKey.php@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Server;use App\Models\PrivateKey as ModelsPrivateKey;use App\Models\Server;use Illuminate\Support\Facades\Route;+use Illuminate\Support\Facades\Storage;use Livewire\Component;class PrivateKey extends Component@@ -13,9 +14,13 @@ class PrivateKey extends Componentpublic $parameters;public function setPrivateKey($private_key_id){- Server::where('uuid', $this->parameters['server_uuid'])->update([+ $server = Server::where('uuid', $this->parameters['server_uuid']);+ $server->update(['private_key_id' => $private_key_id]);+ // Delete the old ssh mux file to force a new one to be created+ Storage::disk('local')->delete(".ssh/ssh_mux_{$server->first()->ip}_{$server->first()->port}_{$server->first()->user}");+return redirect()->route('server.show', $this->parameters['server_uuid']);}public function mount()diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.phpindex f248325c7f..0785973821 100644--- a/app/Http/Livewire/Server/Proxy.php+++ b/app/Http/Livewire/Server/Proxy.php@@ -17,13 +17,22 @@ class Proxy extends Componentpublic ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2;public $proxy_settings = null;+ public function mount()+ {+ $this->proxyStatus();+ }public function serverValidated(){$this->server->settings->refresh();}public function installProxy(){- $this->saveConfiguration($this->server);+ if (+ $this->server->extra_attributes->last_applied_proxy_settings &&+ $this->server->extra_attributes->last_saved_proxy_settings !== $this->server->extra_attributes->last_applied_proxy_settings+ ) {+ $this->saveConfiguration($this->server);+ }$activity = resolve(InstallProxy::class)($this->server);$this->emit('newMonitorActivity', $activity->id);}@@ -32,6 +41,7 @@ class Proxy extends Component{$this->server->extra_attributes->proxy_status = checkContainerStatus(server: $this->server, container_id: 'coolify-proxy');$this->server->save();+ $this->server->refresh();}public function setProxy(){diff --git a/bootstrap/helpers.php b/bootstrap/helpers.phpindex 9a304dd697..5d26fc05ba 100644--- a/bootstrap/helpers.php+++ b/bootstrap/helpers.php@@ -95,7 +95,7 @@ if (!function_exists('savePrivateKeyForServer')) {function savePrivateKeyForServer(Server $server){$temp_file = "id.root@{$server->ip}";- Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key, 'private');+ Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key);return '/var/www/html/storage/app/ssh-keys/' . $temp_file;}}@@ -103,9 +103,11 @@ if (!function_exists('savePrivateKeyForServer')) {if (!function_exists('generateSshCommand')) {function generateSshCommand(string $private_key_location, string $server_ip, string $user, string $port, string $command, bool $isMux = true){- $delimiter = 'EOF-COOLIFY-SSH';Storage::disk('local')->makeDirectory('.ssh');++ $delimiter = 'EOF-COOLIFY-SSH';$ssh_command = "ssh ";+if ($isMux && config('coolify.mux_enabled')) {$ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/.ssh/ssh_mux_%h_%p_%r ';}@@ -159,7 +161,6 @@ if (!function_exists('instantRemoteProcess')) {{$command_string = implode("\n", $command);$private_key_location = savePrivateKeyForServer($server);-$ssh_command = generateSshCommand($private_key_location, $server->ip, $server->user, $server->port, $command_string);$process = Process::run($ssh_command);$output = trim($process->output());diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.phpindex 8041d5a4fb..423c259f28 100644--- a/database/seeders/ServerSeeder.php+++ b/database/seeders/ServerSeeder.php@@ -3,6 +3,7 @@namespace Database\Seeders;use App\Data\ServerMetadata;+use App\Enums\ProxyStatus;use App\Enums\ProxyTypes;use App\Models\PrivateKey;use App\Models\Server;@@ -26,7 +27,8 @@ class ServerSeeder extends Seeder'team_id' => $root_team->id,'private_key_id' => $private_key_1->id,'extra_attributes' => ServerMetadata::from([- 'proxy_type' => ProxyTypes::TRAEFIK_V2->value+ 'proxy_type' => ProxyTypes::TRAEFIK_V2->value,+ 'proxy_status' => ProxyStatus::EXITED->value]),]);Server::create([diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.phpindex af5e205cc6..47cbf8b8da 100644--- a/resources/views/livewire/server/form.blade.php+++ b/resources/views/livewire/server/form.blade.php@@ -39,7 +39,6 @@</div><div class="pt-3">@isset($uptime)- <p>Connection: OK</p><p>Uptime: {{ $uptime }}</p>@endisset@isset($dockerVersion)diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.phpindex 537e23ba18..399e9c151a 100644--- a/resources/views/livewire/server/proxy.blade.php+++ b/resources/views/livewire/server/proxy.blade.php@@ -1,27 +1,25 @@<div>+@if ($server->settings->is_validated)- @if ($this->server->extra_attributes->proxy_status !== 'running')- <select wire:model="selectedProxy">- <option value="{{ \App\Enums\ProxyTypes::TRAEFIK_V2 }}">- {{ \App\Enums\ProxyTypes::TRAEFIK_V2 }}- </option>- </select>- <x-inputs.button isBold wire:click="setProxy">Set Proxy</x-inputs.button>- @endif- @if ($this->server->extra_attributes->proxy_type)+ <div class="flex items-center gap-2">+ <h3>Proxy</h3>+ <div>{{ $server->extra_attributes->proxy_status }}</div>+ </div>++ @if ($server->extra_attributes->proxy_type)<div wire:poll="proxyStatus">@if (- $this->server->extra_attributes->last_applied_proxy_settings &&- $this->server->extra_attributes->last_saved_proxy_settings !==- $this->server->extra_attributes->last_applied_proxy_settings)+ $server->extra_attributes->last_applied_proxy_settings &&+ $server->extra_attributes->last_saved_proxy_settings !== $server->extra_attributes->last_applied_proxy_settings)<div class="text-red-500">Configuration out of sync.</div>@endif- @if ($this->server->extra_attributes->proxy_status !== 'running')+ @if ($server->extra_attributes->proxy_status !== 'running')<x-inputs.button isBold wire:click="installProxy">- Install+ Start</x-inputs.button>+ @else+ <x-inputs.button isWarning wire:click="stopProxy">Stop</x-inputs.button>@endif- <x-inputs.button isBold wire:click="stopProxy">Stop</x-inputs.button><span x-data="{ showConfiguration: false }"><x-inputs.button isBold x-on:click.prevent="showConfiguration = !showConfiguration">ShowConfiguration@@ -35,16 +33,14 @@<div wire:loading wire:target="checkProxySettingsInSync"><x-proxy.loading /></div>- @isset($this->proxy_settings)+ @isset($proxy_settings)<form wire:submit.prevent='saveConfiguration'>- <x-inputs.button isBold>Save</x-inputs.button>- <x-inputs.button x-on:click="showConfiguration = false" isBold- wire:click.prevent="installProxy">- Apply- </x-inputs.button>- <x-inputs.button isBold wire:click.prevent="resetProxy">- Default- </x-inputs.button>+ <div class="pb-2">+ <x-inputs.button isBold>Save</x-inputs.button>+ <x-inputs.button wire:click.prevent="resetProxy">+ Reset Configuration+ </x-inputs.button>+ </div><textarea wire:model.defer="proxy_settings" class="w-full" rows="30"></textarea></form>@endisset@@ -52,6 +48,13 @@</template></span></div>+ @else+ <select wire:model="selectedProxy">+ <option value="{{ \App\Enums\ProxyTypes::TRAEFIK_V2 }}">+ {{ \App\Enums\ProxyTypes::TRAEFIK_V2 }}+ </option>+ </select>+ <x-inputs.button isBold wire:click="setProxy">Set Proxy</x-inputs.button>@endif@else<p>Server is not validated. Validate first.</p>diff --git a/resources/views/server/new.blade.php b/resources/views/server/new.blade.phpindex 5566b3afe9..f4aa9188e7 100644--- a/resources/views/server/new.blade.php+++ b/resources/views/server/new.blade.php@@ -2,7 +2,7 @@@if ($private_keys->count() === 0)<h2>Create private key</h2><div>You need to create a private key before you can create a server.</div>- <livewire:private-key.create />+ <livewire:private-key.create from="server" />@else<livewire:server.new.by-ip :private_keys="$private_keys" />@endifdiff --git a/resources/views/server/show.blade.php b/resources/views/server/show.blade.phpindex 6d8878ab12..c4708f9bc6 100644--- a/resources/views/server/show.blade.php+++ b/resources/views/server/show.blade.php@@ -1,12 +1,5 @@<x-layout><div class="text-3xl font-bold">Server</div>- <div class="flex flex-col pb-4">- @if ($server->settings->is_validated)- <div class="text-green-400">Validated</div>- @else- <div class="text-red-400">Not validated</div>- @endif- </div><div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'general' }"><div class="flex gap-4"><a :class="activeTab === 'general' && 'text-purple-500'"@@ -39,7 +32,7 @@<div class="flex items-center gap-2"><h3>Destinations</h3><a href="{{ route('destination.new', ['server_id' => $server->id]) }}">- <x-inputs.button isBold>New</x-inputs.button>+ <x-inputs.button>Add a new</x-inputs.button></a></div>@if ($server->standaloneDockers->count() > 0)@@ -51,17 +44,7 @@@endif</div><div x-cloak x-show="activeTab === 'proxy'">- <div class="flex items-center gap-2">- <h3>Proxy</h3>- @if ($server->settings->is_validated)- <div>{{ $server->extra_attributes->proxy_status }}</div>- @endif- </div><livewire:server.proxy :server="$server" /></div>-</div>---</x-layout>