-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,396 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,49 @@ require 'contrib/cimonitor.php'; | |
[Source](/contrib/cimonitor.php) | ||
|
||
|
||
|
||
Monitor your deployments on [CIMonitor](https://github.com/CIMonitor/CIMonitor). | ||
![CIMonitorGif](https://www.steefmin.xyz/deployer-example.gif) | ||
Add tasks on deploy: | ||
```php | ||
before('deploy', 'cimonitor:notify'); | ||
after('deploy:success', 'cimonitor:notify:success'); | ||
after('deploy:failed', 'cimonitor:notify:failure'); | ||
``` | ||
## Configuration | ||
- `cimonitor_webhook` – CIMonitor server webhook url, **required** | ||
``` | ||
set('cimonitor_webhook', 'https://cimonitor.enrise.com/webhook/deployer'); | ||
``` | ||
- `cimonitor_title` – the title of application, default the username\reponame combination from `{{repository}}` | ||
``` | ||
set('cimonitor_title', ''); | ||
``` | ||
- `cimonitor_user` – User object with name and email, default gets information from `git config` | ||
``` | ||
set('cimonitor_user', function () { | ||
return [ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
]; | ||
}); | ||
``` | ||
Various cimonitor statusses are set, in case you want to change these yourselves. See the [CIMonitor documentation](https://cimonitor.readthedocs.io/en/latest/) for the usages of different states. | ||
## Usage | ||
If you want to notify only about beginning of deployment add this line only: | ||
```php | ||
before('deploy', 'cimonitor:notify'); | ||
``` | ||
If you want to notify about successful end of deployment add this too: | ||
```php | ||
after('deploy:success', 'cimonitor:notify:success'); | ||
``` | ||
If you want to notify about failed deployment add this too: | ||
```php | ||
after('deploy:failed', 'cimonitor:notify:failure'); | ||
``` | ||
|
||
|
||
## Configuration | ||
### cimonitor_title | ||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cimonitor.php#L64) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,107 @@ require 'contrib/cpanel.php'; | |
|
||
|
||
|
||
### Description | ||
This is a recipe that uses the [cPanel 2 API](https://documentation.cPanel.net/display/DD/Guide+to+cPanel+API+2). | ||
Unfortunately the [UAPI](https://documentation.cPanel.net/display/DD/Guide+to+UAPI) that is recommended does not have support for creating addon domains. | ||
The main idea behind is for staging purposes but I guess you can use it for other interesting concepts. | ||
The idea is, every branch possibly has its own staging domain/subdomain (staging-neat-feature.project.com) and database db_neat-feature_project so it can be tested. | ||
This recipe can make the domain/subdomain and database creation part of the deployment process so you don't have to manually create them through an interface. | ||
### Configuration | ||
The example uses a .env file and Dotenv for configuration, but you can set the parameters as you wish | ||
``` | ||
set('cpanel', [ | ||
'host' => getenv('CPANEL_HOST'), | ||
'port' => getenv('CPANEL_PORT'), | ||
'username' => getenv('CPANEL_USERNAME'), | ||
'auth_type' => getenv('CPANEL_AUTH_TYPE'), | ||
'token' => getenv('CPANEL_TOKEN'), | ||
'user' => getenv('CPANEL_USER'), | ||
'db_user' => getenv('CPANEL_DB_USER'), | ||
'db_user_privileges' => getenv('CPANEL_DB_PRIVILEGES'), | ||
'timeout' => 500, | ||
'allowInStage' => ['staging', 'beta', 'alpha'], | ||
'create_domain_format' => '%s-%s-%s', | ||
'create_domain_values' => ['staging', 'master', get('application')], | ||
'subdomain_prefix' => substr(md5(get('application')), 0,4) . '-', | ||
'subdomain_suffix' => getenv('SUDOMAIN_SUFFIX'), | ||
'create_db_format' => '%s_%s-%s-%s', | ||
'create_db_values' => ['apps', 'staging','master', get('application')], | ||
]); | ||
``` | ||
- `cpanel` – array with configuration for cPanel | ||
- `username` – WHM account | ||
- `user` – cPanel account that you want in charge of the domain | ||
- `token` – WHM API token | ||
- `create_domain_format` – Format for name creation of domain | ||
- `create_domain_values` – The actual value reference for naming | ||
- `subdomain_prefix` – cPanel has a weird way of dealing with addons and subdomains, you cannot create 2 addons with the same subdomain, so you need to change it in some way, example uses first 4 chars of md5(app_name) | ||
- `subdomain_suffix` – cPanel has a weird way of dealing with addons and subdomains, so the suffix needs to be your main domain for that account for deletion purposes | ||
- `addondir` – addon dir is different from the deploy path because cPanel "injects" /home/user/ into the path, so tilde cannot be used | ||
- `allowInStage` – Define the stages that cPanel recipe actions are allowed in | ||
#### .env file example | ||
``` | ||
CPANEL_HOST=xxx.xxx.xxx.xxx | ||
CPANEL_PORT=2087 | ||
CPANEL_USERNAME=root | ||
CPANEL_TOKEN=xxxx | ||
CPANEL_USER=xxx | ||
CPANEL_AUTH_TYPE=hash | ||
CPANEL_DB_USER=db_user | ||
CPANEL_DB_PRIVILEGES="ALL PRIVILEGES" | ||
SUDOMAIN_SUFFIX=.mymaindomain.com | ||
``` | ||
### Tasks | ||
- `cpanel:createaddondomain` Creates an addon domain | ||
- `cpanel:deleteaddondomain` Removes an addon domain | ||
- `cpanel:createdb` Creates a new database | ||
### Usage | ||
A complete example with configs, staging and deployment | ||
``` | ||
<?php | ||
namespace Deployer; | ||
use Dotenv\Dotenv; | ||
require 'vendor/autoload.php'; | ||
(Dotenv::create(__DIR__))->load(); // this is used just so an .env file can be used for credentials | ||
require 'cpanel.php'; | ||
Project name | ||
set('application', 'myproject.com'); | ||
Project repository | ||
set('repository', '[email protected]:myorg/myproject.com'); | ||
set('cpanel', [ | ||
'host' => getenv('CPANEL_HOST'), | ||
'port' => getenv('CPANEL_PORT'), | ||
'username' => getenv('CPANEL_USERNAME'), | ||
'auth_type' => getenv('CPANEL_AUTH_TYPE'), | ||
'token' => getenv('CPANEL_TOKEN'), | ||
'user' => getenv('CPANEL_USER'), | ||
'db_user' => getenv('CPANEL_DB_USER'), | ||
'db_user_privileges' => getenv('CPANEL_DB_PRIVILEGES'), | ||
'timeout' => 500, | ||
'allowInStage' => ['staging', 'beta', 'alpha'], | ||
'create_domain_format' => '%s-%s-%s', | ||
'create_domain_values' => ['staging', 'master', get('application')], | ||
'subdomain_prefix' => substr(md5(get('application')), 0,4) . '-', | ||
'subdomain_suffix' => getenv('SUDOMAIN_SUFFIX'), | ||
'create_db_format' => '%s_%s-%s-%s', | ||
'create_db_values' => ['apps', 'staging','master', get('application')], | ||
]); | ||
host('myproject.com') | ||
->stage('staging') | ||
->set('cpanel_createdb', vsprintf(get('cpanel')['create_db_format'], get('cpanel')['create_db_values'])) | ||
->set('branch', 'dev-branch') | ||
->set('deploy_path', '~/staging/' . vsprintf(get('cpanel')['create_domain_format'], get('cpanel')['create_domain_values'])) | ||
->set('addondir', 'staging/' . vsprintf(get('cpanel')['create_domain_format'], get('cpanel')['create_domain_values'])); | ||
Tasks | ||
task('build', function () { | ||
run('cd {{release_path}} && build'); | ||
}); | ||
after('deploy:prepare', 'cpanel:createaddondomain'); | ||
after('deploy:prepare', 'cpanel:createdb'); | ||
``` | ||
|
||
|
||
|
||
## Tasks | ||
|
||
### cpanel:createdb | ||
|
Oops, something went wrong.