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 Bacsai3bdea4c931a3
diff --git a/app/Actions/Proxy/CheckProxySettingsInSync.php b/app/Actions/Proxy/CheckProxySettingsInSync.phpindex 874dd830ea..ae0142fec6 100644--- a/app/Actions/Proxy/CheckProxySettingsInSync.php+++ b/app/Actions/Proxy/CheckProxySettingsInSync.php@@ -20,7 +20,7 @@ class CheckProxySettingsInSync$final_output = Str::of($output)->trim()->value;}$docker_compose_yml_base64 = base64_encode($final_output);- $server->extra_attributes->proxy_last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;+ $server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;$server->save();if (is_null($output) || $reset) {instant_remote_process([diff --git a/app/Actions/Proxy/InstallProxy.php b/app/Actions/Proxy/InstallProxy.phpindex 21c19d3a69..c967a4687b 100644--- a/app/Actions/Proxy/InstallProxy.php+++ b/app/Actions/Proxy/InstallProxy.php@@ -12,9 +12,9 @@ class InstallProxy{public function __invoke(Server $server): Activity{- if (is_null(data_get($server, 'extra_attributes.proxy_type'))) {- $server->extra_attributes->proxy_type = ProxyTypes::TRAEFIK_V2->value;- $server->extra_attributes->proxy_status = ProxyStatus::EXITED->value;+ if (is_null(data_get($server, 'proxy.type'))) {+ $server->proxy->type = ProxyTypes::TRAEFIK_V2->value;+ $server->proxy->status = ProxyStatus::EXITED->value;$server->save();}$proxy_path = config('coolify.proxy_config_path');@@ -38,7 +38,7 @@ class InstallProxy$configuration = Str::of($configuration)->trim()->value;}$docker_compose_yml_base64 = base64_encode($configuration);- $server->extra_attributes->proxy_last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;+ $server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;$server->save();$activity = remote_process(["echo 'Creating required Docker networks...'",diff --git a/app/Data/ServerMetadata.php b/app/Data/ServerMetadata.phpindex 06f11f2060..b96efa6224 100644--- a/app/Data/ServerMetadata.php+++ b/app/Data/ServerMetadata.php@@ -9,8 +9,8 @@ use Spatie\LaravelData\Data;class ServerMetadata extends Data{public function __construct(- public ?ProxyTypes $proxy_type,- public ?ProxyStatus $proxy_status+ public ?ProxyTypes $type,+ public ?ProxyStatus $status) {}}diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.phpindex 4a5eb466d3..2403fab33c 100644--- a/app/Http/Livewire/Server/Proxy.php+++ b/app/Http/Livewire/Server/Proxy.php@@ -23,14 +23,14 @@ class Proxy extends Component}public function switchProxy(){- $this->server->extra_attributes->proxy_type = null;+ $this->server->proxy->type = null;$this->server->save();}public function installProxy(){if (- $this->server->extra_attributes->proxy_last_applied_settings &&- $this->server->extra_attributes->proxy_last_saved_settings !== $this->server->extra_attributes->proxy_last_applied_settings+ $this->server->proxy->last_applied_settings &&+ $this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings) {$this->saveConfiguration($this->server);}@@ -40,8 +40,8 @@ class Proxy extends Componentpublic function setProxy(string $proxy_type){- $this->server->extra_attributes->proxy_type = $proxy_type;- $this->server->extra_attributes->proxy_status = 'exited';+ $this->server->proxy->type = $proxy_type;+ $this->server->proxy->status = 'exited';$this->server->save();}public function stopProxy()@@ -49,7 +49,7 @@ class Proxy extends Componentinstant_remote_process(["docker rm -f coolify-proxy",], $this->server);- $this->server->extra_attributes->proxy_status = 'exited';+ $this->server->proxy->status = 'exited';$this->server->save();}public function saveConfiguration(Server $server)@@ -58,7 +58,7 @@ class Proxy extends Component$proxy_path = config('coolify.proxy_config_path');$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;$docker_compose_yml_base64 = base64_encode($this->proxy_settings);- $server->extra_attributes->proxy_last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;+ $server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;$server->save();instant_remote_process(["echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",diff --git a/app/Http/Livewire/Server/Proxy/Deploy.php b/app/Http/Livewire/Server/Proxy/Deploy.phpindex 58f5e58518..aa12886f26 100644--- a/app/Http/Livewire/Server/Proxy/Deploy.php+++ b/app/Http/Livewire/Server/Proxy/Deploy.php@@ -19,8 +19,8 @@ class Deploy extends Componentpublic function deploy(){if (- $this->server->extra_attributes->proxy_last_applied_settings &&- $this->server->extra_attributes->proxy_last_saved_settings !== $this->server->extra_attributes->proxy_last_applied_settings+ $this->server->proxy->last_applied_settings &&+ $this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings) {$this->saveConfiguration($this->server);}@@ -32,7 +32,7 @@ class Deploy extends Componentinstant_remote_process(["docker rm -f coolify-proxy",], $this->server);- $this->server->extra_attributes->proxy_status = 'exited';+ $this->server->proxy->status = 'exited';$this->server->save();$this->emit('proxyStatusUpdated');}diff --git a/app/Jobs/InstanceProxyCheckJob.php b/app/Jobs/InstanceProxyCheckJob.phpindex d2cf894f78..4387cd3188 100755--- a/app/Jobs/InstanceProxyCheckJob.php+++ b/app/Jobs/InstanceProxyCheckJob.php@@ -29,7 +29,7 @@ class InstanceProxyCheckJob implements ShouldQueue{try {$container_name = 'coolify-proxy';- $servers = Server::whereRelation('settings', 'is_reachable', true)->where('extra_attributes->proxy_type', ProxyTypes::TRAEFIK_V2)->get();+ $servers = Server::whereRelation('settings', 'is_reachable', true)->where('proxy->type', ProxyTypes::TRAEFIK_V2)->get();foreach ($servers as $server) {$status = get_container_status(server: $server, container_id: $container_name);diff --git a/app/Jobs/ProxyContainerStatusJob.php b/app/Jobs/ProxyContainerStatusJob.phpindex 9c3dcbfdca..7c4b15ca54 100644--- a/app/Jobs/ProxyContainerStatusJob.php+++ b/app/Jobs/ProxyContainerStatusJob.php@@ -3,8 +3,6 @@namespace App\Jobs;use App\Enums\ProxyTypes;-use App\Models\Application;-use App\Models\ApplicationPreview;use App\Models\Server;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldBeUnique;@@ -12,8 +10,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;-use Str;use Illuminate\Queue\Middleware\WithoutOverlapping;+use Illuminate\Support\Str;class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique{@@ -39,13 +37,13 @@ class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUniquetry {$container = get_container_status(server: $this->server, all_data: true, container_id: 'coolify-proxy', throwError: true);$status = $container['State']['Status'];- if ($this->server->extra_attributes->proxy_status !== $status) {- $this->server->extra_attributes->proxy_status = $status;- if ($this->server->extra_attributes->proxy_status === 'running') {+ if ($this->server->proxy->status !== $status) {+ $this->server->proxy->status = $status;+ if ($this->server->proxy->status === 'running') {$traefik = $container['Config']['Labels']['org.opencontainers.image.title'];$version = $container['Config']['Labels']['org.opencontainers.image.version'];if (isset($version) && isset($traefik) && $traefik === 'Traefik' && Str::of($version)->startsWith('v2')) {- $this->server->extra_attributes->proxy_type = ProxyTypes::TRAEFIK_V2->value;+ $this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value;}}$this->server->save();diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 1a1a9704f4..5382f6dfd2 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -4,9 +4,17 @@ namespace App\Models;use Illuminate\Database\Eloquent\Builder;use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;+use Spatie\SchemalessAttributes\SchemalessAttributesTrait;class Server extends BaseModel{+ use SchemalessAttributesTrait;+ protected $schemalessAttributes = [+ 'proxy',+ ];+ public $casts = [+ 'proxy' => SchemalessAttributes::class,+ ];protected static function booted(){static::created(function ($server) {@@ -25,16 +33,14 @@ class Server extends BaseModel'port','team_id','private_key_id',- 'extra_attributes',+ 'proxy',];- public $casts = [- 'extra_attributes' => SchemalessAttributes::class,- ];- public function scopeWithExtraAttributes(): Builder++ public function scopeWithProxy(): Builder{- return $this->extra_attributes->modelScope();+ return $this->proxy->modelScope();}public function isEmpty(){diff --git a/database/migrations/2023_03_24_140711_create_servers_table.php b/database/migrations/2023_03_24_140711_create_servers_table.phpindex 84e2ab6ba8..0f3bf7419c 100644--- a/database/migrations/2023_03_24_140711_create_servers_table.php+++ b/database/migrations/2023_03_24_140711_create_servers_table.php@@ -21,7 +21,7 @@ return new class extends Migration$table->string('user')->default('root');$table->foreignId('team_id');$table->foreignId('private_key_id');- $table->schemalessAttributes('extra_attributes');+ $table->schemalessAttributes('proxy');$table->timestamps();});}diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.phpindex 096e3d12de..de46bf9598 100644--- a/database/seeders/ProductionSeeder.php+++ b/database/seeders/ProductionSeeder.php@@ -77,9 +77,9 @@ class ProductionSeeder extends Seeder'team_id' => 0,'private_key_id' => 0];- $server_details['extra_attributes'] = ServerMetadata::from([- 'proxy_type' => ProxyTypes::TRAEFIK_V2->value,- 'proxy_status' => ProxyStatus::EXITED->value+ $server_details['proxy'] = ServerMetadata::from([+ 'type' => ProxyTypes::TRAEFIK_V2->value,+ 'status' => ProxyStatus::EXITED->value]);$server = Server::create($server_details);$server->settings->is_reachable = true;diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.phpindex 2f265d5dac..886b1e5b75 100644--- a/database/seeders/ServerSeeder.php+++ b/database/seeders/ServerSeeder.php@@ -28,9 +28,9 @@ class ServerSeeder extends Seeder'ip' => "coolify-testing-host",'team_id' => $root_team->id,'private_key_id' => $private_key_1->id,- 'extra_attributes' => ServerMetadata::from([- 'proxy_type' => ProxyTypes::TRAEFIK_V2->value,- 'proxy_status' => ProxyStatus::EXITED->value+ 'proxy' => ServerMetadata::from([+ 'type' => ProxyTypes::TRAEFIK_V2->value,+ 'status' => ProxyStatus::EXITED->value]),]);Server::create([diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.phpindex 2a8cce4fda..1bbf2fbef2 100644--- a/resources/views/livewire/server/proxy.blade.php+++ b/resources/views/livewire/server/proxy.blade.php@@ -2,7 +2,7 @@<x-naked-modal show="stopProxy" action="stopProxy" title="Stop Proxy"message='This proxy will be stopped. It is not reversible. <br>All resources will be unavailable. <br>Please think again.' />@if ($server->settings->is_reachable)- @if ($server->extra_attributes->proxy_type)+ @if ($server->proxy->type)<div x-init="$wire.checkProxySettingsInSync"><div wire:loading wire:target="checkProxySettingsInSync"><x-loading />@@ -13,15 +13,15 @@<div class="flex items-center gap-2"><h2>Proxy</h2><x-forms.button type="submit">Save</x-forms.button>- @if ($server->extra_attributes->proxy_status === 'exited')+ @if ($server->proxy->status === 'exited')<x-forms.button wire:click.prevent="switchProxy">Switch Proxy</x-forms.button>@endif<livewire:server.proxy.status :server="$server" /></div><div class="pt-3 pb-4 ">Traefik v2</div>@if (- $server->extra_attributes->proxy_last_applied_settings &&- $server->extra_attributes->proxy_last_saved_settings !== $server->extra_attributes->proxy_last_applied_settings)+ $server->proxy->last_applied_settings &&+ $server->proxy->last_saved_settings !== $server->proxy->last_applied_settings)<div class="text-red-500 ">Configuration out of sync. Restart to get the new configs.</div>@endifdiff --git a/resources/views/livewire/server/proxy/deploy.blade.php b/resources/views/livewire/server/proxy/deploy.blade.phpindex c68bc87626..208f0e93b2 100644--- a/resources/views/livewire/server/proxy/deploy.blade.php+++ b/resources/views/livewire/server/proxy/deploy.blade.php@@ -1,6 +1,6 @@<div>@if ($server->settings->is_reachable)- @if ($server->extra_attributes->proxy_status === 'running')+ @if ($server->proxy->status === 'running')<div class="flex gap-4"><div class="group"><label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Linksdiff --git a/resources/views/livewire/server/proxy/status.blade.php b/resources/views/livewire/server/proxy/status.blade.phpindex 0d68cfbbf8..310d93079d 100644--- a/resources/views/livewire/server/proxy/status.blade.php+++ b/resources/views/livewire/server/proxy/status.blade.php@@ -1,9 +1,9 @@<div>@if ($server->settings->is_reachable)<div wire:poll.10000ms="proxyStatus" x-init="$wire.proxyStatus">- @if ($server->extra_attributes->proxy_status === 'running')+ @if ($server->proxy->status === 'running')<x-status.running />- @elseif ($server->extra_attributes->proxy_status === 'restarting')+ @elseif ($server->proxy->status === 'restarting')<x-status.restarting />@else<x-status.stopped />diff --git a/routes/web.php b/routes/web.phpindex ee65262741..e3a8f0b007 100644--- a/routes/web.php+++ b/routes/web.php@@ -71,7 +71,7 @@ Route::middleware(['auth'])->group(function () {'server' => Server::ownedByCurrentTeam(['name', 'description', 'ip', 'port', 'user'])->whereUuid(request()->server_uuid)->firstOrFail(),]))->name('server.show');Route::get('/server/{server_uuid}/proxy', fn () => view('server.proxy', [- 'server' => Server::ownedByCurrentTeam(['name', 'extra_attributes'])->whereUuid(request()->server_uuid)->firstOrFail(),+ 'server' => Server::ownedByCurrentTeam(['name', 'proxy'])->whereUuid(request()->server_uuid)->firstOrFail(),]))->name('server.proxy');Route::get('/server/{server_uuid}/private-key', fn () => view('server.private-key', ['server' => Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(),