diff --git a/docs/installation.md b/docs/installation.md index 9724be9..4d72c46 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -69,7 +69,29 @@ The different sections of the deploy file are explained below. ## 1. Deployer recipe -The Deployer recipe the deploy script is based on. +The Deployer recipe the deploy script is based on. + +You can add other recipes for specific tasks. + +### Slack + +Add the Slack recipe to send notifications to a Slack channel on deployment. + +``` +require 'vendor/studio24/deployer-recipes/recipe/slack.php'; +``` + +You need to set up a [Slack webhook URL](https://api.slack.com/messaging/webhooks) and save this in your `.env` file: + +``` +SLACK_WEBHOOK=https://hooks.slack.com/services/your/webhook/url +``` + +In your deploy.php + +``` +set('dotenv', '{{current_path}}/.env'); +``` ## 2. Deployment configuration variables @@ -78,7 +100,7 @@ Configuration variables are set up using the `set()` function. You'll need to ed * `application` - your application name * `repository` - GitHub repo URL, please ensure this uses the SSH URL, e.g. git@github.com:studio24/project-name.git * `http_user` - HTTP user that the webserver runs as (when we use PHP-FPM this is normally `production` or `staging`), remove this if you're not using PHP-FPM -* `log_files` - Path to log files, separate multiple files with a comma +* `log_files` - Path to log files, you can add multiple files as an array (or a string separated by spaces) Settings that you shouldn't need to change: @@ -143,6 +165,16 @@ set('sync', [ See [sync documentation](tasks/sync.md). +### PHP-FPM + +To reload PHP-FPM after deployment, use: + +``` +after('deploy', 'php-fpm:reload'); +``` + +See [PHP-FPM docs](https://deployer.org/docs/7.x/contrib/php-fpm). We set the `php_fpm_command` in [common.php](../recipe/common.php). + ### Check disk space The deployment process checks disk space and warns on low capacity. diff --git a/docs/upgrading.md b/docs/upgrading.md index 23a73bc..4d4187d 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -20,22 +20,14 @@ It's recommended you rename your existing deployment file for reference: cp deploy.php deploy.v1.php ``` -You can then copy an example deployment file (see [installation](installation.md)). -You can copy your existing setup into this new file. +You can then copy an example deployment file (see [installation](installation.md#create-a-deployphp-file)) and copy your existing setup into here. -### Recipe - -Replace: +General tips appear below. -```php -require 'vendor/studio24/deployer-recipes/all.php'; -``` +### Recipe -with: +You should only need to require once recipe file. -```php -require 'vendor/studio24/deployer-recipes/recipe/common.php'; -``` ### Configuration diff --git a/docs/usage.md b/docs/usage.md index d52990c..8b37a44 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -122,3 +122,9 @@ E.g. to connect to staging: ``` dep ssh staging ``` + +You can check if your SSH connection is working via: + +``` +dep check:ssh +``` diff --git a/examples/craft-cms.php b/examples/craft-cms.php index 587ef63..3750479 100644 --- a/examples/craft-cms.php +++ b/examples/craft-cms.php @@ -2,10 +2,10 @@ namespace Deployer; /** - * 1. Deployer recipes we are using for this website + * 1. Deployer recipe we are using for this website */ require_once 'vendor/studio24/deployer-recipes/recipe/craftcms.php'; - +require 'contrib/php-fpm.php'; /** * 2. Deployment configuration variables @@ -17,6 +17,9 @@ // Git repo set('repository', 'git@github.com:studio24/xxx.git'); +// Filesystem volume we're deploying to +set('disk_space_filesystem', '/'); + /** * 3. Hosts @@ -25,15 +28,23 @@ host('production') ->set('hostname', '1.2.3.4') ->set('http_user', 'production') - ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/production') - ->set('log_files', 'storage/logs/*.log /data/logs/DOMAIN.co.uk.access.log /data/logs/DOMAIN.co.uk.error.log') + ->set('deploy_path', '/var/www/vhosts/DOMAIN.co.uk/production') + ->set('log_files', [ + 'storage/logs/*.log', + '/var/log/apache2/DOMAIN.co.uk.access.log', + '/var/log/apache2/DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://www.DOMAIN.co.uk'); host('staging') ->set('hostname', '1.2.3.4') ->set('http_user', 'staging') - ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/staging') - ->set('log_files', 'storage/logs/*.log /data/logs/staging.DOMAIN.co.uk.access.log /data/logs/staging.DOMAIN.co.uk.error.log') + ->set('deploy_path', '/var/www/vhosts/DOMAIN.co.uk/staging') + ->set('log_files', [ + 'storage/logs/*.log', + '/var/log/apache2/staging.DOMAIN.co.uk.access.log', + '/var/log/apache2/staging.DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://DOMAIN.studio24.dev'); @@ -42,3 +53,6 @@ * * Any custom deployment tasks to run */ + +// PHP-FPM reload +after('deploy', 'php-fpm:reload'); diff --git a/examples/default.php b/examples/default.php index 31ceafe..4e7b612 100644 --- a/examples/default.php +++ b/examples/default.php @@ -16,6 +16,9 @@ // Git repo set('repository', 'git@github.com:studio24/xxx.git'); +// Filesystem volume we're deploying to +set('disk_space_filesystem', '/'); + // Shared files that need to persist between deployments set('shared_files', [ '.env' @@ -39,14 +42,20 @@ ->set('hostname', '1.2.3.4') ->set('http_user', 'production') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/production') - ->set('log_files', '/data/logs/DOMAIN.co.uk.access.log /data/logs/DOMAIN.co.uk.error.log') + ->set('log_files', [ + '/data/logs/DOMAIN.co.uk.access.log', + '/data/logs/DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://www.DOMAIN.co.uk'); host('staging') ->set('hostname', '1.2.3.4') ->set('http_user', 'staging') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/staging') - ->set('log_files', '/data/logs/staging.DOMAIN.co.uk.access.log /data/logs/staging.DOMAIN.co.uk.error.log') + ->set('log_files', [ + '/data/logs/staging.DOMAIN.co.uk.access.log', + '/data/logs/staging.DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://DOMAIN.studio24.dev'); @@ -55,3 +64,6 @@ * * Any custom deployment tasks to run */ + +// PHP-FPM reload +after('deploy', 'php-fpm:reload'); diff --git a/examples/laravel.php b/examples/laravel.php index bc8eae2..a5432b2 100644 --- a/examples/laravel.php +++ b/examples/laravel.php @@ -6,7 +6,6 @@ */ require_once 'vendor/studio24/deployer-recipes/recipe/laravel.php'; - /** * 2. Deployment configuration variables */ @@ -17,6 +16,9 @@ // Git repo set('repository', 'git@github.com:studio24/xxx.git'); +// Filesystem volume we're deploying to +set('disk_space_filesystem', '/'); + /** * 3. Hosts @@ -26,14 +28,22 @@ ->set('hostname', '1.2.3.4') ->set('http_user', 'production') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/production') - ->set('log_files', 'storage/logs/*.log /data/logs/DOMAIN.co.uk.access.log /data/logs/DOMAIN.co.uk.error.log') + ->set('log_files', [ + 'storage/logs/*.log', + '/data/logs/DOMAIN.co.uk.access.log', + '/data/logs/DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://www.DOMAIN.co.uk'); host('staging') ->set('hostname', '1.2.3.4') ->set('http_user', 'staging') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/staging') - ->set('log_files', 'storage/logs/*.log /data/logs/staging.DOMAIN.co.uk.access.log /data/logs/staging.DOMAIN.co.uk.error.log') + ->set('log_files', [ + 'storage/logs/*.log', + '/data/logs/staging.DOMAIN.co.uk.access.log', + '/data/logs/staging.DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://DOMAIN.studio24.dev'); @@ -43,3 +53,5 @@ * Any custom deployment tasks to run */ +// PHP-FPM reload +after('deploy', 'php-fpm:reload'); diff --git a/examples/symfony.php b/examples/symfony.php index 17e1aac..12ea8bf 100644 --- a/examples/symfony.php +++ b/examples/symfony.php @@ -6,7 +6,6 @@ */ require_once 'vendor/studio24/deployer-recipes/recipe/symfony.php'; - /** * 2. Deployment configuration variables */ @@ -17,6 +16,9 @@ // Git repo set('repository', 'git@github.com:studio24/xxx.git'); +// Filesystem volume we're deploying to +set('disk_space_filesystem', '/'); + /** * 3. Hosts @@ -26,14 +28,22 @@ ->set('hostname', '1.2.3.4') ->set('http_user', 'production') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/production') - ->set('log_files', 'var/logs/*.log /data/logs/DOMAIN.co.uk.access.log /data/logs/DOMAIN.co.uk.error.log') + ->set('log_files', [ + 'var/logs/*.log', + '/data/logs/DOMAIN.co.uk.access.log', + '/data/logs/DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://www.DOMAIN.co.uk'); host('staging') ->set('hostname', '1.2.3.4') ->set('http_user', 'staging') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/staging') - ->set('log_files', 'var/logs/*.log /data/logs/staging.DOMAIN.co.uk.access.log /data/logs/staging.DOMAIN.co.uk.error.log') + ->set('log_files', [ + 'var/logs/*.log', + '/data/logs/staging.DOMAIN.co.uk.access.log', + '/data/logs/staging.DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://DOMAIN.studio24.dev'); @@ -42,3 +52,6 @@ * * Any custom deployment tasks to run */ + +// PHP-FPM reload +after('deploy', 'php-fpm:reload'); diff --git a/examples/wordpress.php b/examples/wordpress.php index 814a26b..bb662be 100644 --- a/examples/wordpress.php +++ b/examples/wordpress.php @@ -6,7 +6,6 @@ */ require_once 'vendor/studio24/deployer-recipes/recipe/wordpress.php'; - /** * 2. Deployment configuration variables */ @@ -17,6 +16,9 @@ // Git repo set('repository', 'git@github.com:studio24/xxx.git'); +// Filesystem volume we're deploying to +set('disk_space_filesystem', '/'); + /** * 3. Hosts @@ -26,14 +28,20 @@ ->set('hostname', '1.2.3.4') ->set('http_user', 'production') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/production') - ->set('log_files', '/data/logs/DOMAIN.co.uk.access.log /data/logs/DOMAIN.co.uk.error.log') + ->set('log_files', [ + '/data/logs/DOMAIN.co.uk.access.log', + '/data/logs/DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://www.DOMAIN.co.uk'); host('staging') ->set('hostname', '1.2.3.4') ->set('http_user', 'staging') ->set('deploy_path', '/data/var/www/vhosts/DOMAIN.co.uk/staging') - ->set('log_files', '/data/logs/staging.DOMAIN.co.uk.access.log /data/logs/staging.DOMAIN.co.uk.error.log') + ->set('log_files', [ + '/data/logs/staging.DOMAIN.co.uk.access.log', + '/data/logs/staging.DOMAIN.co.uk.error.log', + ]) ->set('url', 'https://DOMAIN.studio24.dev'); @@ -43,5 +51,5 @@ * Any custom deployment tasks to run */ -// Install composer dependencies in subpaths -//before('deploy:publish', 'vendors-subpath'); +// PHP-FPM reload +after('deploy', 'php-fpm:reload'); diff --git a/recipe/common.php b/recipe/common.php index eef4262..900e82d 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -11,9 +11,9 @@ require_once __DIR__ . '/../tasks/show-summary.php'; require_once __DIR__ . '/../tasks/check-branch.php'; require_once __DIR__ . '/../tasks/check-disk-space.php'; +require_once __DIR__ . '/../tasks/check-ssh.php'; require_once __DIR__ . '/../tasks/confirm-continue.php'; require_once __DIR__ . '/../tasks/vendors-subpath.php'; -require_once __DIR__ . '/../tasks/ssh-check.php'; require_once __DIR__ . '/../tasks/logs.php'; // Default deployment and HTTP users @@ -23,6 +23,9 @@ // Default web root set('webroot', 'web'); +// Command to reload PHP-FPM +set('php_fpm_command', 'sudo -n service {{php_fpm_service}} reload'); + // Run pre-deployment checks desc('Run pre-deployment checks'); task('deploy:pre-deploy-checks', [ @@ -46,4 +49,4 @@ task('display-disk-space', ['check:disk-space'])->hidden(); task('check-branch', ['check:branch'])->hidden(); task('pre-deploy-checks', ['deploy:pre-deploy-checks'])->hidden(); -task('show-summary', ['show-summary'])->hidden(); \ No newline at end of file +task('show-summary', ['show-summary'])->hidden(); diff --git a/tasks/check-disk-space.php b/tasks/check-disk-space.php index 03b77a4..380292c 100644 --- a/tasks/check-disk-space.php +++ b/tasks/check-disk-space.php @@ -11,7 +11,7 @@ use Deployer\Task\Context; -desc('Display server disk usage prior to deployment'); +desc('Check remote server disk usage'); task('check:disk-space', function () { $filesystem = get('disk_space_filesystem', ''); $threshold = (int) get('disk_space_threshold', 80); diff --git a/tasks/ssh-check.php b/tasks/check-ssh.php similarity index 82% rename from tasks/ssh-check.php rename to tasks/check-ssh.php index e7f45ab..272eab0 100644 --- a/tasks/ssh-check.php +++ b/tasks/check-ssh.php @@ -2,8 +2,8 @@ namespace Deployer; -desc('Checks you can connect to the host via SSH'); -task('ssh:check', function () { +desc('Check you can connect to the host via SSH'); +task('check:ssh', function () { // Get timeout value, defaults to 10 seconds to give feedback quickly $timeout = get('check-ssh-timeout', 10);