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: broadcast
Andras Bacsai42ee4ca032e4
diff --git a/.env.production b/.env.productionindex 32652711e3..5d9eeaaaf1 100644--- a/.env.production+++ b/.env.production@@ -4,3 +4,11 @@ APP_KEY=DB_PASSWORD=REDIS_PASSWORD=++PUSHER_APP_ID=+PUSHER_APP_KEY=+PUSHER_APP_SECRET=++VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"+VITE_PUSHER_HOST="${PUSHER_HOST}"+VITE_PUSHER_PORT="${PUSHER_PORT}"diff --git a/app/Providers/ApplicationDeploymentFinished.php b/app/Events/ApplicationDeploymentFinished.phpsimilarity index 54%rename from app/Providers/ApplicationDeploymentFinished.phprename to app/Events/ApplicationDeploymentFinished.phpindex 627ae03a1e..fb43f72c52 100644--- a/app/Providers/ApplicationDeploymentFinished.php+++ b/app/Events/ApplicationDeploymentFinished.php@@ -1,6 +1,6 @@<?php-namespace App\Providers;+namespace App\Events;use Illuminate\Broadcasting\Channel;use Illuminate\Broadcasting\InteractsWithSockets;@@ -14,14 +14,25 @@ class ApplicationDeploymentFinished implements ShouldBroadcast{use Dispatchable, InteractsWithSockets, SerializesModels;- public function __construct()+ public ?int $teamId = null;++ /**+ * Create a new event instance.+ */+ public function __construct(public ?string $applicationUuid = null, public ?string $status = null){+ $this->teamId = auth()->user()->currentTeam()->id;}+ /**+ * Get the channels the event should broadcast on.+ *+ * @return array<int, \Illuminate\Broadcasting\Channel>+ */public function broadcastOn(): array{return [- new Channel('custom-channel'),+ new PrivateChannel("custom.{$this->teamId}"),];}}diff --git a/app/Http/Livewire/Dashboard.php b/app/Http/Livewire/Dashboard.phpindex b7219864df..05bef207db 100644--- a/app/Http/Livewire/Dashboard.php+++ b/app/Http/Livewire/Dashboard.php@@ -10,7 +10,6 @@ class Dashboard extends Component{public $projects = [];public $servers = [];-public function mount(){$this->servers = Server::ownedByCurrentTeam()->get();diff --git a/app/Http/Livewire/Project/Application/Configuration.php b/app/Http/Livewire/Project/Application/Configuration.phpindex 7cb2939f2c..51d964d379 100644--- a/app/Http/Livewire/Project/Application/Configuration.php+++ b/app/Http/Livewire/Project/Application/Configuration.php@@ -26,7 +26,7 @@ class Configuration extends Componentreturn redirect()->route('dashboard');}$this->application = $application;- $mainServer = $application->destination->server;+ $mainServer = $this->application->destination->server;$servers = Server::ownedByCurrentTeam()->get();$this->servers = $servers->filter(function ($server) use ($mainServer) {return $server->id != $mainServer->id;diff --git a/app/Http/Livewire/Project/Application/DeploymentNavbar.php b/app/Http/Livewire/Project/Application/DeploymentNavbar.phpindex 830a24fab9..2cee34d115 100644--- a/app/Http/Livewire/Project/Application/DeploymentNavbar.php+++ b/app/Http/Livewire/Project/Application/DeploymentNavbar.php@@ -17,11 +17,7 @@ class DeploymentNavbar extends Componentpublic Application $application;public Server $server;public bool $is_debug_enabled = false;- protected $listeners = ['deploymentFinished','echo:custom-channel,ApplicationDeploymentFinished' => 'notifyNewOrder'];-- public function notifyNewOrder() {- ray('New order received');- }+ protected $listeners = ['deploymentFinished'];public function mount(){$this->application = Application::find($this->application_deployment_queue->application_id);diff --git a/app/Http/Livewire/Project/Application/Heading.php b/app/Http/Livewire/Project/Application/Heading.phpindex 3d5af34da8..9a212867a9 100644--- a/app/Http/Livewire/Project/Application/Heading.php+++ b/app/Http/Livewire/Project/Application/Heading.php@@ -11,11 +11,24 @@ use Visus\Cuid2\Cuid2;class Heading extends Component{+ protected string $deploymentUuid;public Application $application;public array $parameters;+ public function getListeners()+ {+ $teamId = auth()->user()->currentTeam()->id;+ return [+ "echo-private:custom.{$teamId},ApplicationDeploymentFinished" => 'updateStatus',+ ];+ }- protected string $deploymentUuid;-+ public function updateStatus($message)+ {+ $applicationUuid = data_get($message, 'applicationUuid');+ if ($this->application->uuid === $applicationUuid) {+ $this->application->status = data_get($message, 'status');+ }+ }public function mount(){$this->parameters = get_route_parameters();diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.phpindex efca800c28..512a7f68aa 100644--- a/app/Http/Livewire/Server/Form.php+++ b/app/Http/Livewire/Server/Form.php@@ -44,6 +44,7 @@ class Form extends Component{$this->wildcard_domain = $this->server->settings->wildcard_domain;$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;+ $this->validateServer();}public function serverRefresh($install = true){diff --git a/app/Jobs/ApplicationDeploymentNewJob.php b/app/Jobs/ApplicationDeploymentNewJob.phpindex b082e82faa..40301bbe95 100644--- a/app/Jobs/ApplicationDeploymentNewJob.php+++ b/app/Jobs/ApplicationDeploymentNewJob.php@@ -4,6 +4,7 @@ namespace App\Jobs;use App\Enums\ApplicationDeploymentStatus;use App\Enums\ProxyTypes;+use App\Events\ApplicationDeploymentFinished;use App\Models\Application;use App\Models\ApplicationDeploymentQueue;use App\Models\ApplicationPreview;@@ -14,7 +15,6 @@ use App\Models\StandaloneDocker;use App\Models\SwarmDocker;use App\Notifications\Application\DeploymentFailed;use App\Notifications\Application\DeploymentSuccess;-use App\Providers\ApplicationDeploymentFinished;use App\Traits\ExecuteRemoteCommand;use Exception;use Illuminate\Bus\Queueable;@@ -102,7 +102,7 @@ class ApplicationDeploymentNewJob implements ShouldQueue, ShouldBeEncrypted});}$this->next(ApplicationDeploymentStatus::FINISHED->value);- ApplicationDeploymentFinished::dispatch($this->application, $this->deployment);+ ApplicationDeploymentFinished::dispatch($this->application->uuid, ApplicationDeploymentStatus::FINISHED->value);} catch (Throwable $exception) {$this->fail($exception);} finally {diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 1806f5cebd..37a5ffe2ae 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -382,17 +382,17 @@ class Server extends BaseModelpublic function validateConnection(){$server = Server::find($this->id);- if ($this->skipServer()) {+ if ($server->skipServer()) {return false;}- $uptime = instant_remote_process(['uptime'], $this, false);+ $uptime = instant_remote_process(['uptime'], $server, false);if (!$uptime) {- $this->settings()->update([+ $server->settings()->update(['is_reachable' => false,]);return false;} else {- $this->settings()->update([+ $server->settings()->update(['is_reachable' => true,]);$server->update([@@ -400,8 +400,8 @@ class Server extends BaseModel]);}- if (data_get($this, 'unreachable_notification_sent') === true) {- $this->team->notify(new Revived($this));+ if (data_get($server, 'unreachable_notification_sent') === true) {+ $server->team->notify(new Revived($server));$server->update(['unreachable_notification_sent' => false]);}diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex b4b9d1c0c1..b964f2c44e 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -8,31 +8,15 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProviclass EventServiceProvider extends ServiceProvider{- /**- * The event to listener mappings for the application.- *- * @var array<class-string, array<int, class-string>>- */protected $listen = [// Registered::class => [// SendEmailVerificationNotification::class,// ],- ApplicationDeploymentFinished::class => [- SendDeploymentNotification::class,- ],];-- /**- * Register any events for your application.- */public function boot(): void{//}-- /**- * Determine if events and listeners should be automatically discovered.- */public function shouldDiscoverEvents(): bool{return false;diff --git a/app/Providers/SendDeploymentNotification.php b/app/Providers/SendDeploymentNotification.phpdeleted file mode 100644index b4f3d6b465..0000000000--- a/app/Providers/SendDeploymentNotification.php+++ /dev/null@@ -1,28 +0,0 @@-<?php--namespace App\Providers;--use App\Providers\ApplicationDeploymentFinished;-use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;-use Illuminate\Contracts\Queue\ShouldQueue;-use Illuminate\Queue\InteractsWithQueue;--class SendDeploymentNotification implements ShouldQueue, ShouldHandleEventsAfterCommit-{- use InteractsWithQueue;- /**- * Create the event listener.- */- public function __construct()- {- //- }-- /**- * Handle the event.- */- public function handle(ApplicationDeploymentFinished $event): void- {- ray('SendDeploymentNotification');- }-}diff --git a/composer.json b/composer.jsonindex 9937ee5b98..81a1394a0f 100644--- a/composer.json+++ b/composer.json@@ -28,6 +28,7 @@"nubs/random-name-generator": "^2.2","phpseclib/phpseclib": "~3.0","poliander/cron": "^3.0",+ "pusher/pusher-php-server": "^7.2","resend/resend-laravel": "^0.5.0","sentry/sentry-laravel": "^3.4","spatie/laravel-activitylog": "^4.7.3",diff --git a/config/app.php b/config/app.phpindex 246ad1f995..5851640be9 100644--- a/config/app.php+++ b/config/app.php@@ -194,7 +194,7 @@ return [App\Providers\AppServiceProvider::class,App\Providers\FortifyServiceProvider::class,App\Providers\AuthServiceProvider::class,- // App\Providers\BroadcastServiceProvider::class,+ App\Providers\BroadcastServiceProvider::class,App\Providers\EventServiceProvider::class,App\Providers\HorizonServiceProvider::class,App\Providers\RouteServiceProvider::class,diff --git a/config/broadcasting.php b/config/broadcasting.phpindex 2a8b9a3873..88f9af8633 100644--- a/config/broadcasting.php+++ b/config/broadcasting.php@@ -15,7 +15,7 @@ return [|*/- 'default' => env('BROADCAST_DRIVER', 'log'),+ 'default' => env('BROADCAST_DRIVER', 'pusher'),/*|--------------------------------------------------------------------------@@ -32,9 +32,9 @@ return ['pusher' => ['driver' => 'pusher',- 'key' => env('PUSHER_APP_KEY'),- 'secret' => env('PUSHER_APP_SECRET'),- 'app_id' => env('PUSHER_APP_ID'),+ 'key' => env('PUSHER_APP_KEY', 'coolify'),+ 'secret' => env('PUSHER_APP_SECRET', 'coolify'),+ 'app_id' => env('PUSHER_APP_ID', 'coolify'),'options' => ['host' => 'coolify-soketi','port' => env('PUSHER_PORT', 6001),diff --git a/database/seeders/StandaloneDockerSeeder.php b/database/seeders/StandaloneDockerSeeder.phpindex 1e9a749dd9..9f67de710a 100644--- a/database/seeders/StandaloneDockerSeeder.php+++ b/database/seeders/StandaloneDockerSeeder.php@@ -13,11 +13,11 @@ class StandaloneDockerSeeder extends Seeder*/public function run(): void{- // StandaloneDocker::create([- // 'id' => 0,- // 'name' => 'Standalone Docker 1',- // 'network' => 'coolify',- // 'server_id' => 0,- // ]);+ StandaloneDocker::create([+ 'id' => 0,+ 'name' => 'Standalone Docker 1',+ 'network' => 'coolify',+ 'server_id' => 0,+ ]);}}diff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex 25f3d5a7b2..d52c83b7d5 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -21,6 +21,10 @@ services:SSL_MODE: "off"AUTORUN_LARAVEL_STORAGE_LINK: "false"AUTORUN_LARAVEL_MIGRATION: "false"+ PUSHER_HOST: "${PUSHER_HOST:-127.0.0.1}"+ PUSHER_APP_ID: "${PUSHER_APP_ID:-coolify}"+ PUSHER_APP_KEY: "${PUSHER_APP_KEY:-coolify}"+ PUSHER_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}"volumes:- .:/var/www/html/:cachedpostgres:@@ -45,15 +49,22 @@ services:- /data/coolify/_volumes/redis/:/data# - coolify-redis-data-dev:/datasoketi:+ env_file:+ - .envports:- "${FORWARD_SOKETI_PORT:-6001}:6001"- - "${FORWARD_SOKETI_METRICS_SERVER_PORT:-9601}:9601"environment:SOKETI_DEBUG: "true"- SOKETI_METRICS_SERVER_PORT: "${SOKETI_METRICS_SERVER_PORT:-9601}"+ SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID:-coolify}"+ SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY:-coolify}"+ SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}"vite:image: node:20working_dir: /var/www/html+ environment:+ VITE_PUSHER_HOST: "${PUSHER_HOST:-127.0.0.1}"+ VITE_PUSHER_APP_KEY: "${PUSHER_APP_KEY:-coolify}"+ VITE_PUSHER_PORT: "${FORWARD_SOKETI_PORT:-6001}"ports:- "${VITE_PORT:-5173}:${VITE_PORT:-5173}"volumes:@@ -67,14 +78,14 @@ services:- /var/run/docker.sock:/var/run/docker.sock- /data/coolify/:/data/coolify# - coolify-data-dev:/data/coolify- remote-host:- <<: *testing-host-base- container_name: coolify-remote-host- volumes:- - /:/host- - /var/run/docker.sock:/var/run/docker.sock- - /data/coolify/:/data/coolify- # - coolify-data-dev:/data/coolify+ # remote-host:+ # <<: *testing-host-base+ # container_name: coolify-remote-host+ # volumes:+ # - /:/host+ # - /var/run/docker.sock:/var/run/docker.sock+ # - /data/coolify/:/data/coolify+ # # - coolify-data-dev:/data/coolifymailpit:image: "axllent/mailpit:latest"container_name: coolify-maildiff --git a/docker-compose.prod.yml b/docker-compose.prod.ymlindex ca6b42348c..4ba513d5a5 100644--- a/docker-compose.prod.yml+++ b/docker-compose.prod.yml@@ -1,7 +1,7 @@version: '3.8'services:coolify:- image: "ghcr.io/coollabsio/coolify:${LATEST_IMAGE:-4.0.0-beta.20}"+ image: "ghcr.io/coollabsio/coolify:${LATEST_IMAGE:-4.0.0-beta.153}"volumes:- type: bindsource: /data/coolify/source/.env@@ -35,6 +35,13 @@ services:- PHP_PM_START_SERVERS=1- PHP_PM_MIN_SPARE_SERVERS=1- PHP_PM_MAX_SPARE_SERVERS=10+ - PUSHER_HOST+ - PUSHER_APP_ID+ - PUSHER_APP_KEY+ - PUSHER_APP_SECRET+ - VITE_PUSHER_HOST+ - VITE_PUSHER_APP_KEY+ - VITE_PUSHER_PORT- SELF_HOSTED- WAITLIST- SUBSCRIPTION_PROVIDER@@ -111,6 +118,12 @@ services:interval: 2sretries: 5timeout: 2s+ soketi:+ environment:+ SOKETI_DEBUG: "${SOKETI_DEBUG:-false}"+ SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID}"+ SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"+ SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"volumes:coolify-db:name: coolify-dbdiff --git a/resources/js/app.js b/resources/js/app.jsindex d7fb2541d9..053b277c11 100644--- a/resources/js/app.js+++ b/resources/js/app.js@@ -9,14 +9,15 @@ window.Pusher = Pusher;window.Echo = new Echo({broadcaster: 'pusher',- cluster: import.meta.env.VITE_PUSHER_HOST,- key: import.meta.env.VITE_PUSHER_APP_KEY,- wsHost: import.meta.env.VITE_PUSHER_HOST,+ cluster: import.meta.env.VITE_PUSHER_HOST ?? '127.0.0.1',+ key: import.meta.env.VITE_PUSHER_APP_KEY ?? 'coolify',+ wsHost: import.meta.env.VITE_PUSHER_HOST ?? '127.0.0.1',wsPort: import.meta.env.VITE_PUSHER_PORT,wssPort: import.meta.env.VITE_PUSHER_PORT,forceTLS: false,- encrypted: false,- disableStats: true,+ encrypted: true,+ disableStats: false,+ enableLogging: true,enabledTransports: ['ws', 'wss'],});@@ -30,6 +31,4 @@ app.component("magic-bar", MagicBar);app.mount("#vue");-window.Echo.channel("custom-channel").listen("ApplicationDeploymentFinished", (e) => {- console.log(e);-});+diff --git a/resources/views/livewire/project/application/heading.blade.php b/resources/views/livewire/project/application/heading.blade.phpindex ca76d38e81..3a197e8105 100644--- a/resources/views/livewire/project/application/heading.blade.php+++ b/resources/views/livewire/project/application/heading.blade.php@@ -1,4 +1,4 @@-<nav x-init="$wire.check_status" wire:poll.10000ms="check_status">+<nav x-init="$wire.check_status"><x-resources.breadcrumbs :resource="$application" :parameters="$parameters" /><x-applications.navbar :application="$application" :parameters="$parameters" /></nav>diff --git a/routes/channels.php b/routes/channels.phpindex 745a40640d..f289e4e78e 100644--- a/routes/channels.php+++ b/routes/channels.php@@ -11,6 +11,13 @@|*/-// Broadcast::channel('App.Models.User.{id}', function ($user, $id) {-// return (int) $user->id === (int) $id;-// });+use App\Models\Application;+use App\Models\User;+use Illuminate\Support\Facades\Broadcast;++Broadcast::channel('custom.{teamId}', function (User $user, int $teamId) {+ if ($user->teams->pluck('id')->contains($teamId)) {+ return true;+ }+ return false;+});diff --git a/routes/web.php b/routes/web.phpindex 1e276e738c..8db90b16c4 100644--- a/routes/web.php+++ b/routes/web.php@@ -1,5 +1,6 @@<?php+use App\Events\ApplicationDeploymentFinished;use App\Http\Controllers\ApplicationController;use App\Http\Controllers\Controller;use App\Http\Controllers\DatabaseController;@@ -39,6 +40,11 @@ use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;use Laravel\Fortify\Fortify;+Route::get('/fire', function () {+ ApplicationDeploymentFinished::dispatch('kk0gg0s', 'stopped');++ return 'Event has been sent!';+});if (isDev()) {Route::get('/dev/compose', Compose::class)->name('dev.compose');}diff --git a/scripts/upgrade.sh b/scripts/upgrade.shindex af64638694..3659b2abfb 100644--- a/scripts/upgrade.sh+++ b/scripts/upgrade.sh@@ -1,11 +1,7 @@#!/bin/bash## Do not modify this file. You will lost the ability to autoupdate!-###########-## Always run "php artisan app:sync-to-bunny-cdn --env=secrets" if you update this file.-###########--VERSION="1.0.1"+VERSION="1.1.0"CDN="https://cdn.coollabs.io/coolify"curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml@@ -15,6 +11,28 @@ curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production# Merge .env and .env.production. New values will be added to .envsort -u -t '=' -k 1,1 /data/coolify/source/.env /data/coolify/source/.env.production | sed '/^$/d' > /data/coolify/source/.env.temp && mv /data/coolify/source/.env.temp /data/coolify/source/.env+# Check if PUSHER_APP_ID or PUSHER_APP_KEY or PUSHER_APP_SECRET is empty in /data/coolify/source/.env+if grep -q "PUSHER_APP_ID=" /data/coolify/source/.env; then+ echo "PUSHER_APP_ID is set in .env"+else+ echo "PUSHER_APP_ID is not set in .env"+ sed -i "s|PUSHER_APP_ID=.*|PUSHER_APP_ID=$(openssl rand -base64 32)|g" /data/coolify/source/.env+fi++if grep -q "PUSHER_APP_KEY=" /data/coolify/source/.env; then+ echo "PUSHER_APP_KEY is set in .env"+else+ echo "PUSHER_APP_KEY is not set in .env"+ sed -i "s|PUSHER_APP_KEY=.*|PUSHER_APP_KEY=$(openssl rand -base64 32)|g" /data/coolify/source/.env+fi++if grep -q "PUSHER_APP_SECRET=" /data/coolify/source/.env; then+ echo "PUSHER_APP_SECRET is set in .env"+else+ echo "PUSHER_APP_SECRET is not set in .env"+ sed -i "s|PUSHER_APP_SECRET=.*|PUSHER_APP_SECRET=$(openssl rand -base64 32)|g" /data/coolify/source/.env+fi+# Make sure coolify network existsdocker network create --attachable coolify 2>/dev/null# docker network create --attachable --driver=overlay coolify-overlay 2>/dev/null