deployphp / deployer

The PHP deployment tool with support for popular frameworks out of the box
https://deployer.org
MIT License
10.41k stars 1.47k forks source link

Add ability to customize & overwrite deployer stock commands #3802

Open cornelisonc opened 2 months ago

cornelisonc commented 2 months ago

I've reworked the init() function of Deployer.php to include a maybeAddCustomCommands() function, which checks for a DeployerCommands dir in the project root and, if any exist, integrate them with Deployer accordingly. Custom commands can either override stock Deployer commands or create new commands. These changes are 100% backwards-compatible, in that if no DeployerCommands dir is present, there are no changes to the current functionality.

One of the primary advantages of this restructure is the ability to customize the deployer.php templates being used, to include additional information or additional formats.

Here is a gist demonstrating an example implementation of a customized InitCommand.php file, which would be placed inside DeployerCommands/ at the project root. In this example file, I've customized

  1. configure() -- customized the init command description
  2. setDomain() -- new functionality to set project domain on initialization
  3. guessHost() -- an example of a customized host-guessing procedure where our site includes a host.php file serving the hostname; this hostname can later be used in the deployer.php script

An alternative implementation of guessHost() could also integrate with a registrar's API, implement nslookup, just for a few examples.

For developers or engineering teams, the ability to override Deployer's stock commands and templates would make a huge improvement in standardizing implementation across projects, and allow them to script out many of the initial configuration steps for deployer.php which aren't quite covered by custom recipes.