Skip to content

Commit

Permalink
Update to docs and deploy.php formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrjones committed May 3, 2024
1 parent cffe532 commit 3142a4b
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 38 deletions.
36 changes: 34 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
16 changes: 4 additions & 12 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <environment>
```
26 changes: 20 additions & 6 deletions examples/craft-cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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');


Expand All @@ -42,3 +53,6 @@
*
* Any custom deployment tasks to run
*/

// PHP-FPM reload
after('deploy', 'php-fpm:reload');
16 changes: 14 additions & 2 deletions examples/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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');


Expand All @@ -55,3 +64,6 @@
*
* Any custom deployment tasks to run
*/

// PHP-FPM reload
after('deploy', 'php-fpm:reload');
18 changes: 15 additions & 3 deletions examples/laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
require_once 'vendor/studio24/deployer-recipes/recipe/laravel.php';


/**
* 2. Deployment configuration variables
*/
Expand All @@ -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
Expand All @@ -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');


Expand All @@ -43,3 +53,5 @@
* Any custom deployment tasks to run
*/

// PHP-FPM reload
after('deploy', 'php-fpm:reload');
19 changes: 16 additions & 3 deletions examples/symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
require_once 'vendor/studio24/deployer-recipes/recipe/symfony.php';


/**
* 2. Deployment configuration variables
*/
Expand All @@ -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
Expand All @@ -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');


Expand All @@ -42,3 +52,6 @@
*
* Any custom deployment tasks to run
*/

// PHP-FPM reload
after('deploy', 'php-fpm:reload');
18 changes: 13 additions & 5 deletions examples/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
require_once 'vendor/studio24/deployer-recipes/recipe/wordpress.php';


/**
* 2. Deployment configuration variables
*/
Expand All @@ -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
Expand All @@ -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');


Expand All @@ -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');
7 changes: 5 additions & 2 deletions recipe/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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', [
Expand All @@ -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();
task('show-summary', ['show-summary'])->hidden();
2 changes: 1 addition & 1 deletion tasks/check-disk-space.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tasks/ssh-check.php → tasks/check-ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3142a4b

Please sign in to comment.