From 24ba6dfb96c49df1607ee05fc7646330e861ce19 Mon Sep 17 00:00:00 2001 From: Alan Isaacson Date: Wed, 17 Mar 2021 17:48:03 +0000 Subject: [PATCH 1/7] Minor updates and add local deployer Added local deployer to avoid package version errors. Update the documentation as needed. Adjust show-summary method for reading the build information --- .gitignore | 4 ++++ README.md | 11 +++++++++-- composer.json | 6 ++++-- docs/check-branch.md | 9 +++------ docs/show-summary.md | 10 +++++++--- docs/sync.md | 6 +++--- examples/deploy.php | 2 +- src/display-disk-space.php | 2 ++ src/show-summary.php | 23 ++++++++++++++++++----- 9 files changed, 51 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 177fb86..59b33b9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ composer.phar composer.lock .phplint-cache + +.idea + + diff --git a/README.md b/README.md index 45eec87..7a4507d 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,15 @@ Install via Composer: ``` composer require studio24/deployer-recipes --dev +``` +This project will use a local deployer installation as part of the composer install/require process. To run deployments please use +``` +vendor/bin/dep deploy environment +``` +rather than +``` +dep deploy environment ``` - Install all Studio 24 Deployer tasks by adding this to your `deploy.php`: ```php @@ -36,7 +43,7 @@ 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) +**NOTE:** If you do not need to run a composer install during deployemnt remove the lines below (118 & 119) ``` // Composer install 'deploy:vendors,', diff --git a/composer.json b/composer.json index 03584cd..9678360 100644 --- a/composer.json +++ b/composer.json @@ -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 ./", diff --git a/docs/check-branch.md b/docs/check-branch.md index 7936f3f..edfdde8 100644 --- a/docs/check-branch.md +++ b/docs/check-branch.md @@ -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 @@ -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 ``` @@ -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 ``` diff --git a/docs/show-summary.md b/docs/show-summary.md index 24c0478..1869c89 100644 --- a/docs/show-summary.md +++ b/docs/show-summary.md @@ -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 (alan@studio24.net). diff --git a/docs/sync.md b/docs/sync.md index a7966ce..85c98b1 100644 --- a/docs/sync.md +++ b/docs/sync.md @@ -69,13 +69,13 @@ Sync from any environment configured to your local development environment. By d fisrt sync path setup in config. ``` -dep sync +vendor/bin/dep sync ``` 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 @@ -96,7 +96,7 @@ set('sync', $sync); And the sync command would be: ``` -dep sync staging log +vendor/bin/dep sync staging log ``` diff --git a/examples/deploy.php b/examples/deploy.php index c175023..b55a319 100644 --- a/examples/deploy.php +++ b/examples/deploy.php @@ -107,7 +107,7 @@ 's24:display-disk-space', // Request confirmation to continue (default N) - 's24:confirm', + 's24:confirm-continue', // Deploy site 'deploy:prepare', diff --git a/src/display-disk-space.php b/src/display-disk-space.php index 569510c..eddbe48 100644 --- a/src/display-disk-space.php +++ b/src/display-disk-space.php @@ -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(); diff --git a/src/show-summary.php b/src/show-summary.php index 592c654..fcae29c 100644 --- a/src/show-summary.php +++ b/src/show-summary.php @@ -2,14 +2,27 @@ namespace Deployer; +use Symfony\Component\HttpClient\HttpClient; + desc('Display the build_summary from the webserver'); task('s24:show-summary', function () { - + // Check for build file + $client = HttpClient::create(); + $response = $client->request('GET', get('url') . '/_build_summary.json'); + + $statusCode = $response->getStatusCode(); + + if ($statusCode != '200') { + writeLn(sprintf('Unable to load the file returns a %s, ', $statusCode)); + return; + } + + // Get build file - $file = get('url') . '/_build_summary.json'; - $file = file_get_contents($file); - if ($file === null) { - writeLn(sprintf('Cannot load build summary from URL %s', $file)); + $file = $response->getContent(); + + if (empty($file)) { + writeLn(sprintf('There is no content in build summary from URL %s', $file)); return; } $json = json_decode($file, true); From 499b54e7557eaa0298c050951776a48783befa5f Mon Sep 17 00:00:00 2001 From: Simon R Jones Date: Thu, 18 Mar 2021 11:37:25 +0000 Subject: [PATCH 2/7] Expand notes on running deployer --- README.md | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7a4507d..4d7b310 100644 --- a/README.md +++ b/README.md @@ -11,21 +11,42 @@ Install via Composer: ``` composer require studio24/deployer-recipes --dev ``` -This project will use a local deployer installation as part of the composer install/require process. To run deployments please use + +Install all Studio 24 Deployer tasks by adding this to your `deploy.php`: + +```php +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 + +rather than: + ``` dep deploy environment ``` -Install all Studio 24 Deployer tasks by adding this to your `deploy.php`: -```php -require 'vendor/studio24/deployer-recipes/all.php'; -``` +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`: -To only install individual tasks, see the docs for each task. +```json +{ + "config": { + "bin-dir": "bin" + } +} +``` ## Tasks @@ -43,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 during deployemnt 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+ From 1557aa5a5fadf209bd8213f043cd9d7c1ea83315 Mon Sep 17 00:00:00 2001 From: Alan Isaacson Date: Thu, 18 Mar 2021 12:04:16 +0000 Subject: [PATCH 3/7] remove rogue , --- examples/deploy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/deploy.php b/examples/deploy.php index b55a319..11f0865 100644 --- a/examples/deploy.php +++ b/examples/deploy.php @@ -116,7 +116,7 @@ 'deploy:update_code', // Composer install - 'deploy:vendors,', + 'deploy:vendors', 'deploy:shared', 'deploy:writable', From 8fd4e7240179151b24956a5be9962dd108008cc4 Mon Sep 17 00:00:00 2001 From: Alan Isaacson Date: Fri, 19 Mar 2021 10:03:54 +0000 Subject: [PATCH 4/7] Remove .idea from gitignore amd tidy code check in show summary --- .gitignore | 1 - src/show-summary.php | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 59b33b9..6b96075 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,5 @@ composer.phar composer.lock .phplint-cache -.idea diff --git a/src/show-summary.php b/src/show-summary.php index fcae29c..02add77 100644 --- a/src/show-summary.php +++ b/src/show-summary.php @@ -21,10 +21,8 @@ // Get build file $file = $response->getContent(); - if (empty($file)) { - writeLn(sprintf('There is no content in build summary from URL %s', $file)); - return; - } + $json = $response->toArray(); + $json = json_decode($file, true); if ($json === null) { writeLn(sprintf('Cannot decode JSON build summary from URL %s, error: %s', $file, json_last_error_msg())); From d94f5ad7734c8074914bad0820138593c5b6782e Mon Sep 17 00:00:00 2001 From: Alan Isaacson Date: Fri, 19 Mar 2021 10:11:40 +0000 Subject: [PATCH 5/7] Updated status code error message --- src/show-summary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/show-summary.php b/src/show-summary.php index 02add77..a5e3919 100644 --- a/src/show-summary.php +++ b/src/show-summary.php @@ -13,7 +13,7 @@ $statusCode = $response->getStatusCode(); if ($statusCode != '200') { - writeLn(sprintf('Unable to load the file returns a %s, ', $statusCode)); + writeLn(sprintf('The build_summary.json file is unavailable with the status code %s ', $statusCode)); return; } From 7cf18ee3848d15062756224186337ed7be77fa86 Mon Sep 17 00:00:00 2001 From: Simon R Jones Date: Fri, 19 Mar 2021 10:18:57 +0000 Subject: [PATCH 6/7] Update error checking on get JSON file --- src/show-summary.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/show-summary.php b/src/show-summary.php index a5e3919..3ad2672 100644 --- a/src/show-summary.php +++ b/src/show-summary.php @@ -3,13 +3,14 @@ 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(); - $response = $client->request('GET', get('url') . '/_build_summary.json'); - + $buildUrl = get('url') . '/_build_summary.json'; + $response = $client->request('GET', $buildUrl); $statusCode = $response->getStatusCode(); if ($statusCode != '200') { @@ -17,15 +18,16 @@ return; } - // Get build file - $file = $response->getContent(); - - $json = $response->toArray(); + try { + $json = $response->toArray(); - $json = json_decode($file, true); - if ($json === null) { - writeLn(sprintf('Cannot decode JSON build summary from URL %s, error: %s', $file, json_last_error_msg())); + } catch (DecodingExceptionInterface $e) { + writeLn(sprintf('Cannot decode JSON build summary from URL %s, error: %s', $buildUrl, $e->getMessage())); + return; + } + if (empty($json)) { + writeLn(sprintf('No data found in JSON build summary from URL %s', $buildUrl)); return; } From e4c342508739c0e194ed71986329b7d8967e44bc Mon Sep 17 00:00:00 2001 From: Simon R Jones Date: Fri, 19 Mar 2021 10:20:41 +0000 Subject: [PATCH 7/7] code standards --- src/show-summary.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/show-summary.php b/src/show-summary.php index 3ad2672..c34ccac 100644 --- a/src/show-summary.php +++ b/src/show-summary.php @@ -21,7 +21,6 @@ // Get build file try { $json = $response->toArray(); - } catch (DecodingExceptionInterface $e) { writeLn(sprintf('Cannot decode JSON build summary from URL %s, error: %s', $buildUrl, $e->getMessage())); return;