Skip to content

Commit c4e201f

Browse files
authored
Merge pull request #9 from gaambo/development
v3.0.0: Rewrite to be more similar to PHP Deployers base recipes
2 parents d282fdf + f9575bf commit c4e201f

27 files changed

+572
-601
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Changelog
2+
3+
## v3.0.0
4+
5+
- Did a large refactor of paths (release_path, current_path, document_root)
6+
- Provide two [recipes](#recipes) (base and advanced) and examples for both
7+
- v2.0.0 did not work with symlink deployments, this now works again (see #8)
8+
- Updated from Deployer 7.2 to 7.3
9+
- New config options (see `set.php`):
10+
- `wp/configFiles` for wp-config/wp-config-local files which should be protected by more restrict file permissions
11+
- `wp/configFiles/permissions` for the chmod permissions to apply to the configFiles
12+
- Removed `document_root` - use `release_or_current_path` instead
13+
- New/changed task names:
14+
- `push_code` now is called `update_code` again for parity with PHPDeployer.
15+
16+
**Upgrading:**
17+
- If you haven't upgraded to v2.0.0 yet, it's best to upgrade to 3.0.0 directly
18+
- Have a look at the example files. Your deploy.php will get much smaller and require less configuration.
19+
- Also the new version is more smiliar to PHPDeployers default common recipe.
20+
21+
## v2.0.0
22+
23+
- Updated from Deployer 6.x to 7.x
24+
See [docs](https://deployer.org/docs/7.x/UPGRADE#upgrade-from-6x-to-7x) for more information.
25+
Most notable changes:
26+
- New format for yml-files which can now also include configuration.
27+
- The `local` is not available any more. Instead `once` and `runLocally` should be used. For theme assets the example uses a function callback and the `on` helper to optionally run those build tasks on the local host.
28+
- When deploying you can't select a host by name or stage anymore. Instead you have to use labels (eg a `stage` label). If you've used `dep deploy production` you now have to use `dep deploy stage=production` and set the stage label in your yml file.
29+
- Switched to a single base recipe which can be included and built upon. See `examples/deploy.php`.
30+
- The new recipe and examples uses yml-files for project-specific configuration so the `deploy.php` is a dropin file and has no configuration in it.
31+
- PHP 8 compatibility.
32+
- Fixes issues with rsync flags/options and `'`.
33+
34+
**Upgrading:**
35+
If you've used the default recipe it's probably easiest to copy the new example `deploy.php` and update your yml-file with project-specific configuration. If you have added any other tasks/features to your `deploy.php` make sure you upgrade them too.
36+
If you've used most of the core functions of this library or just the examples, the upgrade should only take a few minutes.

README.md

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,27 @@ A collection of [Deployer](https://deployer.org) Tasks/Recipes to deploy WordPre
2121
- [MU Plugin Tasks (`tasks/mu-plugins.php`)](#mu-plugin-tasks-tasksmu-pluginsphp)
2222
- [WordPress Tasks (`tasks/wp.php`)](#wordpress-tasks-taskswpphp)
2323
- [WP-CLI](#wp-cli)
24-
- [Simple Tasks (`tasks/simple.php`)](#simple-tasks-taskssimplephp)
2524
- [Recipes](#recipes)
26-
- [Default aka Vanilla - `deploy.php`](#default-aka-vanilla---deployphp)
25+
- [Base](#base)
26+
- [Advanced](#advanced)
2727
- [Custom Theme](#custom-theme)
2828
- [Custom MU-Plugin](#custom-mu-plugin)
29-
- [Simple - `deploy-simple.php`](#simple---deploy-simplephp)
30-
- [Custom Theme](#custom-theme-1)
31-
- [Custom MU-Plugin](#custom-mu-plugin-1)
3229
- [Changelog](#changelog)
33-
- [v2.0.0](#v200)
3430
- [Contributing](#contributing)
31+
- [Testing](#testing)
3532
- [Built by](#built-by)
3633

3734
## Installation
3835

3936
1. Run `composer require gaambo/deployer-wordpress --dev` in your root directory
40-
2. Choose one of the [recipes](#recipes) and copy the corresponding recipe file (`deploy*.php`) and example host file (`hosts*.example.yml`) from `recipes` into your root directory - **or** write your own.
37+
2. Choose one of the [recipes](#recipes) and copy the corresponding example files (`examples/base` or `examples/advanced`) into your root directory - **or** write your own.
4138
3. Read through the recipe and customize it to your needs - here's a checklist:
4239
- [ ] Check localhost configuration
4340
- [ ] Set paths to your directory structure
4441
- [ ] If you have a custom theme set it's name - if not remove the configuration and the theme build-tasks
4542
- [ ] If you have a custom mu-plugin set it's name - if not remove the configuration and the mu-plugin build-tasks
4643
- [ ] Check if the deployment flow meets your needs and maybe delete/add/overwrite tasks
47-
4. Make your remote hosts ready for deployment (install composer, WP CLI; setup paths,...)
44+
4. Make your remote hosts ready for deployment (install composer, WP CLI; setup paths,...). Allthough the library checks for most of them and installs them.
4845
5. Make a **test deployment** to a test/staging server. Do not directly deploy to your production site, you may break it.
4946
6. Develop, deploy and be happy :)
5047

@@ -70,13 +67,11 @@ Some tasks have additional requirements, eg:
7067
All tasks are documented and describe which options/variables need to be configured. `set.php` is included in all example recipes - This and the example recipes should have you covered regarding all required configurations. Further variables which need to be set by you are marked accordingly in the recipes.
7168

7269
To help understand all the configurations here are the thoughts behind theme:
73-
The tasks are built to work with any kind of WordPress setup (vanilla, composer, subdirectory,..) - therefore all paths and directorys are configurable via variables. `set.php` contains some sane defaults which makes all tasks wort out of the box with a default installation.
70+
The tasks are built to work with any kind of WordPress setup (vanilla, composer, subdirectory,..) - therefore all paths and directorys are configurable via variables. `set.php` contains some sane defaults which makes all tasks work out of the box with a default installation.
7471

7572
### Default Directory Structure
7673

77-
The defaults assume you've got everything in your root project directory. Which means `deploy.php` is located in the same directory which serves as document root and in this document root WordPress is installed with it's default directory structure (themes, plugins, uploads under `wp-content`).
78-
79-
My [Vanilla WordPress Boilerplate](https://github.com/gaambo/vanilla-wp/) puts the document root into a `public` subdirectory of the root directory. So it updates the paths on localhost to point to the public directory. You can find a example configuration in the GitHub repository.
74+
My [Vanilla WordPress Boilerplate](https://github.com/gaambo/vanilla-wp/) uses this library. You can find a example configuration in the GitHub repository.
8075

8176
### wp-config.php
8277

@@ -110,7 +105,7 @@ This prevents any development files/development tools from syncing. I strongly r
110105
## Tasks
111106

112107
All tasks reside in the `src/tasks` directory and are documented well. Here's a summary of all tasks - for details (eg required variables/config) see their source.
113-
You can also run `dep --list` to see all available tasks and their description.
108+
You can also run `dep list` to see all available tasks and their description.
114109

115110
### Database Tasks (`tasks/database.php`)
116111

@@ -178,17 +173,7 @@ You can also run `dep --list` to see all available tasks and their description.
178173
Handling and installing the WP-CLI binary can be done in one of multiple ways:
179174

180175
1. The default `bin/wp` in `set.php` checks for a usable WP-CLI binary and if none is found it downloads and installs it to `{{deploy_path}}/.dep/wp-cli.phar` (this path is checked in the future as well).
181-
2. If you want this behaviour (check if installed, else install) but in another path, overwrite the `bin/wp` variable with a function:
182-
```php
183-
set('bin/wp', function() {
184-
if($path = getWPCLIBinary()) {
185-
return $path;
186-
}
187-
return installWPCLI('/usr/local/bin', 'wp', true);
188-
}
189-
```
190-
This would install the WP-CLI binary into `/usr/local/bin` with sudo, since this path is probably in $PATH it's found via `getWPCLIBinary` the next time.
191-
176+
2. If you want this behaviour (check if installed, else install) but in another path, overwrite the `bin/wp` variable with a function and change the path it should be installed to.
192177
3. Set the `bin/wp` variable path on the host configuration, if WP-CLI is already installed.
193178
4. Install the WP-CLI binary manually with the `wp:install-wpcli` task and set the path as `/bin/wp` afterwards.
194179
You can pass the installPath, binaryFile and sudo usage via CLI:
@@ -198,45 +183,21 @@ See [original PR](https://github.com/gaambo/deployer-wordpress/pull/5) for more
198183

199184
There's a task for downloading core and `--info`. You can generate your own tasks to handle other WP-CLI commands, there's a util function `Gaambo\DeployerWordpress\Utils\WPCLI\runCommand` (`src/utils/wp-cli.php`);
200185

201-
### Simple Tasks (`tasks/simple.php`)
202-
203-
- Contains some overwrites of Deployer default `deploy:*` tasks to be used in a "simple" recipe without release paths. See [Simple Recipe](#simple)
204-
205-
If you want to include only some tasks/files you can require them via `require_once 'tasks/{task}.php';` because the `autoload.php` adds the `tasks` directory to the include path (similar to deployer). Please check you have your `vendor/autoload.php` loaded as well.
206-
207186
## Recipes
208187

209-
Deployer WordPress ships with some recipes which handle most of my use cases/WordPress setup types. Just copy the contents of the corresponding recipe file (`deploy*.php`) and example host file (`hosts*.example.yml`) from `recipes` into your root directory (and maybe rename the recipe to `deploy.php`). See [the installation checklist](#installation) for a quick checklist of settings to change. All recipes have some special configurations which are documented well in each file. Configuration details, thoughts behind it, use cases and more information are listed below for each recipe.
210-
211-
### Default aka Vanilla - `deploy.php`
212-
213-
Used for standard aka default aka vanilla deployments. By default it assumes the document root and WordPress are located in the same directory as your `deploy.php` (aka the root directory of your project). But all paths can be configured (see `set.php`).
214-
The recipe contains tasks for building assets for your custom theme, installing the vendors of your custom theme and installing the vendors of your custom mu-plugin (eg site-specific/core-functionality plugin).
215-
216-
The deployment flow is based on the default [Deployer flow](https://deployer.org/docs/flow.html) and assumes a default Deployer directory structure on the remote host.
217-
By default this recipes overwrites the `deploy:update_code` Deployer task with a `deploy:push_code` task to deploy code via rsync instead of git - but you can change that by removing the overwrite. Or you can edit the task to just sync themes (`themes:push`) and mu-plugins (`mu-plugins:push`).
218-
219-
#### Custom Theme
220-
221-
Set custom theme name (= directory) in variable `theme/name`.
222-
By default it runs `theme:assets:vendors` and `theme:assets:build` locally and just pushes the built/dist files to the server (--> no need to install Node.js/npm on server). The `theme:assets` task (which groups the two tasks above) is hooked into _before_ `deploy:push_code`.
223-
224-
Installing PHP/composer vendors/dependencies is done on the server. The `theme:vendors` task is therefore hooked into _after_ `deploy:push_code`.
225-
226-
#### Custom MU-Plugin
227-
228-
Set custom mu-plugin name (=directory) in variable `mu-plugin/name`.
229-
Installing PHP/composer vendors/dependencies is done on the server. The `mu-plugin:vendors` task is therefore hooked into _after_ `deploy:push_code`.
188+
Deployer WordPress ships with two base recipes which handle my use cases.
189+
Both recipes are based on the default PHPDeployer common recipe and have their own recipe file which you can include in your `deploy.php` as a start. The examples folder provides examples for each recipe.
190+
Both recipes log the deployed versions in PHPDeployers default format (`.dep` folder).
191+
Both recipes overwrites the `deploy:update_code` Deployer task with a `deploy:update_code` task to deploy code via rsync instead of git
230192

231-
### Simple - `deploy-simple.php`
193+
### Base
232194

233-
A simple task for deploying WordPress Sites on shared hosting via rsync.
234-
This is especially useful in case you can't put directories outside of the document root on your hosting or you don't want (for any reason) atomic deploys.
195+
This is for WordPress sites where you don't need symlinking per version or atomic releases. This means that on your remote/production host you just have on folder which contains all of WordPress files and this is served by your web server.
196+
Since this is still based on the default PHPDeployer recipe which uses symlinking and to provide compatibility with all tasks, this just hardcodes the `release_path` and `current_path`.
235197

236-
The deployment flow is based on the default [Deployer flow](https://deployer.org/docs/flow.html) but overwrites/removes some of the default `deploy:*` tasks to not create handle release directories, symlinks etc.
237-
By default this recipes overwrites the `deploy:update_code` Deployer task with a `deploy:push_code` task to deploy code via rsync instead of git - but you can change that by removing the overwrite. Or you can edit the task to just sync themes (`themes:push`) and mu-plugins (`mu-plugins:push`).
198+
### Advanced
238199

239-
An important configuration step is to set **deploy_path**, **release_path** and **document_root** on each remote host to the same directory. This way all tasks work as usual and don't require any changes.
200+
This uses symlinking like the default common recipe from PHPDeployer. Each release gets deployed in its own folder unter `{{deploy_path}}/releases/` and `{{deploy_path}}/current` is a symlink to the most current version. The symlink is automatically updated after the deployment finishes successfully. You can configure your webserver to just server `{{deploy_path}}/current`.
240201

241202
#### Custom Theme
242203

@@ -252,28 +213,20 @@ Installing PHP/composer vendors/dependencies is done on the server. The `mu-plug
252213

253214
## Changelog
254215

255-
### v2.0.0
256-
257-
- Updated from Deployer 6.x to 7.x
258-
See [docs](https://deployer.org/docs/7.x/UPGRADE#upgrade-from-6x-to-7x) for more information.
259-
Most notable changes:
260-
- New format for yml-files which can now also include configuration.
261-
- The `local` is not available any more. Instead `once` and `runLocally` should be used. For theme assets the example uses a function callback and the `on` helper to optionally run those build tasks on the local host.
262-
- When deploying you can't select a host by name or stage anymore. Instead you have to use labels (eg a `stage` label). If you've used `dep deploy production` you now have to use `dep deploy stage=production` and set the stage label in your yml file.
263-
- Switched to a single base recipe which can be included and built upon. See `examples/deploy.php`.
264-
- The new recipe and examples uses yml-files for project-specific configuration so the `deploy.php` is a dropin file and has no configuration in it.
265-
- PHP 8 compatibility.
266-
- Fixes issues with rsync flags/options and `'`.
267-
268-
**Upgrading:**
269-
If you've used the default recipe it's probably easiest to copy the new example `deploy.php` and update your yml-file with project-specific configuration. If you have added any other tasks/features to your `deploy.php` make sure you upgrade them too.
270-
If you've used most of the core functions of this library or just the examples, the upgrade should only take a few minutes.
216+
See [CHANGELOG.md](CHANGELOG.md).
271217

272218
## Contributing
273219

274220
If you have feature requests, find bugs or need help just open an issue on [GitHub](https://github.com/gaambo/deployer-wordpress).
275221
Pull requests are always welcome. PSR2 coding standard are used and I try to adhere to Deployer best-practices.
276222

223+
### Testing
224+
225+
1. Download my [Vanilla WordPress Boilerplate](https://github.com/gaambo/vanilla-wp/) or set up a local dev environment with a deploy config
226+
2. Setup a remote test server
227+
3. Configure yml/deploy.php
228+
4. Run common tasks (`deploy`, `plugins:pull/push`, `db`) for both base as well as advanced recipe
229+
277230
## Built by
278231

279232
[Gaambo](https://github.com/gaambo) and [Contributors](https://github.com/gaambo/deployer-wordpress/graphs/contributors)

composer.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"name": "gaambo/deployer-wordpress",
3-
"description": "Deployer tasks for deploying WordPress Sites",
4-
"version": "2.0.0",
5-
"type": "library",
6-
"license": "MIT",
7-
"homepage": "https://github.com/gaambo/deployer-wordpress",
8-
"authors": [
9-
{
10-
"name": "Fabian Todt",
11-
"email": "fabian@fabiantodt.at"
12-
}
13-
],
14-
"require-dev": {},
15-
"require": {
16-
"php": "^8.0|^7.3",
17-
"deployer/deployer": "^7.2"
18-
},
19-
"autoload": {
20-
"files": [
21-
"autoload.php"
22-
]
2+
"name": "gaambo/deployer-wordpress",
3+
"description": "Deployer tasks for deploying WordPress Sites",
4+
"version": "3.0.0",
5+
"type": "library",
6+
"license": "MIT",
7+
"homepage": "https://github.com/gaambo/deployer-wordpress",
8+
"authors": [
9+
{
10+
"name": "Fabian Todt",
11+
"email": "fabian@fabiantodt.at"
2312
}
13+
],
14+
"require-dev": {},
15+
"require": {
16+
"php": "^8.0|^7.3",
17+
"deployer/deployer": "^7.3"
18+
},
19+
"autoload": {
20+
"files": [
21+
"autoload.php"
22+
]
23+
}
2424
}

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/advanced/deploy.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
require_once __DIR__ . '/vendor/gaambo/deployer-wordpress/recipes/advanced.php';
5+
6+
use function Deployer\after;
7+
use function Deployer\import;
8+
use function Deployer\localhost;
9+
use function Deployer\task;
10+
use function Gaambo\DeployerWordpress\Utils\Localhost\getLocalhost;
11+
12+
// hosts & config
13+
import('deploy.yml');
14+
15+
// OPTIONAL: overwrite localhost config'
16+
localhost()
17+
->set('public_url', "{{local_url}}")
18+
->set('deploy_path', __DIR__)
19+
->set('release_path', __DIR__ . '/public')
20+
// set current_path to hardcoded release_path on local so release_or_current_path works; {{release_path}} does not work here?
21+
->set('current_path', function () {
22+
return getLocalhost()->get('release_path');
23+
})
24+
->set('dump_path', __DIR__ . '/data/db_dumps')
25+
->set('backup_path', __DIR__ . '/data/backups');
26+
27+
/**
28+
* Example Deployment Configuration:
29+
*/
30+
// only push WordPress core files, themes, mu-plugins, plugins (not uploads, )
31+
// task('deploy:update_code', ['wp:push', 'plugins:push', 'mu-plugins:push', 'themes:push'])
32+
// ->desc("Pushes updated code to target host");
33+
34+
// // install theme composer vendors composer on server
35+
// after('deploy:update_code', 'theme:vendors');
36+
37+
// // install mu-plugin vendors after deploying (on remote host)
38+
// after('deploy:update_code', 'mu-plugin:vendors');

0 commit comments

Comments
 (0)