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
subscribe to events
Andras Bacsaif7dd110a490e
diff --git a/app/Data/SmtpConfiguration.php b/app/Data/SmtpConfiguration.phpnew file mode 100644index 0000000000..1aac317de3--- /dev/null+++ b/app/Data/SmtpConfiguration.php@@ -0,0 +1,23 @@+<?php++namespace App\Data;++use Spatie\LaravelData\Data;++class SmtpConfiguration extends Data+{+ public function __construct(+ public bool $smtp_active = false,+ public string $smtp_host,+ public int $smtp_port,+ public ?string $smtp_encryption,+ public ?string $smtp_username,+ public ?string $smtp_password,+ public ?int $smtp_timeout,+ public string $smtp_from_address,+ public string $smtp_from_name,+ public ?string $smtp_recipients,+ public ?string $smtp_test_recipients,+ ) {+ }+}diff --git a/app/Http/Livewire/Notifications/DiscordSettings.php b/app/Http/Livewire/Notifications/DiscordSettings.phpindex e8ef7b94df..4e47c3ec76 100644--- a/app/Http/Livewire/Notifications/DiscordSettings.php+++ b/app/Http/Livewire/Notifications/DiscordSettings.php@@ -15,11 +15,16 @@ class DiscordSettings extends Componentprotected $rules = ['model.extra_attributes.discord_active' => 'nullable|boolean','model.extra_attributes.discord_webhook' => 'required|url',+ 'model.extra_attributes.notifications_test' => 'nullable|boolean',+ 'model.extra_attributes.notifications_deployments' => 'nullable|boolean',];protected $validationAttributes = ['model.extra_attributes.discord_webhook' => 'Discord Webhook',];-+ public function instantSaveEvents()+ {+ $this->saveModel();+ }public function instantSave(){try {@@ -35,6 +40,7 @@ class DiscordSettings extends Componentif (is_a($this->model, Team::class)) {session(['currentTeam' => $this->model]);}+ $this->emit('success', 'Settings saved.');}public function submit(){diff --git a/app/Http/Livewire/Notifications/EmailSettings.php b/app/Http/Livewire/Notifications/EmailSettings.phpindex 28ecd7aa26..186ca7898f 100644--- a/app/Http/Livewire/Notifications/EmailSettings.php+++ b/app/Http/Livewire/Notifications/EmailSettings.php@@ -24,6 +24,8 @@ class EmailSettings extends Component'model.extra_attributes.smtp_password' => 'nullable','model.extra_attributes.smtp_timeout' => 'nullable','model.extra_attributes.smtp_test_recipients' => 'nullable',+ 'model.extra_attributes.notifications_deployments' => 'nullable|boolean',+ 'model.extra_attributes.notifications_test' => 'nullable|boolean',];protected $validationAttributes = ['model.extra_attributes.smtp_from_address' => 'From Address',@@ -66,11 +68,16 @@ class EmailSettings extends Componentif (is_a($this->model, Team::class)) {session(['currentTeam' => $this->model]);}+ $this->emit('success', 'Settings saved.');}public function sendTestNotification(){Notification::send($this->model, new TestNotification);}+ public function instantSaveEvents()+ {+ $this->saveModel();+ }public function instantSave(){try {diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 51bc5d7411..450e5a8cc7 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -9,12 +9,14 @@ use App\Enums\ProcessStatus;use App\Models\Application;use App\Models\ApplicationDeploymentQueue;use App\Models\ApplicationPreview;+use App\Notifications\Notifications\ApplicationDeployedNotification;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Illuminate\Support\Collection;+use Illuminate\Support\Facades\Notification;use Illuminate\Support\Facades\Storage;use Spatie\Activitylog\Models\Activity;use Symfony\Component\Yaml\Yaml;@@ -315,6 +317,7 @@ COPY --from=$this->build_image_name /app/{$this->application->publish_directory}dispatch(new InstanceProxyCheckJob());}queue_next_deployment($this->application);+ Notification::send($this->application->environment->project->team, new ApplicationDeployedNotification($this->application, $this->deployment_uuid));}private function execute_in_builder(string $command){diff --git a/app/Models/Project.php b/app/Models/Project.phpindex 68b5940676..a790b191da 100644--- a/app/Models/Project.php+++ b/app/Models/Project.php@@ -26,7 +26,10 @@ class Project extends BaseModel{return Project::whereTeamId(session('currentTeam')->id);}-+ public function team()+ {+ return $this->belongsTo(Team::class);+ }public function environments(){return $this->hasMany(Environment::class);diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.phpindex 03fb46e2c8..8db504f404 100644--- a/app/Notifications/Channels/EmailChannel.php+++ b/app/Notifications/Channels/EmailChannel.php@@ -11,20 +11,14 @@ class EmailChannelpublic function send(SendsEmail $notifiable, Notification $notification): void{$this->bootConfigs($notifiable);- $is_test_notification = $notification instanceof \App\Notifications\Notifications\TestNotification;- if ($is_test_notification) {- $bcc = $notifiable->routeNotificationForEmail('smtp_test_recipients');- if (count($bcc) === 0) {- if ($notifiable instanceof \App\Models\Team) {- $bcc = $notifiable->members()->pluck('email')->toArray();- }+ $bcc = $notifiable->routeNotificationForEmail('smtp_test_recipients');+ if (count($bcc) === 0) {+ if ($notifiable instanceof \App\Models\Team) {+ $bcc = $notifiable->members()->pluck('email')->toArray();}- } else {- $bcc = $notifiable->routeNotificationForEmail();}$mailMessage = $notification->toMail($notifiable);-Mail::send([],[],diff --git a/app/Notifications/Notifications/ApplicationDeployedNotification.php b/app/Notifications/Notifications/ApplicationDeployedNotification.phpnew file mode 100644index 0000000000..8718b5a614--- /dev/null+++ b/app/Notifications/Notifications/ApplicationDeployedNotification.php@@ -0,0 +1,67 @@+<?php++namespace App\Notifications\Notifications;++use App\Models\Application;+use App\Models\Team;+use App\Notifications\Channels\EmailChannel;+use App\Notifications\Channels\DiscordChannel;+use Illuminate\Bus\Queueable;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Notification;+use Illuminate\Support\Str;++class ApplicationDeployedNotification extends Notification implements ShouldQueue+{+ use Queueable;+ public Application $application;+ public string $application_name;+ public string $deployment_uuid;+ public string|null $deployment_url = null;+ public string $project_uuid;+ public string $environment_name;+ public string $fqdn;++ public function __construct(Application $application, string $deployment_uuid)+ {+ $this->application = $application;+ $this->application_name = data_get($application, 'name');+ $this->deployment_uuid = $deployment_uuid;+ $this->project_uuid = data_get($application, 'environment.project.uuid');+ $this->environment_name = data_get($application, 'environment.name');+ $this->fqdn = data_get($application, 'fqdn');+ if (Str::of($this->fqdn)->explode(',')->count() > 1) {+ $this->fqdn = Str::of($this->fqdn)->explode(',')->first();+ }+ $this->deployment_url = base_url() . "/project/{$this->project_uuid}/{$this->environment_name}/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}";+ }+ public function via(object $notifiable): array+ {+ $channels = [];+ if ($notifiable->extra_attributes?->get('email_active') && $notifiable->extra_attributes?->get('notifications_deployments')) {+ $channels[] = EmailChannel::class;+ }+ if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_deployments')) {+ $channels[] = DiscordChannel::class;+ }+ return $channels;+ }+ public function toMail(Team $team): MailMessage+ {+ $mail = new MailMessage();+ $mail->subject("New version is deployed of {$this->application_name}");+ $mail->view('emails.application-deployed', [+ 'name' => $this->application_name,+ 'fqdn' => $this->fqdn,+ 'url' => $this->deployment_url,+ ]);+ return $mail;+ }++ public function toDiscord(): string+ {+ return '⚒️ A new version has been deployed of **' . $this->application_name . '**.+[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';+ }+}diff --git a/app/Notifications/Notifications/TestNotification.php b/app/Notifications/Notifications/TestNotification.phpindex e953c3c61d..9f535e0a3d 100644--- a/app/Notifications/Notifications/TestNotification.php+++ b/app/Notifications/Notifications/TestNotification.php@@ -15,20 +15,26 @@ class TestNotification extends Notification implements ShouldQueuepublic function via(object $notifiable): array{$channels = [];- $notifiable->extra_attributes?->get('smtp_active') && $channels[] = EmailChannel::class;- $notifiable->extra_attributes?->get('discord_active') && $channels[] = DiscordChannel::class;+ if ($notifiable->extra_attributes?->get('email_active') && $notifiable->extra_attributes?->get('notifications_test')) {+ $channels[] = EmailChannel::class;+ }+ if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_test')) {+ $channels[] = DiscordChannel::class;+ }return $channels;}public function toMail(): MailMessage{- return (new MailMessage)- ->subject('Coolify Test Notification')- ->line('Congratulations!')- ->line('You have successfully received a test Email notification from Coolify. 🥳');+ $mail = new MailMessage();+ $mail->subject("Coolify Test Notification");+ $mail->view('emails.test');+ return $mail;}public function toDiscord(): string{- return 'You have successfully received a test Discord notification from Coolify. 🥳 [Go to your dashboard](' . base_url() . ')';+ return 'This is a test Discord notification from Coolify.++[Go to your dashboard](' . base_url() . ')';}}diff --git a/database/seeders/InstanceSettingsSeeder.php b/database/seeders/InstanceSettingsSeeder.phpindex 959d0c49c4..937e147abc 100644--- a/database/seeders/InstanceSettingsSeeder.php+++ b/database/seeders/InstanceSettingsSeeder.php@@ -2,6 +2,7 @@namespace Database\Seeders;+use App\Data\SmtpConfiguration;use App\Models\InstanceSettings;use Illuminate\Database\Seeder;use Illuminate\Support\Facades\Process;@@ -16,14 +17,14 @@ class InstanceSettingsSeeder extends SeederInstanceSettings::create(['id' => 0,'is_registration_enabled' => true,- 'extra_attributes' => [+ 'extra_attributes' => SmtpConfiguration::from(['smtp_active' => true,'smtp_test_recipients' => '[email protected],[email protected]','smtp_host' => 'coolify-mail','smtp_port' => 1025,'smtp_from_address' => '[email protected]','smtp_from_name' => 'Coolify',- ]+ ])]);try {$ipv4 = Process::run('curl -4s https://ifconfig.io')->output();diff --git a/resources/views/components/forms/checkbox.blade.php b/resources/views/components/forms/checkbox.blade.phpindex b734736d7d..0ab5c22ef1 100644--- a/resources/views/components/forms/checkbox.blade.php+++ b/resources/views/components/forms/checkbox.blade.php@@ -35,5 +35,5 @@<div class="flex-1"></div><input type="checkbox" @if ($disabled !== null) disabled @endif name={{ $id }}@if (!$noDirty) wire:dirty.class="input-warning" @endif- @if ($instantSave) wire:click='instantSave' wire:model.defer={{ $id }} @else wire:model.defer={{ $value ?? $id }} @endif />+ @if ($instantSave) wire:click='{{ $instantSave === 'instantSave' || $instantSave == '1' ? 'instantSave' : $instantSave }}' wire:model.defer={{ $id }} @else wire:model.defer={{ $value ?? $id }} @endif /></div>diff --git a/resources/views/components/notification-subscription.blade.php b/resources/views/components/notification-subscription.blade.phpnew file mode 100644index 0000000000..7812208679--- /dev/null+++ b/resources/views/components/notification-subscription.blade.php@@ -0,0 +1,9 @@+ <h4 class="mt-4">Subscribe to events</h4>+ <div class="w-64 ">+ @if (isDev())+ <x-forms.checkbox instantSave="instantSaveEvents" id="model.extra_attributes.notifications_test"+ label="Test Notifications" />+ @endif+ <x-forms.checkbox instantSave="instantSaveEvents" id="model.extra_attributes.notifications_deployments"+ label="New Deployments" />+ </div>diff --git a/resources/views/emails/application-deployed.blade.php b/resources/views/emails/application-deployed.blade.phpnew file mode 100644index 0000000000..ee5a11a101--- /dev/null+++ b/resources/views/emails/application-deployed.blade.php@@ -0,0 +1,7 @@+Hello,<br><br>++A new version of your application "{{ $name }}" has been deployed to <a target="_blank"+ href="{{ $fqdn }}">{{ $fqdn }}</a><br><br>++Click the following link to view the deployment logs: <a target="_blank" href="{{ $url }}">View+ Deployment</a><br><br>diff --git a/resources/views/emails/test.blade.php b/resources/views/emails/test.blade.phpindex 9c931db198..c06e333f09 100644--- a/resources/views/emails/test.blade.php+++ b/resources/views/emails/test.blade.php@@ -1 +1,3 @@-Hello from test email. If you are seeing this, it means that your SMTP settings are working.+Hello,<br><br>++If you are seeing this, it means that your SMTP settings are correct.diff --git a/resources/views/livewire/notifications/discord-settings.blade.php b/resources/views/livewire/notifications/discord-settings.blade.phpindex 6272608ce8..aa66c5ff47 100644--- a/resources/views/livewire/notifications/discord-settings.blade.php+++ b/resources/views/livewire/notifications/discord-settings.blade.php@@ -12,11 +12,12 @@</x-forms.button>@endif</div>- <div class="flex flex-col gap-2 xl:flex-row w-96">+ <div class="w-48"><x-forms.checkbox instantSave id="model.extra_attributes.discord_active" label="Notification Enabled" /></div><x-forms.input type="string"helper="Generate a webhook in Discord.<br>Example: https://discord.com/api/webhooks/...." requiredid="model.extra_attributes.discord_webhook" label="Webhook" /></form>+ <x-notification-subscription /></div>diff --git a/resources/views/livewire/notifications/email-settings.blade.php b/resources/views/livewire/notifications/email-settings.blade.phpindex 0f1939c9b2..81c1b78baf 100644--- a/resources/views/livewire/notifications/email-settings.blade.php+++ b/resources/views/livewire/notifications/email-settings.blade.php@@ -17,7 +17,7 @@</x-forms.button>@endif</div>- <div class="flex flex-col">+ <div class="w-48"><x-forms.checkbox instantSave id="model.extra_attributes.smtp_active" label="Notification Enabled" /></div>@@ -53,4 +53,5 @@</div></div></form>+ <x-notification-subscription /></div>