├── .ddev └── config.yaml ├── .gitignore ├── CHANGELOG.rst ├── LICENSE.txt ├── README.rst ├── UPGRADE.rst ├── composer.json ├── deployer ├── assets │ └── task │ │ └── assets_build.php ├── db │ └── task │ │ └── db_import_post_command_wp_domains.php ├── deploy │ └── task │ │ └── deploy.php ├── file │ └── task │ │ └── file_upload.php └── set.php └── src ├── Drivers ├── EnvDriver.php └── WordpressDriver.php └── Loader.php /.ddev/config.yaml: -------------------------------------------------------------------------------- 1 | name: deployer-extended-wordpress-composer 2 | type: php 3 | docroot: "" 4 | php_version: "7.3" 5 | webserver_type: nginx-fpm 6 | router_http_port: "80" 7 | router_https_port: "443" 8 | xdebug_enabled: false 9 | additional_hostnames: [] 10 | additional_fqdns: [] 11 | mariadb_version: "10.2" 12 | mysql_version: "" 13 | provider: default 14 | use_dns_when_possible: true 15 | composer_version: "" 16 | 17 | 18 | # This config.yaml was created with ddev version v1.16.5 19 | # webimage: drud/ddev-webserver:v1.16.3 20 | # dbimage: drud/ddev-dbserver-mariadb-10.2:v1.16.0 21 | # dbaimage: phpmyadmin:5 22 | # However we do not recommend explicitly wiring these images into the 23 | # config.yaml as they may break future versions of ddev. 24 | # You can update this config.yaml using 'ddev config'. 25 | 26 | # Key features of ddev's config.yaml: 27 | 28 | # name: # Name of the project, automatically provides 29 | # http://projectname.ddev.site and https://projectname.ddev.site 30 | 31 | # type: # drupal6/7/8, backdrop, typo3, wordpress, php 32 | 33 | # docroot: # Relative path to the directory containing index.php. 34 | 35 | # php_version: "7.3" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4" "8.0" 36 | 37 | # You can explicitly specify the webimage, dbimage, dbaimage lines but this 38 | # is not recommended, as the images are often closely tied to ddev's' behavior, 39 | # so this can break upgrades. 40 | 41 | # webimage: # nginx/php docker image. 42 | # dbimage: # mariadb docker image. 43 | # dbaimage: 44 | 45 | # mariadb_version and mysql_version 46 | # ddev can use many versions of mariadb and mysql 47 | # However these directives are mutually exclusive 48 | # mariadb_version: 10.2 49 | # mysql_version: 8.0 50 | 51 | # router_http_port: # Port to be used for http (defaults to port 80) 52 | # router_https_port: # Port for https (defaults to 443) 53 | 54 | # xdebug_enabled: false # Set to true to enable xdebug and "ddev start" or "ddev restart" 55 | # Note that for most people the commands 56 | # "ddev xdebug" to enable xdebug and "ddev xdebug off" to disable it work better, 57 | # as leaving xdebug enabled all the time is a big performance hit. 58 | 59 | # webserver_type: nginx-fpm # or apache-fpm 60 | 61 | # timezone: Europe/Berlin 62 | # This is the timezone used in the containers and by PHP; 63 | # it can be set to any valid timezone, 64 | # see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones 65 | # For example Europe/Dublin or MST7MDT 66 | 67 | # composer_version: "2" 68 | # if composer_version:"" it will use the current ddev default composer release. 69 | # It can also be set to "1", to get most recent composer v1 70 | # or "2" for most recent composer v2. 71 | # It can be set to any existing specific composer version. 72 | # After first project 'ddev start' this will not be updated until it changes 73 | 74 | # additional_hostnames: 75 | # - somename 76 | # - someothername 77 | # would provide http and https URLs for "somename.ddev.site" 78 | # and "someothername.ddev.site". 79 | 80 | # additional_fqdns: 81 | # - example.com 82 | # - sub1.example.com 83 | # would provide http and https URLs for "example.com" and "sub1.example.com" 84 | # Please take care with this because it can cause great confusion. 85 | 86 | # upload_dir: custom/upload/dir 87 | # would set the destination path for ddev import-files to custom/upload/dir. 88 | 89 | # working_dir: 90 | # web: /var/www/html 91 | # db: /home 92 | # would set the default working directory for the web and db services. 93 | # These values specify the destination directory for ddev ssh and the 94 | # directory in which commands passed into ddev exec are run. 95 | 96 | # omit_containers: [db, dba, ddev-ssh-agent] 97 | # Currently only these containers are supported. Some containers can also be 98 | # omitted globally in the ~/.ddev/global_config.yaml. Note that if you omit 99 | # the "db" container, several standard features of ddev that access the 100 | # database container will be unusable. 101 | 102 | # nfs_mount_enabled: false 103 | # Great performance improvement but requires host configuration first. 104 | # See https://ddev.readthedocs.io/en/stable/users/performance/#using-nfs-to-mount-the-project-into-the-container 105 | 106 | # host_https_port: "59002" 107 | # The host port binding for https can be explicitly specified. It is 108 | # dynamic unless otherwise specified. 109 | # This is not used by most people, most people use the *router* instead 110 | # of the localhost port. 111 | 112 | # host_webserver_port: "59001" 113 | # The host port binding for the ddev-webserver can be explicitly specified. It is 114 | # dynamic unless otherwise specified. 115 | # This is not used by most people, most people use the *router* instead 116 | # of the localhost port. 117 | 118 | # host_db_port: "59002" 119 | # The host port binding for the ddev-dbserver can be explicitly specified. It is dynamic 120 | # unless explicitly specified. 121 | 122 | # phpmyadmin_port: "8036" 123 | # phpmyadmin_https_port: "8037" 124 | # The PHPMyAdmin ports can be changed from the default 8036 and 8037 125 | 126 | # mailhog_port: "8025" 127 | # mailhog_https_port: "8026" 128 | # The MailHog ports can be changed from the default 8025 and 8026 129 | 130 | # webimage_extra_packages: [php7.3-tidy, php-bcmath] 131 | # Extra Debian packages that are needed in the webimage can be added here 132 | 133 | # dbimage_extra_packages: [telnet,netcat] 134 | # Extra Debian packages that are needed in the dbimage can be added here 135 | 136 | # use_dns_when_possible: true 137 | # If the host has internet access and the domain configured can 138 | # successfully be looked up, DNS will be used for hostname resolution 139 | # instead of editing /etc/hosts 140 | # Defaults to true 141 | 142 | # project_tld: ddev.site 143 | # The top-level domain used for project URLs 144 | # The default "ddev.site" allows DNS lookup via a wildcard 145 | # If you prefer you can change this to "ddev.local" to preserve 146 | # pre-v1.9 behavior. 147 | 148 | # ngrok_args: --subdomain mysite --auth username:pass 149 | # Provide extra flags to the "ngrok http" command, see 150 | # https://ngrok.com/docs#http or run "ngrok http -h" 151 | 152 | # disable_settings_management: false 153 | # If true, ddev will not create CMS-specific settings files like 154 | # Drupal's settings.php/settings.ddev.php or TYPO3's AdditionalSettings.php 155 | # In this case the user must provide all such settings. 156 | 157 | # no_project_mount: false 158 | # (Experimental) If true, ddev will not mount the project into the web container; 159 | # the user is responsible for mounting it manually or via a script. 160 | # This is to enable experimentation with alternate file mounting strategies. 161 | # For advanced users only! 162 | 163 | # provider: default # Currently either "default" or "pantheon" 164 | # 165 | # Many ddev commands can be extended to run tasks before or after the 166 | # ddev command is executed, for example "post-start", "post-import-db", 167 | # "pre-composer", "post-composer" 168 | # See https://ddev.readthedocs.io/en/stable/users/extending-commands/ for more 169 | # information on the commands that can be extended and the tasks you can define 170 | # for them. Example: 171 | #hooks: 172 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /composer.lock -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | 2 | Changelog 3 | --------- 4 | 5 | 9.0.0 6 | ~~~~~ 7 | 8 | 1) [BREAKING] Update dependencies to deployer-extended, deployer-extended-media, deployer-extended-database, 9 | deployer-loader, symfony/dotenv. 10 | 11 | 8.0.1 12 | ~~~~~ 13 | 14 | 1) [BUGFIX] Fix dependencies mistake. 15 | 16 | 8.0.0 17 | ~~~~~ 18 | 19 | 1) [BREAKING] Upgrade for Deployer 7. 20 | 2) [BREAKING] Remove ``deploy:extend_log`` task in favour of similar task build in in Deployer 7. 21 | 3) [BREAKING] Variable ``vhost_document_root`` has been removed because it was used in automatic vhost creation 22 | and this is no longer in `deployer-extended` package. 23 | 24 | 7.0.0 25 | ~~~~~ 26 | 27 | 1) [BREAKING] Update sourcebroker/deployer-extended-* stack. 28 | 2) [TASK] Add ddev. 29 | 3) [BREAKING] Add filename to argument of methods getDatabaseConfig() and getInstanceName() in EnvDriver class, refactor EnvDriver class. 30 | 4) [BUGFIX] Change build command from ``npm build`` to ``npm run build`` 31 | 32 | 6.0.0 33 | ~~~~~ 34 | 35 | 1) [BREAKING] Change ``set('instance_local_name', 'development'); set('instance_live_name', 'production');`` to ``set('instance_local_name', 'dev'); set('instance_live_name', 'live');`` 36 | 2) [BREAKING] Change shared files to ``set('shared_files', ['config/.env.local','web/.htaccess'])``; 37 | 3) [BREAKING] Move ``.env`` file to ``config/`` and use Symfony/Dotenv loadEnv() to have support for instance based env read. 38 | 4) [BREAKING] Change default build command from ``npm ci && gulp build`` to ``npm ci && npm build`` 39 | 5) [BREAKING] Add ``web/.htaccess`` to files which are downloaded as media. 40 | 41 | 5.0.0 42 | ~~~~~ 43 | 44 | 1) [BREAKING] Increase ``sourcebroker/deployer-extended``. 45 | 2) [BREAKING] Increase ``deployer-extended-database``. 46 | 3) [TASK] Extend dependency of symfony/dotenv to 5.0 47 | 4) [TASK] Increase ``deployer/dist`` version. 48 | 5) [TASK] Add '.ddev' to 'clear_paths'. 49 | 50 | 4.0.0 51 | ~~~~~ 52 | 53 | 1) [BUGFIX] Change Dotenv dependency to Symfony\Dotenv (possible breaking change) 54 | 2) [TASK][BRAKING] Update to deployer 6 and compatible deployer-extended- stack. 55 | 3) [TASK] Allow to override assets build command. 56 | 4) [BUGFIX] Fix wrongly calculated $absolutePathWithConfig in driver. 57 | 5) [TASK] Add deploy:unlock after fail. 58 | 6) [BUGFIX] Add deployer-instance to loader. 59 | 7) [BUGFIX] Deployer 6.x compatibility - dumpcode argument missing in db:import:post_command:wp_domains 60 | 8) [TASK] Increase default timeout to 900s. 61 | 9) [TASK][BREAKING] Change deploy tasks to use more tasks from deployer-extended. 62 | 10) [TASK] Deployer-instance changes. 63 | 11) [TASK] Rename task names to not use ":" for Windows WSL compatibility. 64 | 12) [TASK] Increase sourcebroker/deployer-extended to 12.0.0 65 | 13) [BUGFIX] Fix possible errors with wrong php version on host in db:import:post_command:wp_domains 66 | 14) [TASK] set('instance_local_name', 'development'), set('instance_live_name', 'production'); 67 | 15) [TASK] Disallow pushing, coping, pulling media and database to top instance. 68 | 16) [TASK][BREAKING] By setting ``set('branch_detect_to_deploy', false);`` change the default unsafe bahaviour 69 | of deployer to deploy the currently checked out branch. The branch must be set explicitly in host configuration. 70 | 17) [TASK] Update deployer-extended-media, deployer-extended-database, deployer-instance, deployer-extended. 71 | 72 | 3.0.0 73 | ~~~~~ 74 | 75 | 1) [BUGFIX] Change the way the wp-cli binary is detected. It must be now present in vendor/bin. 76 | 77 | 2.0.0 78 | ~~~~~ 79 | 80 | 1) [TASK][!!!BREAKING] Change th logic for finding "wp-cli" executable. 81 | 82 | 1.0.1 83 | ~~~~~ 84 | 85 | 1) [BUGFIX] file_upload should be an array 86 | 87 | 1.0.0 88 | ~~~~~ 89 | 90 | 1) First stable release. 91 | 92 | 0.0.1 93 | ~~~~~ 94 | 95 | 1) Init version. 96 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2019 SourceBroker Team 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | deployer-extended-wordpress-composer 2 | ==================================== 3 | 4 | .. contents:: :local: 5 | 6 | What does it do? 7 | ---------------- 8 | 9 | This package provides deploy task for deploying WordPress with deployer (deployer.org) and additionally a tasks 10 | to synchronize database and media files. 11 | 12 | The deployment is expected to be compatible with capistrano based for https://roots.io/bedrock/ 13 | 14 | Dependencies 15 | ------------ 16 | 17 | This package depends on following packages: 18 | 19 | - | `sourcebroker/deployer-extended`_ 20 | | Package which provides some deployer tasks that can be used for any framework or CMS. 21 | 22 | - | `sourcebroker/deployer-extended-database`_ 23 | | Package which provides some php framework independent deployer tasks to synchronize database. 24 | 25 | - | `sourcebroker/deployer-extended-media`_ 26 | | Package which provides some php framework independent deployer tasks to synchronize media. 27 | 28 | - | `wp-cli/search-replace-command`_ 29 | | Package to change domains after database synchronization. Part of wp-cli/wp-cli utility. 30 | 31 | 32 | Installation 33 | ------------ 34 | 35 | 1) Install package with composer: 36 | :: 37 | 38 | composer require sourcebroker/deployer-extended-wordpress-composer 39 | 40 | 2) If you are using deployer as phar then put following lines in your deploy.php: 41 | :: 42 | 43 | require __DIR__ . '/vendor/autoload.php'; 44 | new \SourceBroker\DeployerExtendedWordpressComposer\Loader(); 45 | 46 | 3) Remove task "deploy" from your deploy.php. Otherwise you will overwrite deploy task defined in 47 | deployer/deploy/task/deploy.php 48 | 49 | 4) Example deploy.php file: 50 | :: 51 | 52 | setHostname('111.111.111.111')->port(22) 63 | ->setRemoteUser('www-data') 64 | ->set('branch', 'master') 65 | ->set('public_urls', ['https://www.example.com/']) 66 | ->set('deploy_path', '/var/www/example.com.live'); 67 | 68 | host('beta') 69 | ->setHostname('111.111.111.111')->port(22) 70 | ->setRemoteUser('www-data') 71 | ->set('branch', 'beta') 72 | ->set('public_urls', ['https://beta.example.com/']) 73 | ->set('deploy_path', '/var/www/example.com.beta'); 74 | 75 | host('dev') 76 | ->set('public_urls', ['https://example-com.local/']) 77 | ->set('deploy_path', getcwd()); 78 | 79 | 80 | Mind the declaration of host('dev'); Its needed for database tasks to declare domain replacements, 81 | and path to store database dumps. 82 | 83 | 84 | Synchronizing database 85 | ---------------------- 86 | 87 | Database synchronization is done with `sourcebroker/deployer-extended-database`. 88 | Example of command for synchronizing database from live to local instance: 89 | :: 90 | 91 | dep db:pull live 92 | 93 | You can also copy database from live to beta instance like: 94 | :: 95 | 96 | dep db:copy live --options=target:beta 97 | 98 | 99 | 100 | Domain replacement 101 | ++++++++++++++++++ 102 | 103 | The "post_command" task "db:import:post_command:wp_domains" will change domains declared in "public_urls". Domain 104 | replacement is done with cli command "search-replace" from `wp-cli/wp-cli`_. 105 | 106 | Please mind to have the same amount of "public_urls" for each of instances because replacement on domains is done for 107 | every pair of corresponding urls. 108 | 109 | Look at following example to give you idea: 110 | :: 111 | 112 | host('live') 113 | ->setHostname('111.111.111.111') 114 | ->setRemoteUser('www-data') 115 | ->set('public_urls', ['https://www.example.com', 'https://sub.example.com']) 116 | ->set('deploy_path', '/var/www/example.com.live'); 117 | 118 | host('beta') 119 | ->setHostname('111.111.111.111') 120 | ->setRemoteUser('www-data') 121 | ->set('public_urls', ['https://beta.example.com', 'https://beta-sub.example.com']) 122 | ->set('deploy_path', '/var/www/example.com.beta'); 123 | 124 | host('dev') 125 | ->set('public_urls', ['https://example-com.dev', 'https://sub-example-com.dev']) 126 | ->set('deploy_path', getcwd()); 127 | 128 | 129 | The if you will do: 130 | :: 131 | 132 | dep db:pull live 133 | 134 | the following commands will be done automatically after database import: 135 | :: 136 | 137 | wp search-replace https://www.example.com https://example-com.dev 138 | wp search-replace https://sub.example.com https://sub-example-com.dev 139 | 140 | 141 | Should I use "deployer-extended-wordpress" or "deployer-extended-wordpress-composer"? 142 | ------------------------------------------------------------------------------------- 143 | 144 | In `sourcebroker/deployer-extended-wordpress`_ the WordPress and third party plugins are installed manually. What you have in git is 145 | basically only your theme. The good thing is that in such case you can update WordPress and plugins automatically. 146 | This can be considered as preferable for low budget WordPress websites. 147 | 148 | In `sourcebroker/deployer-extended-wordpress-composer`_ the WordPress and third party plugins are installed using composer. 149 | This way you gain more control over what is installed but at the same time to install new WordPress or new plugin 150 | version you need first to modify composer.json or do composer update (depending how big upgrade you do). Then you need 151 | to commit composer.json / composer.lock and do deploy which will install new version of WordPress and plugins. 152 | This is additional work that can not be easily automated. One of additional advantages of this solution is that you can 153 | easily cleanup infected WordPress/plugins files as with each deployment all php files are fresh (part from your git 154 | and part from composer repositories). 155 | 156 | 157 | .. _sourcebroker/deployer-extended: https://github.com/sourcebroker/deployer-extended 158 | .. _sourcebroker/deployer-extended-media: https://github.com/sourcebroker/deployer-extended-media 159 | .. _sourcebroker/deployer-extended-database: https://github.com/sourcebroker/deployer-extended-database 160 | .. _sourcebroker/deployer-extended-wordpress: https://github.com/sourcebroker/deployer-extended-wordpress 161 | .. _sourcebroker/deployer-extended-wordpress-composer: https://github.com/sourcebroker/deployer-extended-wordpress-composer 162 | .. _wp-cli/search-replace-command: https://github.com/wp-cli/search-replace-command 163 | .. _wp-cli/wp-cli: https://github.com/wp-cli/wp-cli 164 | -------------------------------------------------------------------------------- /UPGRADE.rst: -------------------------------------------------------------------------------- 1 | 2 | UPGRADE 3 | ------- 4 | 5 | 7 -> 8 6 | ~~~~~~ 7 | 8 | 1) ``set('composer_channel', 2);`` is now default. You can remove it from you config. 9 | 10 | 2) A Deployer 7 specific: in your deploy.php change ``hostname`` to ``setHostname``, change ``user`` to ``setRemoteUser``. 11 | 12 | 3) It is now required to always put stage name. So before version 8.0 you could do ``dep db:export`` to export the 13 | database on current host. Now you need to ``dep db:export local`` to export database when you run it on `local` host. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sourcebroker/deployer-extended-wordpress-composer", 3 | "description": "Composer based WordPress deployment with deployer.org.", 4 | "license": "MIT", 5 | "keywords": [ 6 | "WordPress", 7 | "deployer", 8 | "bedrock", 9 | "composer" 10 | ], 11 | "authors": [ 12 | { 13 | "name": "Krystian Szymukowicz", 14 | "email": "k.szymukowicz@gmail.com" 15 | } 16 | ], 17 | "require": { 18 | "wp-cli/wp-cli": "~2.1", 19 | "wp-cli/search-replace-command": "~2.0", 20 | "symfony/dotenv": "^3.3 || ^4 || ^5 || ^6", 21 | "deployer/deployer": "~7.0", 22 | "sourcebroker/deployer-extended": "^18", 23 | "sourcebroker/deployer-extended-media": "^11", 24 | "sourcebroker/deployer-extended-database": "^16", 25 | "sourcebroker/deployer-loader": "^4" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "SourceBroker\\DeployerExtendedWordpressComposer\\": "src/" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /deployer/assets/task/assets_build.php: -------------------------------------------------------------------------------- 1 | getOption('dumpcode', true); 14 | $dumpsForDumpCode = glob(get('db_storage_path_local') . '/' . '*dumpcode=' . $dumpCode . '*'); 15 | if (empty($dumpsForDumpCode)) { 16 | throw new \Exception('Can not find dumps for dumpcode: ' . $dumpCode . '. [Error code: 1498321476975]'); 17 | } 18 | $sourceInstanceName = null; 19 | preg_match('/\#server=(.*)\#/U', reset($dumpsForDumpCode), $match); 20 | if (isset($match[1])) { 21 | $sourceInstanceName = $match[1]; 22 | } else { 23 | throw new \Exception('Can not determine source instance based on dump filename. [Error code: 1498321481427]'); 24 | } 25 | $currentInstancePublicUrls = get('public_urls'); 26 | $sourceInstancePublicUrls = Configuration::getHost($sourceInstanceName)->get('public_urls'); 27 | if (count($currentInstancePublicUrls) === count($sourceInstancePublicUrls)) { 28 | $publicUrlsPairs = array_combine($sourceInstancePublicUrls, $currentInstancePublicUrls); 29 | foreach ($publicUrlsPairs as $publicUrlOld => $publicUrlNew) { 30 | runLocally('{{local/bin/wp}} search-replace ' . 31 | escapeshellarg(rtrim($publicUrlOld, '/')) . ' ' 32 | . escapeshellarg(rtrim($publicUrlNew, '/')) 33 | ); 34 | } 35 | } else { 36 | throw new \Exception('The amount of public_urls in source and current instance must be the same. [Error code: 1498321606442]'); 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /deployer/deploy/task/deploy.php: -------------------------------------------------------------------------------- 1 | desc('Deploy your WordPress'); 93 | 94 | after('deploy:failed', 'deploy:unlock'); 95 | -------------------------------------------------------------------------------- /deployer/file/task/file_upload.php: -------------------------------------------------------------------------------- 1 | getInstanceName(getcwd() . '/config/.env'); 56 | }); 57 | 58 | // Look on https://github.com/sourcebroker/deployer-extended#buffer-start for docs 59 | set('buffer_config', [ 60 | 'index.php' => [ 61 | 'entrypoint_filename' => 'web/index.php', 62 | ], 63 | ] 64 | ); 65 | 66 | // Look https://github.com/sourcebroker/deployer-extended-media for docs 67 | set('media_allow_push_live', false); 68 | set('media_allow_pull_live', false); 69 | set('media_allow_copy_live', false); 70 | set('media_allow_link_live', false); 71 | set('media', 72 | [ 73 | 'filter' => [ 74 | '+ web/', 75 | '+ web/.htaccess', 76 | '+ web/app/', 77 | '+ web/app/uploads/', 78 | '+ web/app/uploads/**', 79 | '- *' 80 | ] 81 | ]); 82 | 83 | // Look https://github.com/sourcebroker/deployer-extended-database for docs 84 | set('db_allow_push_live', false); 85 | set('db_allow_pull_live', false); 86 | set('db_allow_copy_live', false); 87 | set('db_databases', 88 | [ 89 | 'database_default' => [ 90 | [ 91 | 'ignore_tables_out' => [], 92 | 'post_sql_in' => '', 93 | 'post_command' => ['export $(cat config/.env | grep PATH | xargs) && export $(cat config/.env.local | grep PATH | xargs) && {{local/bin/deployer}} db:import:post_command:wp_domains ' . get('local_host')] 94 | ], 95 | function () { 96 | return (new \SourceBroker\DeployerExtendedWordpressComposer\Drivers\EnvDriver()) 97 | ->getDatabaseConfig(getcwd() . '/config/.env'); 98 | } 99 | ] 100 | ] 101 | ); 102 | 103 | // Look https://github.com/sourcebroker/deployer-extended-database#db-dumpclean for docs 104 | set('db_dumpclean_keep', [ 105 | '*' => 5, 106 | 'live' => 10, 107 | ]); -------------------------------------------------------------------------------- /src/Drivers/EnvDriver.php: -------------------------------------------------------------------------------- 1 | loadEnv($absolutePathWithConfig); 18 | return [ 19 | 'host' => $this->getEnv('DB_HOST'), 20 | 'port' => $this->getEnv('DB_PORT'), 21 | 'dbname' => $this->getEnv('DB_NAME'), 22 | 'user' => $this->getEnv('DB_USER'), 23 | 'password' => $this->getEnv('DB_PASSWORD'), 24 | ]; 25 | } 26 | 27 | /** 28 | * @param null $absolutePathWithConfig 29 | * @return string 30 | * @throws Exception 31 | */ 32 | public function getInstanceName($absolutePathWithConfig = null): string 33 | { 34 | $this->loadEnv($absolutePathWithConfig); 35 | $instanceName = $this->getEnv($this->getInstanceEnvName()); 36 | if ($instanceName === null) { 37 | throw new RuntimeException("\nWP_INSTANCE/WP_ENV env variable is not set. \nIf this is your local instance then please put following line: \nWP_ENV=development (or WP_INSTANCE=dev if you have instance based settings)\nin configuration file: ' . $absolutePathWithConfig . '\n\n"); 38 | } 39 | return $instanceName; 40 | } 41 | 42 | /** 43 | * @param null $absolutePathWithConfig 44 | */ 45 | private function loadEnv($absolutePathWithConfig = null): void 46 | { 47 | $env = new Env(); 48 | $env->load($absolutePathWithConfig, 'WP_INSTANCE'); 49 | } 50 | 51 | /** 52 | * @param string $envName 53 | * @return mixed|null 54 | */ 55 | private function getEnv(string $envName) 56 | { 57 | $env = new Env(); 58 | return $env->get($envName); 59 | } 60 | 61 | /** 62 | * @return mixed 63 | */ 64 | private function getInstanceEnvName() 65 | { 66 | return $_ENV['WP_INSTANCE'] ? 'WP_INSTANCE' : 'WP_ENV'; 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/Drivers/WordpressDriver.php: -------------------------------------------------------------------------------- 1 | load($envFilePath); 26 | $dbSettings = [ 27 | 'host' => getenv('DB_HOST'), 28 | 'port' => getenv('DB_PORT'), 29 | 'dbname' => getenv('DB_NAME'), 30 | 'user' => getenv('DB_USER'), 31 | 'password' => getenv('DB_PASSWORD'), 32 | ]; 33 | } else { 34 | throw new \Exception('Missing file "' . $envFilePath . '".'); 35 | } 36 | return $dbSettings; 37 | } 38 | 39 | /** 40 | * Return the instance name for project 41 | * 42 | * @param null $absolutePathWithConfig 43 | * @return string 44 | * @throws \Exception 45 | * @internal param null $params 46 | */ 47 | public function getInstanceName($absolutePathWithConfig = null) 48 | { 49 | $absolutePathWithConfig = $absolutePathWithConfig ?? getcwd(); 50 | $absolutePathWithConfig = rtrim($absolutePathWithConfig, DIRECTORY_SEPARATOR); 51 | $envFilePath = $absolutePathWithConfig . '/.env'; 52 | if (file_exists($envFilePath)) { 53 | (new Dotenv(true))->load($envFilePath); 54 | $instanceName = getenv('WP_ENV'); 55 | if (isset($instanceName) && strlen($instanceName)) { 56 | $instanceName = strtolower($instanceName); 57 | } else { 58 | throw new \Exception("\nWP_ENV env variable is not set. \nIf this is your local instance then please put following line: \nWP_ENV=development \nin configuration file: ' . $absolutePathWithConfig . '\n\n"); 59 | } 60 | } else { 61 | throw new \Exception('Missing file "' . $envFilePath . '".'); 62 | } 63 | return $instanceName; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Loader.php: -------------------------------------------------------------------------------- 1 | 'vendor/sourcebroker/deployer-instance/deployer'], 15 | ['path' => 'vendor/sourcebroker/deployer-extended/deployer'], 16 | ['path' => 'vendor/sourcebroker/deployer-extended-database/deployer'], 17 | ['path' => 'vendor/sourcebroker/deployer-extended-media/deployer'], 18 | ['path' => 'vendor/sourcebroker/deployer-extended-wordpress-composer/deployer'] 19 | ] 20 | ); 21 | } 22 | } 23 | --------------------------------------------------------------------------------