-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeploy.php
More file actions
171 lines (151 loc) · 4.69 KB
/
deploy.php
File metadata and controls
171 lines (151 loc) · 4.69 KB
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
<?php
namespace Deployer;
require_once 'recipe/common.php';
require_once 'contrib/rsync.php';
require_once 'contrib/cachetool.php';
require_once 'contrib/yarn.php';
// Config
set('repository', 'git@bitbucket.org:statikbe/[PROJECT_CODE_HERE].git');
//change writeable mode to chown because combell does not have acl installed:
set('writable_mode', 'chown');
set('keep_releases', 2);
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);
set('cachetool_args', '--web --web-path=./web --web-url=https://{{http_host}}');
// Shared files/dirs between deploys
set('shared_files', [
'.env'
]);
set('shared_dirs', [
'storage',
'public/files',
'translations',
]);
// Writable dirs by web server
set('writable_dirs', [
'storage',
'storage/runtime',
'storage/logs',
'storage/rebrand',
'public/cpresources',
'public/frontend'
]);
// Enable multiplexing
set('ssh_multiplexing', true);
//configure rsync:
set('rsync_src', __DIR__);
set('rsync_dest', '{{release_path}}');
set('rsync', [
'exclude' => [
'clint',
'.git',
'deploy.php',
'node_modules'
],
'exclude-file' => false,
'include' => [],
'include-file' => false,
'filter' => [],
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'rlE', // Recursive, copy symlinks as links, preserve executability
'options' => [
'delete', // Delete files that don't exist on sender
'inplace', // Update destination files in-place
'omit-dir-times', // Avoid setting directory timestamps (faster)
'no-compress', // Disable compression for small files
'no-perms', // Don't preserve permissions
],
'timeout' => 300,
]);
// Hosts
import('hosts.yml');
desc('Copy the correct .htaccess file for the given stage');
task('statik:copy_htaccess', function () {
$htaccessFile = get('htaccess_file');
if ($htaccessFile) {
run("cp {{release_path}}/config/$htaccessFile {{release_path}}/public/.htaccess");
}
});
desc('Copy the correct robots.txt file for the given stage');
task('statik:copy_robots', function () {
$robotsFile = get('robots_file');
if ($robotsFile) {
run("cp {{release_path}}/config/$robotsFile {{release_path}}/public/robots.txt");
}
});
desc('Give execute permissions for the Craft console command');
task('craft:set_permissions', function () {
run('chmod +x {{release_path}}/craft');
})->once();
desc('Craft up');
task('craft:up', function () {
run('{{release_path}}/craft up');
})->once();
desc('Cache clear');
task('craft:clear_caches', function () {
run('{{release_path}}/craft clear-caches/all');
})->once();
desc('Fichenbak versioning');
task('statik:fichenbak_versioning', function () {
run('if [ -s {{release_path}}/fichenbak-versioning.sh ]; then sh {{release_path}}/fichenbak-versioning.sh; fi');
})->once();
desc('Symlink current/public to www');
task('statik:symlink', function () {
onlyOnProduction(function () {
run('if [ ! -L "/data/sites/web/[PROJECT_CODE_HERE]livestatikbe/www" ]; then ln -s subsites/[PROJECT_CODE_HERE].live.statik.be/current/public /data/sites/web/[PROJECT_CODE_HERE]livestatikbe/www; fi');
});
run('{{release_path}}/craft statik/setup/install-translation-files');
})->once();
desc('Reload PHP-FPM');
task('statik:reload-phpfpm', function () {
sleep(3);
//reload the PHP-FPM caches.
//Combell has a command to achieve this: reloadPHP.sh
$tries = 1;
while ($tries <= 3) {
writeln('Reload PHP-FPM attempt #'.$tries.'..');
$output = run('reloadPHP.sh');
if (str_contains($output, 'OK')) {
writeln('PHP-FPM reloaded!');
break;
}
if ($tries++ >= 3) {
throw new \RuntimeException('Failed to reload PHP-fpm. Cannot proceed');
}
sleep(1);
}
});
//overwrite the deploy:prepare task, to change the git clone command with rsync:
task('deploy:prepare', [
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'rsync',
'deploy:shared',
'deploy:writable',
]);
task('deploy', [
'deploy:prepare',
'craft:set_permissions',
'craft:up',
'craft:clear_caches',
'statik:copy_htaccess',
'statik:copy_robots',
'statik:fichenbak_versioning',
'deploy:publish',
]);
//Adjust standard deployment:
after('deploy:failed', 'deploy:unlock');
after('deploy', 'statik:symlink');
after('statik:symlink', 'statik:reload-phpfpm');
after('deploy', 'deploy:success');
function onlyOnProduction(callable $taskLogic)
{
if (get('stage') === 'production') {
$taskLogic();
} else {
writeln('Skipping task: not in production stage.');
}
}