├── LICENSE ├── README.md ├── composer.json └── magento.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Webgriffe® 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Magento 1.x Deployer Recipe 2 | =========================== 3 | 4 | Deployer recipe for Magento project. It requires Deployer greater or equal to version `5.0`. 5 | 6 | Install 7 | ------- 8 | 9 | Install it using Composer: 10 | 11 | $ composer require --dev webgriffe/deployer-magento 12 | 13 | Usage 14 | ----- 15 | 16 | Require the recipe in your `deploy.php`: 17 | 18 | ```php 19 | 20 | namespace Deployer; 21 | 22 | require __DIR__ . '/vendor/webgriffe/deployer-magento/magento.php'; 23 | 24 | // Usual Deployer configuration here 25 | 26 | // Set magento root directory inside release path (leave blank if Magento is in the root of the release path) 27 | set('magento_root', 'magento'); 28 | // Set other Magento's specific config (see below) 29 | ``` 30 | 31 | Caution 32 | ------- 33 | Please, refer to the `magento.php` file to check the provided shared directories and files. Make sure that these don't conflict with your project. Even when you upgrade `webgriffe/deployer-magento` please check the shared stuff. We do not treat a different shared configuration as a BC break. 34 | 35 | Configuration 36 | ------------- 37 | 38 | This recipe provides the following Deployer parameters that you can set in your local `deploy.php` file: 39 | 40 | * `media_pull_exclude_dirs`, default value `['css', 'css_secure', 'js']`: allows to set a list of subdirectories of the `media` folder that will be excluded from the `magento:media-pull` task. 41 | * `setup-run-timeout`, default value `300`: allows to set the timeout for the `magento:setup-run` task which in some cases takes more time. 42 | * `db_pull_strip_tables`, default value `['@stripped']`: allows to set an array of table names or groups which data will be stripped from the database dump generated with the `magento:db-pull` task. Table names or groups syntax follow the same rules of the `--strip` option of the `n98-magerun.phar db:dump`, see the [magerun](https://github.com/netz98/n98-magerun) documentation for more information. 43 | * `magerun_remote`, default value `n98-magerun.phar`: allows to set the path of the magerun bin on the remote stage. 44 | * `magerun_local`, default value `getenv('DEPLOYER_MAGERUN_LOCAL') ?: 'n98-magerun.phar'`: allows to set the path of the local magerun bin. As you can see the default value is taken from the `DEPLOYER_MAGERUN_LOCAL ` environment variable if it's set, otherwise `n98-magerun.phar` will be used. 45 | 46 | 47 | Magento useful tasks 48 | -------------------- 49 | 50 | This recipe provides Magento useful tasks: 51 | 52 | * `magento:db-dump`: creates a gzipped database dump on the remote stage in the deploy user's home directory 53 | * `magento:db-pull`: pulls database from the remote stage to local environment 54 | * `magento:media-pull`: pulls Magento media from the remote stage to local environment 55 | * `magento:set-copy-deploy-strategy`: sets the "copy" deploy strategy for [Magento Composer Installer](https://github.com/Cotya/magento-composer-installer) into the composer.json file. 56 | 57 | License 58 | ------- 59 | 60 | This library is under the MIT license. See the complete license in the LICENSE file. 61 | 62 | Credits 63 | ------- 64 | 65 | Developed by [Webgriffe®](http://www.webgriffe.com/). Please, report to us any bug or suggestion by GitHub issues. 66 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webgriffe/deployer-magento", 3 | "description": "Deployer recipe for Magento project", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Webgriffe Srl", 9 | "email": "support@webgriffe.com" 10 | } 11 | ], 12 | "require": {} 13 | } 14 | -------------------------------------------------------------------------------- /magento.php: -------------------------------------------------------------------------------- 1 | = 5.0) 8 | 9 | require 'recipe/common.php'; 10 | 11 | set('magento_root_path', function () { 12 | $magentoRoot = get('magento_root'); 13 | return empty($magentoRoot) ? '' : (rtrim($magentoRoot, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); 14 | }); 15 | 16 | // Magento shared dirs 17 | set( 18 | 'shared_dirs', 19 | ['{{magento_root_path}}' . 'var', '{{magento_root_path}}' . 'media', '{{magento_root_path}}' . 'sitemaps'] 20 | ); 21 | 22 | // Magento shared files 23 | set('shared_files', ['{{magento_root_path}}' . 'app/etc/local.xml', '{{magento_root_path}}' . '.htaccess']); 24 | 25 | // Magento writable dirs 26 | set( 27 | 'writable_dirs', 28 | ['{{magento_root_path}}' . 'var', '{{magento_root_path}}' . 'media', '{{magento_root_path}}' . 'sitemaps'] 29 | ); 30 | 31 | // Magento media pull exclude dirs (paths must be relative to the media dir) 32 | set('media_pull_exclude_dirs', ['css', 'css_secure', 'js', 'catalog/product/cache']); 33 | 34 | // Magento clear paths 35 | set( 36 | 'clear_paths', 37 | [ 38 | '{{magento_root_path}}' . 'LICENSE.html', 39 | '{{magento_root_path}}' . 'LICENSE.txt', 40 | '{{magento_root_path}}' . 'LICENSE_AFL.txt', 41 | '{{magento_root_path}}' . 'RELEASE_NOTES.txt', 42 | '{{magento_root_path}}' . 'downloader', 43 | ] 44 | ); 45 | 46 | // Setup run timeout 47 | set('setup-run-timeout', 300); 48 | 49 | // DB pull strip tables 50 | set('db_pull_strip_tables', ['@stripped']); 51 | 52 | // Local/remote magerun path 53 | set('magerun_remote', 'n98-magerun.phar'); 54 | set('magerun_local', getenv('DEPLOYER_MAGERUN_LOCAL') ?: 'n98-magerun.phar'); 55 | 56 | set('local_project_path', function () { 57 | return runLocally('pwd'); 58 | }); 59 | 60 | // Tasks 61 | desc('Run the Magento setup scripts'); 62 | task('magento:setup-run', function () { 63 | if (test('[ -f {{release_path}}/{{magento_root_path}}app/etc/local.xml ]')) { 64 | $installed = run('cat {{release_path}}/{{magento_root_path}}app/etc/local.xml | grep ""; true'); 65 | if ($installed) { 66 | run( 67 | 'cd {{release_path}}/{{magento_root_path}} && {{magerun_remote}} sys:setup:run --no-implicit-cache-flush', 68 | ['timeout' => get('setup-run-timeout')] 69 | ); 70 | } 71 | } 72 | }); 73 | 74 | desc('Clear Magento cache'); 75 | task('magento:clear-cache', function () { 76 | if (test('[ -f {{release_path}}/{{magento_root_path}}app/etc/local.xml ]')) { 77 | $installed = run('cat {{release_path}}/{{magento_root_path}}app/etc/local.xml | grep ""; true'); 78 | if ($installed) { 79 | run('cd {{release_path}}/{{magento_root_path}} && {{magerun_remote}} cache:clean'); 80 | } 81 | } 82 | }); 83 | 84 | desc('Create Magento database dump'); 85 | task('magento:db-dump', function () { 86 | run('cd {{current_path}}/{{magento_root_path}} && {{magerun_remote}} db:dump -n -c gz ~'); 87 | }); 88 | 89 | option( 90 | 'db-pull-timeout', 91 | null, 92 | InputOption::VALUE_OPTIONAL, 93 | 'Timeout for db:dump and db:import executions in db-pull task in seconds (default is 300s)' 94 | ); 95 | desc('Pull Magento database to local'); 96 | task('magento:db-pull', function () { 97 | $timeout = 300; 98 | if (input()->hasOption('db-pull-timeout')) { 99 | $timeout = input()->getOption('db-pull-timeout'); 100 | } 101 | 102 | $fileName = uniqid('dbdump_'); 103 | $stripTables = implode(' ', get('db_pull_strip_tables')); 104 | $remoteDump = "/tmp/{$fileName}.sql.gz"; 105 | run( 106 | 'cd {{current_path}}/{{magento_root_path}} && ' . 107 | '{{magerun_remote}} db:dump -n --strip="'. $stripTables .'" -c gz ' . $remoteDump, 108 | ['timeout' => $timeout] 109 | ); 110 | $dumpName = tempnam(sys_get_temp_dir(), 'deployer_'); 111 | $localDumpGz = $dumpName . '.sql.gz'; 112 | $localDumpSql = $dumpName . '.sql'; 113 | download($remoteDump, $localDumpGz); 114 | run('rm ' . $remoteDump); 115 | runLocally('gunzip ' . $localDumpGz); 116 | runLocally( 117 | 'cd {{local_project_path}}/{{magento_root_path}} && {{magerun_local}} db:import -n --drop-tables --optimize ' . $localDumpSql, 118 | ['timeout' => $timeout] 119 | ); 120 | 121 | runLocally('cd {{local_project_path}}/{{magento_root_path}} && {{magerun_local}} cache:disable'); 122 | runLocally('rm ' . $localDumpSql); 123 | }); 124 | 125 | option( 126 | 'media-pull-timeout', 127 | null, 128 | InputOption::VALUE_OPTIONAL, 129 | 'Timeout for media-pull task in seconds (default is 300s)' 130 | ); 131 | desc('Pull Magento media to local'); 132 | task('magento:media-pull', function () { 133 | $remotePath = '{{current_path}}/{{magento_root_path}}/media/'; 134 | $localPath = '{{local_project_path}}/{{magento_root_path}}/media/'; 135 | 136 | $excludeDirs = array_map(function($dir) { 137 | return '--exclude '.$dir; 138 | }, get('media_pull_exclude_dirs')); 139 | 140 | $timeout = 300; 141 | if (input()->hasOption('media-pull-timeout')) { 142 | $timeout = input()->getOption('media-pull-timeout'); 143 | } 144 | $config = [ 145 | 'options' => $excludeDirs, 146 | 'timeout' => $timeout 147 | ]; 148 | 149 | 150 | download($remotePath, $localPath, $config); 151 | }); 152 | 153 | desc('Set "copy" as Magento deploy strategy'); 154 | task('magento:set-copy-deploy-strategy', function(){ 155 | run('cd {{release_path}} && {{bin/composer}} config extra.magento-deploystrategy copy'); 156 | run('cd {{release_path}} && {{bin/composer}} config extra.magento-force true'); 157 | }); 158 | 159 | after('deploy:shared', 'magento:set-copy-deploy-strategy'); 160 | before('deploy:symlink', 'magento:setup-run'); 161 | after('deploy:symlink', 'magento:clear-cache'); 162 | --------------------------------------------------------------------------------