-
Notifications
You must be signed in to change notification settings - Fork 4
feat(reverb): implement reverb health check + env variables generator #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SlimDeluxe
merged 2 commits into
DataLinx:main
from
KilianTrunk:feat/reverb-improvements
Jul 19, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| /* | ||
| * A result store is responsible for saving the results of the checks. The | ||
| * `EloquentHealthResultStore` will save results in the database. You | ||
| * can use multiple stores at the same time. | ||
| */ | ||
| 'result_stores' => [ | ||
| Spatie\Health\ResultStores\EloquentHealthResultStore::class => [ | ||
| 'connection' => env('HEALTH_DB_CONNECTION', env('DB_CONNECTION')), | ||
| 'model' => Spatie\Health\Models\HealthCheckResultHistoryItem::class, | ||
| 'keep_history_for_days' => 5, | ||
| ], | ||
|
|
||
| /* | ||
| Spatie\Health\ResultStores\CacheHealthResultStore::class => [ | ||
| 'store' => 'file', | ||
| ], | ||
|
|
||
| Spatie\Health\ResultStores\JsonFileHealthResultStore::class => [ | ||
| 'disk' => 's3', | ||
| 'path' => 'health.json', | ||
| ], | ||
|
|
||
| Spatie\Health\ResultStores\InMemoryHealthResultStore::class, | ||
| */ | ||
| ], | ||
|
|
||
| /* | ||
| * You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'. | ||
| * For Slack you need to install laravel/slack-notification-channel. | ||
| */ | ||
| 'notifications' => [ | ||
| /* | ||
| * Notifications will only get sent if this option is set to `true`. | ||
| */ | ||
| 'enabled' => true, | ||
|
|
||
| 'notifications' => [ | ||
| Spatie\Health\Notifications\CheckFailedNotification::class => ['mail'], | ||
| ], | ||
|
|
||
| /* | ||
| * Here you can specify the notifiable to which the notifications should be sent. The default | ||
| * notifiable will use the variables specified in this config file. | ||
| */ | ||
| 'notifiable' => Spatie\Health\Notifications\Notifiable::class, | ||
|
|
||
| /* | ||
| * When checks start failing, you could potentially end up getting | ||
| * a notification every minute. | ||
| * | ||
| * With this setting, notifications are throttled. By default, you'll | ||
| * only get one notification per hour. | ||
| */ | ||
| 'throttle_notifications_for_minutes' => 60, | ||
| 'throttle_notifications_key' => 'health:latestNotificationSentAt:', | ||
|
|
||
| 'mail' => [ | ||
| 'to' => 'your@example.com', | ||
|
|
||
| 'from' => [ | ||
| 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), | ||
| 'name' => env('MAIL_FROM_NAME', 'Example'), | ||
| ], | ||
| ], | ||
|
|
||
| 'slack' => [ | ||
| 'webhook_url' => env('HEALTH_SLACK_WEBHOOK_URL', ''), | ||
|
|
||
| /* | ||
| * If this is set to null the default channel of the webhook will be used. | ||
| */ | ||
| 'channel' => null, | ||
|
|
||
| 'username' => null, | ||
|
|
||
| 'icon' => null, | ||
| ], | ||
| ], | ||
|
|
||
| /* | ||
| * You can let Oh Dear monitor the results of all health checks. This way, you'll | ||
| * get notified of any problems even if your application goes totally down. Via | ||
| * Oh Dear, you can also have access to more advanced notification options. | ||
| */ | ||
| 'oh_dear_endpoint' => [ | ||
| 'enabled' => false, | ||
|
|
||
| /* | ||
| * When this option is enabled, the checks will run before sending a response. | ||
| * Otherwise, we'll send the results from the last time the checks have run. | ||
| */ | ||
| 'always_send_fresh_results' => true, | ||
|
|
||
| /* | ||
| * The secret that is displayed at the Application Health settings at Oh Dear. | ||
| */ | ||
| 'secret' => env('OH_DEAR_HEALTH_CHECK_SECRET'), | ||
|
|
||
| /* | ||
| * The URL that should be configured in the Application health settings at Oh Dear. | ||
| */ | ||
| 'url' => '/oh-dear-health-check-results', | ||
| ], | ||
|
|
||
| /* | ||
| * You can specify a heartbeat URL for the Horizon check. | ||
| * This URL will be pinged if the Horizon check is successful. | ||
| * This way you can get notified if Horizon goes down. | ||
| */ | ||
| 'horizon' => [ | ||
| 'heartbeat_url' => env('HORIZON_HEARTBEAT_URL', null), | ||
| ], | ||
|
|
||
| /* | ||
| * You can specify a heartbeat URL for the Schedule check. | ||
| * This URL will be pinged if the Schedule check is successful. | ||
| * This way you can get notified if the schedule fails to run. | ||
| */ | ||
| 'schedule' => [ | ||
| 'heartbeat_url' => env('SCHEDULE_HEARTBEAT_URL', null), | ||
| ], | ||
|
|
||
| /* | ||
| * You can specify a heartbeat URL for the Reverb check. | ||
| * This URL will be pinged if the Reverb check is successful. | ||
| * This way you can get notified if Reverb goes down. | ||
| */ | ||
| 'reverb' => [ | ||
| 'heartbeat_url' => env('REVERB_HEARTBEAT_URL', null), | ||
| ], | ||
|
|
||
| /* | ||
| * You can set a theme for the local results page | ||
| * | ||
| * - light: light mode | ||
| * - dark: dark mode | ||
| */ | ||
| 'theme' => 'light', | ||
|
|
||
| /* | ||
| * When enabled, completed `HealthQueueJob`s will be displayed | ||
| * in Horizon's silenced jobs screen. | ||
| */ | ||
| 'silence_health_queue_job' => true, | ||
|
|
||
| /* | ||
| * The response code to use for HealthCheckJsonResultsController when a health | ||
| * check has failed | ||
| */ | ||
| 'json_results_failure_status' => 200, | ||
|
|
||
| /* | ||
| * You can specify a secret token that needs to be sent in the X-Secret-Token for secured access. | ||
| */ | ||
| 'secret_token' => env('HEALTH_SECRET_TOKEN') ?? null, | ||
|
|
||
| /** | ||
| * By default, conditionally skipped health checks are treated as failures. | ||
| * You can override this behavior by uncommenting the configuration below. | ||
| * | ||
| * @link https://spatie.be/docs/laravel-health/v1/basic-usage/conditionally-running-or-modifying-checks | ||
| */ | ||
| // 'treat_skipped_as_failure' => false | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| <?php | ||
|
|
||
| namespace Eclipse\Core\Console\Commands; | ||
|
|
||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\File; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| /** | ||
| * Generate Reverb WebSocket server credentials for Laravel Broadcasting. | ||
| * | ||
| * This command generates the required credentials for Laravel Reverb WebSocket server: | ||
| * - REVERB_APP_ID: Random 6-digit number (100,000 - 999,999) | ||
| * - REVERB_APP_KEY: Random 20-character lowercase string | ||
| * - REVERB_APP_SECRET: Random 20-character lowercase string | ||
| * | ||
| * The credentials are automatically added to the .env file. If credentials already exist, | ||
| * use the --force flag to overwrite them. | ||
| * | ||
| * This replaces the need to run `php artisan install:broadcasting` for new projects, | ||
| * ensuring Reverb is configured out-of-the-box. | ||
| * | ||
| * @example php artisan eclipse:setup:reverb | ||
| * @example php artisan eclipse:setup:reverb --force | ||
| */ | ||
| class SetupReverb extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'eclipse:setup:reverb | ||
| {--force : Force overwrite existing credentials}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Generate random Reverb credentials (APP_ID, APP_KEY, APP_SECRET) for WebSocket broadcasting'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| * | ||
| * Generates new Reverb credentials and updates the .env file. | ||
| * Uses the same generation logic as Laravel Reverb's install command. | ||
| * | ||
| * @return int Command exit code (SUCCESS or FAILURE) | ||
| */ | ||
| public function handle(): int | ||
| { | ||
| if (File::missing($env = app()->environmentFile())) { | ||
| $this->components->error('Environment file not found.'); | ||
|
|
||
| return self::FAILURE; | ||
| } | ||
|
|
||
| $contents = File::get($env); | ||
|
|
||
| // Check if credentials already exist | ||
| $hasCredentials = Str::contains($contents, 'REVERB_APP_ID=') && | ||
| ! Str::contains($contents, 'REVERB_APP_ID=null'); | ||
|
|
||
| if ($hasCredentials && ! $this->option('force')) { | ||
| $this->components->warn('Reverb credentials already exist in .env file.'); | ||
| $this->components->info('Use --force to overwrite existing credentials.'); | ||
|
|
||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| // Generate credentials using the same logic as Laravel Reverb | ||
| $appId = random_int(100_000, 999_999); | ||
| $appKey = Str::lower(Str::random(20)); | ||
| $appSecret = Str::lower(Str::random(20)); | ||
|
|
||
| $this->updateEnvironmentFile($env, $contents, $appId, $appKey, $appSecret); | ||
|
|
||
| $this->components->info('Reverb credentials generated successfully:'); | ||
| $this->components->twoColumnDetail('REVERB_APP_ID', $appId); | ||
| $this->components->twoColumnDetail('REVERB_APP_KEY', $appKey); | ||
| $this->components->twoColumnDetail('REVERB_APP_SECRET', '***'.substr($appSecret, -4)); | ||
|
|
||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| /** | ||
| * Update the environment file with new Reverb credentials. | ||
| * | ||
| * This method handles both updating existing credentials and adding new ones. | ||
| * It uses regex replacement for existing values and appends new lines for missing keys. | ||
| * | ||
| * @param string $envPath Path to the .env file | ||
| * @param string $contents Current contents of the .env file | ||
| * @param int $appId Generated Reverb application ID | ||
| * @param string $appKey Generated Reverb application key | ||
| * @param string $appSecret Generated Reverb application secret | ||
| */ | ||
| protected function updateEnvironmentFile(string $envPath, string $contents, int $appId, string $appKey, string $appSecret): void | ||
| { | ||
| $replacements = [ | ||
| 'REVERB_APP_ID' => "REVERB_APP_ID={$appId}", | ||
| 'REVERB_APP_KEY' => "REVERB_APP_KEY={$appKey}", | ||
| 'REVERB_APP_SECRET' => "REVERB_APP_SECRET={$appSecret}", | ||
| ]; | ||
|
|
||
| $newContents = $contents; | ||
|
|
||
| foreach ($replacements as $key => $value) { | ||
| if (Str::contains($newContents, "{$key}=")) { | ||
| // Replace existing value | ||
| $newContents = preg_replace( | ||
| "/^{$key}=.*$/m", | ||
| $value, | ||
| $newContents | ||
| ); | ||
| } else { | ||
| // Add new line if it doesn't exist | ||
| $newContents = rtrim($newContents).PHP_EOL.$value.PHP_EOL; | ||
| } | ||
| } | ||
|
|
||
| File::put($envPath, $newContents); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.