{"id":19300034,"url":"https://github.com/kirschbaum-development/laravel-preflight-checks","last_synced_at":"2025-04-22T10:31:15.863Z","repository":{"id":56707111,"uuid":"336132386","full_name":"kirschbaum-development/laravel-preflight-checks","owner":"kirschbaum-development","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-24T13:51:33.000Z","size":56,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":15,"default_branch":"main","last_synced_at":"2024-09-26T05:39:50.692Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirschbaum-development.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-05T01:41:08.000Z","updated_at":"2024-06-24T13:50:01.000Z","dependencies_parsed_at":"2024-01-12T20:20:42.484Z","dependency_job_id":"14c9c21c-35b2-4e37-ac22-0792b53ff4c2","html_url":"https://github.com/kirschbaum-development/laravel-preflight-checks","commit_stats":{"total_commits":18,"total_committers":3,"mean_commits":6.0,"dds":"0.11111111111111116","last_synced_commit":"c61b4bb6e6c9152d0e5edd28112b6add8e655478"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-preflight-checks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-preflight-checks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-preflight-checks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-preflight-checks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirschbaum-development","download_url":"https://codeload.github.com/kirschbaum-development/laravel-preflight-checks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223713715,"owners_count":17190498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T23:13:28.258Z","updated_at":"2024-11-09T23:13:28.899Z","avatar_url":"https://github.com/kirschbaum-development.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Preflight Checks\n\n![Laravel Supported Versions](https://img.shields.io/badge/laravel-6.x/7.x/8.x/9.x/10.x/11.x-green.svg)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n\nPerforms pre-flight checks to ensure configuration and setup for deployment or development.\n\nThis package is particularly useful for automated deployments where configuration is managed separately (such as containerized deployments via Docker, K8s, etc). It can also be used as a go/no-go check for setting up local and/or dev environments.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require kirschbaum-development/laravel-preflight-checks\n```\n\n## Setup\n\nAfter requiring the composer package, publish the config file\n\n```bash\nphp artisan vendor:publish --provider=\"Kirschbaum\\PreflightChecks\\PreflightChecksServiceProvider\"\n```\n\nConfigure the `config/preflight_checks.php` file with the configuration necessary for your app. Some defaults are provided (commented out) based on typical environments.\n\nThe config file is structured like so: `'checks'` \u003e `environment name` \u003e `array of checks`\n\n```php\nreturn [\n    'checks' =\u003e [\n        'production' =\u003e [\n            // Database::class,\n            // Redis::class,\n            // Configuration::class =\u003e [\n            //     // Essential production keys here\n            // ],\n        ],\n\n        'anyEnvironmentName' =\u003e [\n            // Any class(es) extending Kirschbaum\\PreflightChecks\\Checks\\PreflightCheck::class\n        ],\n\n        // ...\n    ],\n];\n```\n\nEvery check can be specified with options, for example:\n\n```php\n'production' =\u003e [\n    Database::class =\u003e [\n        'connection' =\u003e 'db2'\n    ],\n]\n```\n\nOr with the fully explicit syntax:\n\n```php\n'production' =\u003e [\n    [\n        'check' =\u003e Database::class,\n        'options' =\u003e [\n            'connection' =\u003e 'db2'\n        ]\n    ],\n]\n```\n\nIf you need to repeat checks (for example, when using multiple database connections), you will need to use the full syntax.\n\n## Available Checks\n\n### Database\n\n`Kirschbaum\\PreflightChecks\\Checks\\Database`\n\nChecks that the database connection can be established, via the PDO, and that the required config keys are set. It outputs some server info and version information.\n\n| Option | Description |\n| --- | --- |\n| `connection` | The name of the connection in `config/database.php` |\n\n### Redis\n\n`Kirschbaum\\PreflightChecks\\Checks\\Redis`\n\nChecks that Redis connection can be established, and that the required config keys are set.\n\n| Option | Description |\n| --- | --- |\n| `connection` | The name of the connection in `config/database.php` |)\n\n### Configuration\n\n`Kirschbaum\\PreflightChecks\\Checks\\Configuration`\n\nChecks that the specified config keys are set. This checks the `config` values, NOT the `env` values to ensure that in higher environments the correct detection is taking place. As such, make sure to specify the same keys you'd use for `config(...)`.\n\nThe accepted options for the `Configuration` preflight check is a list of config keys to check. For example:\n\n```php\n'production' =\u003e [\n    Configuration::class =\u003e [\n        'services.payment.key',\n        'services.mail.key',\n        // ...\n    ]\n]\n```\n\nYou may also pass a hint (recommended for local development only) that will be shown if the key is not set. For example:\n\n```php\n'local' =\u003e [\n    Configuration::class =\u003e [\n        'services.payment.key' =\u003e 'In dashboard as \"Super Secret API Token Key Thing\"',\n        'services.mail.key',\n        // ...\n    ]\n]\n```\n\nWhen a new dev sets up their environment and is missing that config value, they will get that nice friendly message helping them find the key.\n\nYou can also specify optional config values and provide a hint as well with the `OptionalConfiguration` class, which operates the same way, but does not cause the command to fail.\n\n### Write Your Own!\n\nIf you have a special startup consideration you'd like to make, feel free write your own check, extending `Kirschbaum\\PreflightChecks\\Checks\\PreflightCheck`.\n\nSpecify any necessary config keys on the `$requiredConfig` property.\n\nImplement the `check` method, which should perform your check and mark the `$result` as pass/fail.\n\nExample:\n\n```php\n/**\n * Performs the preflight check.\n *\n * This method should set a pass/fail on the result.\n */\npublic function check(Result $result): Result\n{\n    try {\n        // Check something is up/ready/willing/etc\n    } catch (Exception $e) {\n        return $result-\u003efail($e-\u003egetMessage(), $e);\n    }\n\n    return $result-\u003epass('Woohoo! It didn\\'t fail!', $dataFromTheCheck);\n}\n```\n\n## Usage\n\nBasic usage is via the Artisan command:\n\n```bash\nphp artisan preflight:check\n```\n\nIf you would like to see the info on successful checks (not just the failures), add a verbose flag `-v`.\n\nYou may test other environment by specifying the artisan environment (`--env`).\n\nFor higher and/or automated environments (such as CI/CD), you may want to use the `--show-only-failures` flag to cut down on noise.\n\n### Kubernetes\n\nIn Kubernetes deployments, this can be used in a startup probe (1.20+):\n\n```yaml\nstartupProbe:\n  exec:\n    command:\n    - php\n    - artisan\n    - preflight:check\n    - --show-only-failures\n  failureThreshold: 30\n  periodSeconds: 10\n```\n\nYou could also set this up for a readiness probe, but keep in mind that probe is still run throughout the entire lifecycle of the container (we are establishing connections to Redis or the DB, which are not insignificant to consider).\n\n### Containerized Environments\n\nIn containerized environments (including K8s), you may want to \"block\" container startup (e.g. `php-fpm`) with this command, to ensure the correct environment was loaded and cached properly. For the standard `php-fpm` docker container, you can use a startup script such as:\n\n```bash\n#!/bin/bash\nset -e\n\nphp artisan optimize\nphp artisan preflight:check -v\nphp-fpm\n```\n\n### Local Environment\n\nThe `preflight:check` command can also provide a concrete method of assuring all the appropriate environment configuration has taken place. This can be especially helpful when bringing on new developers, as simply running `php artisan preflight:check` can give them a good indication of what's left to setup/configure before their environment is live.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email security@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.\n\n## Credits\n\n- [Zack Teska](https://github.com/zerodahero)\n\n## Sponsorship\n\nDevelopment of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)!\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Flaravel-preflight-checks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirschbaum-development%2Flaravel-preflight-checks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Flaravel-preflight-checks/lists"}