-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.php
92 lines (78 loc) · 2.54 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
<?php
namespace Deployer;
use Deployer\Task\Context;
require 'recipe/common.php';
require 'deploy/recipe/silverstripe.php';
// Number of releases to keep
set('keep_releases', 5);
// [Optional] Allocate tty for git clone. Default value is false
set('git_tty', true);
// Shared files/dirs between deploys
set('shared_files', [
'.env',
'debug.log'
]);
set('shared_dirs', [
'public/assets',
'public/.well-known'
]);
// Writable dirs by web server
set('writable_dirs', [
'public/assets',
'silverstripe-cache'
]);
set('allow_anonymous_stats', false);
// Hosts
set('default_stage', 'staging');
inventory(__DIR__ . '/deploy/hosts.yml');
desc('Deploy your project');
task('deploy', function() {
invoke('deploy:info');
invoke('deploy:prepare');
invoke('deploy:lock');
invoke('deploy:release');
invoke('deploy:update_code');
invoke('silverstripe:create_dotenv');
invoke('silverstripe:create_cache_dir');
invoke('deploy:shared');
invoke('deploy:writable');
invoke('deploy:vendors');
invoke('silverstripe:vendor_expose');
invoke('silverstripe:dev_build');
invoke('deploy:clear_paths');
invoke('deploy:symlink');
invoke('deploy:unlock');
invoke('cleanup');
invoke('success');
});
// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
task('clear_cloudflare_cache', function () {
$config = Context::get()->getHost()->getConfig();
$zone_id_key = 'zone_id';
$api_key_key = 'api_key';
$zone_id_value = $config->has($zone_id_key) ? $config->get($zone_id_key) : null;
$api_key_value = $config->has($api_key_key) ? $config->get($api_key_key) : null;
if (!empty($zone_id_value) && !empty($api_key_value)) {
try {
ob_start();
$head = [];
$head[] = 'Content-Type: application/json';
$head[] = "Authorization: Bearer {$api_key_value}";
$head[] = 'cache-control: no-cache';
$url = "https://api.cloudflare.com/client/v4/zones/{$zone_id_value}/purge_cache";
$purge = ['purge_everything' => true];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($purge));
curl_exec($ch);
curl_close($ch);
ob_clean();
} catch (Exception $e) {
print($e);
}
}
});
before('success', 'clear_cloudflare_cache');