diff --git a/docs/recipe/README.md b/docs/recipe/README.md index 05a922165..9df62c3ed 100644 --- a/docs/recipe/README.md +++ b/docs/recipe/README.md @@ -19,6 +19,7 @@ * [Provision Recipe](/docs/recipe/provision.md) * [Shopware Recipe](/docs/recipe/shopware.md) * [Silverstripe Recipe](/docs/recipe/silverstripe.md) +* [Spiral Recipe](/docs/recipe/spiral.md) * [Statamic Recipe](/docs/recipe/statamic.md) * [Sulu Recipe](/docs/recipe/sulu.md) * [Symfony Recipe](/docs/recipe/symfony.md) diff --git a/docs/recipe/spiral.md b/docs/recipe/spiral.md new file mode 100644 index 000000000..5c649c180 --- /dev/null +++ b/docs/recipe/spiral.md @@ -0,0 +1,284 @@ + + + + +# How to Deploy a Spiral Project + +```php +require 'recipe/spiral.php'; +``` + +[Source](/recipe/spiral.php) + +Deployer is a free and open source deployment tool written in PHP. +It helps you to deploy your Spiral application to a server. +It is very easy to use and has a lot of features. + +Three main features of Deployer are: +- **Provisioning** - provision your server for you. +- **Zero downtime deployment** - deploy your application without a downtime. +- **Rollbacks** - rollback your application to a previous version, if something goes wrong. + +Additionally, Deployer has a lot of other features, like: +- **Easy to use** - Deployer is very easy to use. It has a simple and intuitive syntax. +- **Fast** - Deployer is very fast. It uses parallel connections to deploy your application. +- **Secure** - Deployer uses SSH to connect to your server. +- **Supports all major PHP frameworks** - Deployer supports all major PHP frameworks. + +You can read more about Deployer in [Getting Started](/docs/getting-started.md). + +The [deploy](#deploy) task of **Spiral** consists of: +* [deploy:prepare](/docs/recipe/common.md#deployprepare) – Prepares a new release + * [deploy:info](/docs/recipe/deploy/info.md#deployinfo) – Displays info about deployment + * [deploy:setup](/docs/recipe/deploy/setup.md#deploysetup) – Prepares host for deploy + * [deploy:lock](/docs/recipe/deploy/lock.md#deploylock) – Locks deploy + * [deploy:release](/docs/recipe/deploy/release.md#deployrelease) – Prepares release + * [deploy:update_code](/docs/recipe/deploy/update_code.md#deployupdate_code) – Updates code + * [deploy:shared](/docs/recipe/deploy/shared.md#deployshared) – Creates symlinks for shared files and dirs + * [deploy:writable](/docs/recipe/deploy/writable.md#deploywritable) – Makes writable dirs +* [deploy:environment](/docs/recipe/spiral.md#deployenvironment) – Create .env file if it doesn't exist +* [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) – Installs vendors +* [spiral:encrypt-key](/docs/recipe/spiral.md#spiralencrypt-key) – Generate a new encryption key if it doesn't already exist +* [spiral:configure](/docs/recipe/spiral.md#spiralconfigure) – Configure the Spiral Framework +* [deploy:download-rr](/docs/recipe/spiral.md#deploydownload-rr) – Download RoadRunner +* [deploy:publish](/docs/recipe/common.md#deploypublish) – Publishes the release + * [deploy:symlink](/docs/recipe/deploy/symlink.md#deploysymlink) – Creates symlink to release + * [deploy:unlock](/docs/recipe/deploy/lock.md#deployunlock) – Unlocks deploy + * [deploy:cleanup](/docs/recipe/deploy/cleanup.md#deploycleanup) – Cleanup old releases + * [deploy:success](/docs/recipe/common.md#deploysuccess) – + + +The spiral recipe is based on the [common](/docs/recipe/common.md) recipe. + +## Configuration +### shared_dirs +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L9) + +Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/deploy/shared.php`. + + + +```php title="Default value" +['runtime'] +``` + + +### writable_dirs +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L10) + +Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `recipe/deploy/writable.php`. + + + +```php title="Default value" +['runtime', 'public'] +``` + + +### roadrunner_path +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L13) + +Define the path to the RoadRunner server. + +```php title="Default value" +'{{release_or_current_path}}' +``` + + + +## Tasks + +### deploy:environment +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L16) + +Create .env file if it doesn't exist. + + + + +### spiral:configure +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L58) + +Configure the Spiral Framework. + +Spiral Framework console commands + + +### spiral:cycle +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L61) + +Update the CycleORM schema from the database and annotated classes. + + + + +### spiral:migrate +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L64) + +Perform all outstanding migrations. + + + + +### spiral:update +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L67) + +Update the project state. + + + + +### spiral:cache:clean +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L70) + +Clean the application's runtime cache. + + + + +### spiral:i18n:reset +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L73) + +Reset the translation cache. + + + + +### spiral:encrypt-key +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L76) + +Generate a new encryption key if it doesn't already exist. + + + + +### spiral:views:compile +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L79) + +Warm up the view cache. + + + + +### spiral:views:reset +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L82) + +Clear the view cache. + + + + +### cycle:migrate +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L88) + +Generate ORM schema migrations. + +Cycle ORM and migrations console commands + + +### cycle:render +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L91) + +Render available CycleORM schemas. + + + + +### cycle:sync +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L94) + +Sync Cycle ORM schema with database without intermediate migration (risk operation). + + + + +### migrate:init +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L97) + +Init the migrations component and create the migrations table. + + + + +### migrate:replay +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L100) + +Replay (down, up) one or multiple migrations. + + + + +### migrate:rollback +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L103) + +Rollback one (default) or multiple migrations. + + + + +### migrate:status +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L106) + +Get list of all available migrations and their statuses. + + + + +### roadrunner:serve +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L112) + +Start RoadRunner server. + +RoadRunner console commands + + +### roadrunner:stop +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L117) + +Stop RoadRunner server. + + + + +### roadrunner:reset +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L120) + +Reset workers of all services. + + + + +### deploy:download-rr +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L126) + +Download RoadRunner. + +Download and restart RoadRunner + + +### deploy:restart-rr +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L132) + +Restart RoadRunner. + + + + +### deploy +[Source](https://github.com/deployphp/deployer/blob/master/recipe/spiral.php#L146) + +Deploys your project. + +Main task + + +This task is group task which contains next tasks: +* [deploy:prepare](/docs/recipe/common.md#deployprepare) +* [deploy:environment](/docs/recipe/spiral.md#deployenvironment) +* [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) +* [spiral:encrypt-key](/docs/recipe/spiral.md#spiralencrypt-key) +* [spiral:configure](/docs/recipe/spiral.md#spiralconfigure) +* [deploy:download-rr](/docs/recipe/spiral.md#deploydownload-rr) +* [deploy:publish](/docs/recipe/common.md#deploypublish) + + diff --git a/recipe/spiral.php b/recipe/spiral.php new file mode 100644 index 000000000..cf003e289 --- /dev/null +++ b/recipe/spiral.php @@ -0,0 +1,158 @@ +$output"); + } + }; +} + +/** + * Run a RoadRunner command. + * + * Supported options: + * - 'showOutput': Show the output of the command if given. + */ +function rr(string $command, array $options = []): \Closure +{ + return function () use ($command, $options): void { + $output = run("cd {{roadrunner_path}} && ./rr $command"); + + if (\in_array('showOutput', $options, true)) { + writeln("$output"); + } + }; +} + +/** + * Spiral Framework console commands + */ +desc('Configure project'); +task('spiral:configure', command('configure', ['showOutput'])); + +desc('Update (init) cycle schema from database and annotated classes'); +task('spiral:cycle', command('cycle', ['showOutput'])); + +desc('Perform all outstanding migrations'); +task('spiral:migrate', command('migrate', ['showOutput'])); + +desc('Update project state'); +task('spiral:update', command('update', ['showOutput'])); + +desc('Clean application runtime cache'); +task('spiral:cache:clean', command('cache:clean', ['showOutput'])); + +desc('Reset translation cache'); +task('spiral:i18n:reset', command('i18n:reset', ['showOutput'])); + +desc('Generate new encryption key, if it doesn\'t exist'); +task('spiral:encrypt-key', command('encrypt:key -m .env -p', ['showOutput'])); + +desc('Warm-up view cache'); +task('spiral:views:compile', command('views:compile', ['showOutput'])); + +desc('Clear view cache'); +task('spiral:views:reset', command('views:reset', ['showOutput'])); + +/** + * Cycle ORM and migrations console commands + */ +desc('Generate ORM schema migrations'); +task('cycle:migrate', command('cycle:migrate', ['showOutput'])); + +desc('Render available CycleORM schemas'); +task('cycle:render', command('cycle:render', ['showOutput'])); + +desc('Sync Cycle ORM schema with database without intermediate migration (risk operation)'); +task('cycle:sync', command('cycle:sync', ['showOutput'])); + +desc('Init migrations component (create migrations table)'); +task('migrate:init', command('migrate:init', ['showOutput'])); + +desc('Replay (down, up) one or multiple migrations'); +task('migrate:replay', command('migrate:replay', ['showOutput'])); + +desc('Rollback one (default) or multiple migrations'); +task('migrate:rollback', command('migrate:rollback', ['showOutput'])); + +desc('Get list of all available migrations and their statuses'); +task('migrate:status', command('migrate:status', ['showOutput'])); + +/** + * RoadRunner console commands + */ +desc('Start RoadRunner server'); +task('roadrunner:serve', function (): void { + exec(parse('cd {{roadrunner_path}} && ./rr serve -p > /dev/null 2>&1 &')); +}); + +desc('Stop RoadRunner server'); +task('roadrunner:stop', rr('stop', ['showOutput'])); + +desc('Reset workers of all services'); +task('roadrunner:reset', rr('reset', ['showOutput'])); + +/** + * Download and restart RoadRunner + */ +desc('Download RoadRunner'); +task('deploy:download-rr', function (): void { + $output = run("cd {{release_or_current_path}} && {{bin/php}} ./vendor/bin/rr get-binary -l {{roadrunner_path}}"); + writeln("$output"); +}); + +desc('Restart RoadRunner'); +task('deploy:restart-rr', function (): void { + try { + invoke('roadrunner:reset'); + writeln("Roadrunner successfully restarted."); + } catch (\Throwable $e) { + invoke('roadrunner:serve'); + writeln("Roadrunner successfully started."); + } +}); + +/** + * Main task + */ +desc('Deploys your project'); +task('deploy', [ + 'deploy:prepare', + 'deploy:environment', + 'deploy:vendors', + 'spiral:encrypt-key', + 'spiral:configure', + 'deploy:download-rr', + 'deploy:publish', + 'deploy:restart-rr' +]);