Skip to content

Commit

Permalink
Merge pull request #5 from studio24/minor-corrections
Browse files Browse the repository at this point in the history
Minor updates and add local deployer
  • Loading branch information
simonrjones authored Mar 19, 2021
2 parents 2da73b8 + e4c3425 commit 7fd15f6
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ composer.phar

composer.lock
.phplint-cache



38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Install via Composer:

```
composer require studio24/deployer-recipes --dev
```
```

Install all Studio 24 Deployer tasks by adding this to your `deploy.php`:

Expand All @@ -20,6 +20,34 @@ require 'vendor/studio24/deployer-recipes/all.php';

To only install individual tasks, see the docs for each task.

### Running Deployer

Please note this project uses a local Deployer installation (via Composer) not a global version of Deployer. This is so we
can make use of other Composer packages in deployment tasks reliably.

To run deployments please use:

```
vendor/bin/dep deploy environment
```

rather than:

```
dep deploy environment
```

If you wish, you can [install vendor binaries to another location](https://getcomposer.org/doc/articles/vendor-binaries.md#can-vendor-binaries-be-installed-somewhere-other-than-vendor-bin-)
by editing your project composer.json file. For example, to install to `bin` so you can run deployer via `bin/dep`:

```json
{
"config": {
"bin-dir": "bin"
}
}
```

## Tasks

The following tasks are available:
Expand All @@ -36,14 +64,16 @@ The following tasks are available:
## Full deploy example

A sample of a full deploy file can be found in `examples/deploy.php`
**NOTE:** If you do not need to run a composer install remove the lines below (118 & 119)

To use this file in a project copy it to your project root and update the config variables.

Please edit `deploy.php` depending on your needs. For example if you don't need to run Composer during deployment remove the line:

```
// Composer install
'deploy:vendors,',
```

To use these file in a project copy it to your project root and update the config variables.

## Requirements

* PHP 7.2+
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
],
"require": {
"php": ">=7.2",
"ext-json": "*"
"ext-json": "*",
"symfony/http-client": "^5.2"
},
"require-dev": {
"overtrue/phplint": "^2.3",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5",
"deployer/deployer": "^6.8"
},
"scripts": {
"lint": "phplint ./",
Expand Down
9 changes: 3 additions & 6 deletions docs/check-branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ require 'vendor/studio24/deployer-recipes/src/check-branch.php';
```

## Configuration
Requires the main branch to be set in deploy.php
```
$main_branch = 'master'; or $main_branch = 'main';
```
No configuration required

## Tasks

Expand All @@ -40,7 +37,7 @@ task('deploy', [

Default protection result
```
dep deploy production --branch=hotfix
vendor/bin/dep deploy production --branch=hotfix
```
will result in the exception
```
Expand All @@ -49,7 +46,7 @@ You cannot deploy hotfix to production
```
To force a non main branch to be deployed use
```
dep deploy production --branch=hotfix --force=true
vendor/bin/dep deploy production --branch=hotfix --force=true
```
which will result in
```
Expand Down
10 changes: 7 additions & 3 deletions docs/show-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ No configuration is required.

Run on any environment to display current deploy information

```dep studio24:show-summary environment```
```
vendor/bin/dep studio24:show-summary environment
```

eg:
```dep studio24:show-summary production```
```
vendor/bin/dep studio24:show-summary production
```

This returns a response of

```angular2html
```
Build Summary:
Currently deployed branch on the production environment is master, deployed on Wednesday, March 03 at 04:54PM by Alan Isaacson ([email protected]).
Expand Down
6 changes: 3 additions & 3 deletions docs/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ Sync from any environment configured to your local development environment. By d
fisrt sync path setup in config.

```
dep sync <environment>
vendor/bin/dep sync <environment>
```

E.g.

```
dep sync staging
vendor/bin/dep sync staging
```

To sync different file paths, you can use the `--files` option. For example, to sync down a logfile setup the config
Expand All @@ -96,7 +96,7 @@ set('sync', $sync);
And the sync command would be:

```
dep sync staging log
vendor/bin/dep sync staging log
```


Expand Down
4 changes: 2 additions & 2 deletions examples/deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
's24:display-disk-space',

// Request confirmation to continue (default N)
's24:confirm',
's24:confirm-continue',

// Deploy site
'deploy:prepare',
Expand All @@ -116,7 +116,7 @@
'deploy:update_code',

// Composer install
'deploy:vendors,',
'deploy:vendors',

'deploy:shared',
'deploy:writable',
Expand Down
2 changes: 2 additions & 0 deletions src/display-disk-space.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Deployer;

use Deployer\Task\Context;

desc('Display server disk usage prior to deployment');
task('s24:display-disk-space', function () {
$target = Context::get()->getHost();
Expand Down
28 changes: 20 additions & 8 deletions src/show-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

namespace Deployer;

use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;

desc('Display the build_summary from the webserver');
task('s24:show-summary', function () {

// Check for build file
$client = HttpClient::create();
$buildUrl = get('url') . '/_build_summary.json';
$response = $client->request('GET', $buildUrl);
$statusCode = $response->getStatusCode();

if ($statusCode != '200') {
writeLn(sprintf('<comment>The build_summary.json file is unavailable with the status code</> <info>%s</> ', $statusCode));
return;
}

// Get build file
$file = get('url') . '/_build_summary.json';
$file = file_get_contents($file);
if ($file === null) {
writeLn(sprintf('<comment>Cannot load build summary from URL %s</comment>', $file));
try {
$json = $response->toArray();
} catch (DecodingExceptionInterface $e) {
writeLn(sprintf('<comment>Cannot decode JSON build summary from URL %s, error: %s</comment>', $buildUrl, $e->getMessage()));
return;
}
$json = json_decode($file, true);
if ($json === null) {
writeLn(sprintf('<comment>Cannot decode JSON build summary from URL %s, error: %s</comment>', $file, json_last_error_msg()));
if (empty($json)) {
writeLn(sprintf('<comment>No data found in JSON build summary from URL %s</comment>', $buildUrl));
return;
}

Expand Down

0 comments on commit 7fd15f6

Please sign in to comment.