-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.php
218 lines (183 loc) · 6.79 KB
/
deploy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Magento 2 Deployer
*
* Deployment tool for Magento 2 by Imagination Media.
*
* @package ImaginationMedia\Deployer
* @author Igor Ludgero Miura <[email protected]>
* @copyright Copyright (c) 2019 Imagination Media (https://www.imaginationmedia.com/)
* @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0
*/
namespace Deployer;
require '../../deployer/recipes/recipe/slack.php';
require_once 'recipe/common.php';
require_once './Helper/Configuration.php';
require_once './Model/Environment.php';
require_once './Configuration/General.php';
require_once './Configuration/Mode/Full.php';
use Deployer\Helper\Configuration;
use Deployer\Task\Context;
use Deployer\Utility\Httpie;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
/**
* ====== Use custom invoke function to ignore tasks declared as ignored on env.json ==========================
*/
function invoke_custom($task)
{
if (!in_array($task, get("ignored_steps"))) {
$hosts = [Context::get()->getHost()];
$tasks = Deployer::get()->scriptManager->getTasks($task, $hosts);
$executor = Deployer::get()->seriesExecutor;
$executor->run($tasks, $hosts);
} else {
writeln("➤ Step ".$task." was ignored because it's set as ignored on env.json file.");
}
}
/**
* ============================================== CONFIGURE DEFAULT SETTINGS ===================================
*/
$configuration = new Configuration();
set('application', $configuration->getApplicationName());
set('git_tty', $configuration->getGitTty());
set('repository', $configuration->getRepositoryPath());
if (strpos(__DIR__, 'vendor/imaginationmedia/deployer-magento2') !== false) {
set('is_composer_installation', true);
} else {
set('is_composer_installation', false);
}
set('allow_anonymous_stats', false);
set('writable_use_sudo', false);
option('mode', null, InputOption::VALUE_OPTIONAL, 'Set the deployment mode.');
set('release_name', function () {
return date('YmdHis');
});
set('default_timeout', null);
/**
* Configure all hosts
* @var $environment \Deployer\Model\Environment
*/
foreach ($configuration->getEnvironments() as $environmentName => $environment) {
host($environmentName)
->hostname($environment->getHostName())
->user($environment->getUser())
->port($environment->getPort())
->set('deploy_path', $environment->getDeployPath())
->set('branch', $environment->getBranch())
->set('is_production', $environment->getIsProduction())
->set('php', $environment->getPhpPath())
->set('composer', $environment->getComposerPath())
->set('before_commands', $environment->getBeforeCommands())
->set('after_commands', $environment->getAfterCommands())
->set('keep_releases', $environment->getKeepReleases())
->set('http_user', $environment->getHttpUser())
->set('writable_mode', 'chown')
->set('languages', $environment->getLanguages())
->set('shared_files', $environment->getSharedFiles())
->set('shared_dirs', $environment->getSharedDirs())
->set('writable_dirs', $environment->getWritableDirs())
->set('clear_paths', $environment->getClearPaths())
->set('slack_webhook', $environment->getSlackWebhook())
->set('slack_text', $environment->getSlackText())
->set('slack_success_text', $environment->getSlackSuccessText())
->set('slack_failure_text', $environment->getSlackFailureText())
->set('ignored_steps', $environment->getIgnoredSteps())
->set('composer_ignore_requirements', $environment->isComposerIgnoreRequirements())
->set('actions_before_symlink', $environment->getActionsBeforeSymlinkChange())
->set('themes', $environment->getThemes())
->identityFile($environment->getIdentityFile())
->addSshOption('UserKnownHostsFile', '/dev/null')
->addSshOption('StrictHostKeyChecking', 'no');
//If symlink_fullpath is set as true we will deploy the symlinks using the fullpath
if ($environment->isSymlinkFullpath()) {
host($environmentName)
->set("bin/symlink", "ln -s");
}
}
/**
*
* ========================================= DEPLOYMENT ACTIONS ============================================
*
*/
task('deploy', function () {
invoke_custom('deploy:full:actions');
});
/**
* ========================================== Set SLACK options ============================================
*/
set('slack_color', "#15bb3c");
set('slack_failure_color', "#fa1212");
desc('Notifying Slack');
task('custom:slack:notify', function () {
if (!get('slack_webhook', false)) {
return;
}
foreach (get('slack_webhook') as $webhook) {
$attachment = [
'title' => get('slack_title'),
'text' => get('slack_text'),
'color' => get('slack_color'),
'mrkdwn_in' => ['text'],
];
Httpie::post($webhook)->body(['attachments' => [$attachment]])->send();
}
})
->once()
->shallow()
->setPrivate();
desc('Notifying Slack about deploy finish');
task('custom:slack:notify:success', function () {
if (!get('slack_webhook', false)) {
return;
}
foreach (get('slack_webhook') as $webhook) {
$attachment = [
'title' => get('slack_title'),
'text' => get('slack_success_text'),
'color' => get('slack_success_color'),
'mrkdwn_in' => ['text'],
];
Httpie::post($webhook)->body(['attachments' => [$attachment]])->send();
}
})
->once()
->shallow()
->setPrivate();
desc('Notifying Slack about deploy failure');
task('custom:slack:notify:failure', function () {
if (!get('slack_webhook', false)) {
return;
}
foreach (get('slack_webhook') as $webhook) {
$attachment = [
'title' => get('slack_title'),
'text' => get('slack_failure_text'),
'color' => get('slack_failure_color'),
'mrkdwn_in' => ['text'],
];
Httpie::post($webhook)->body(['attachments' => [$attachment]])->send();
}
})
->once()
->shallow()
->setPrivate();
task('before:deploy:slack:notify', function () {
if (count(get("slack_webhook")) > 0) {
invoke_custom('custom:slack:notify');
}
});
task('deploy:slack:success:notify', function () {
if (count(get("slack_webhook")) > 0) {
invoke_custom('custom:slack:notify:success');
}
});
task('deploy:slack:failed:notify', function () {
if (count(get("slack_webhook")) > 0) {
invoke_custom('custom:slack:notify:failure');
}
});
before('deploy', 'before:deploy:slack:notify');
after('success', 'deploy:slack:success:notify');
after('deploy:failed', 'deploy:slack:failed:notify');
after('deploy:failed', 'deploy:unlock');