Repository navigation
Expand file tree
/
Copy pathdeploy.php
More file actions
173 lines (152 loc) · 4.86 KB
/
Copy pathdeploy.php
File metadata and controls
173 lines (152 loc) · 4.86 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
172
173
<?php
namespace Deployer;
use Robo\Robo;
import('recipe/wordpress.php');
import('contrib/cachetool.php');
import('contrib/rsync.php');
import('recipe/deploy/rollback.php');
import('vendor/generoi/deployer-genero/cachetool.php');
import('vendor/generoi/deployer-genero/common.php');
import('vendor/generoi/deployer-genero/setup.php');
import('vendor/generoi/deployer-genero/wordpress.php');
require_once __DIR__.'/vendor/autoload.php';
$robo = Robo::createConfiguration(['robo.yml'])->export();
set('scaffold_machine_name', $robo['machine_name']);
set('scaffold_env_file', __DIR__.'/.env.example');
set('theme_dir', $robo['theme_path']);
set('keep_releases', 5);
set('default_stage', 'production');
set('ssh_multiplexing', true);
set('shared_files', ['.env']);
set('shared_dirs', ['web/app/uploads', 'storage/logs']);
set('writable_dirs', ['web/app/cache', ...get('shared_dirs')]);
set('writable_mode', 'chmod');
set('writable_use_sudo', false);
set('writable_chmod_mode', 'ug+w');
set('bin/wp', './vendor/bin/wp');
/**
* Deploy configuration
*/
set('rsync_src', '{{build_artifact_dir}}');
set('rsync_dest', '{{release_path}}');
set('rsync', [
'exclude' => [...get('writable_dirs'), ...get('shared_files')],
'include' => [],
'filter' => [],
'exclude-file' => false,
'include-file' => false,
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'rv',
'options' => ['delete', 'links', 'chmod=u+w'],
'timeout' => 3600,
]);
/**
* Build configuration
*/
set('build_repository', __DIR__); // @todo github
set('build_path', '/tmp/dep-'.basename(__DIR__));
set('build_artifact_dir', '{{build_path}}/artifact');
set('build_artifact_exclude', [
'.git',
'node_modules',
'*.sql',
'/.*',
'/*.md',
'/config/*.yml',
'/config/patches',
'/*.php',
'/*.xml',
'/*.yml',
'/web/wp/readme.html',
'/web/wp/license.txt',
]);
/**
* Hosts
*/
if (! empty($prod = $robo['env']['@production'])) {
host('production')
->setHostname($prod['host'])
->setPort($prod['port'] ?? 22)
->setRemoteUser($prod['user'])
->set('url', is_array($prod['url']) ? $prod['url'][0] : $prod['url'])
->set('deploy_path', dirname($prod['path']))
->set('bin/wp', '{{ release_path }}/vendor/bin/wp');
}
if (! empty($staging = $robo['env']['@staging'])) {
host('staging')
->setHostname($staging['host'])
->setPort($staging['port'] ?? 22)
->setRemoteUser($staging['user'])
->set('url', is_array($staging['url']) ? $staging['url'][0] : $staging['url'])
->set('deploy_path', dirname($staging['path']))
->set('bin/wp', '{{ release_path }}/vendor/bin/wp')
->set('scaffold_home_url', is_array($staging['url']) ? $staging['url'][0] : $staging['url']);
}
/**
* Build tasks
*/
task('build:setup', function () {
runLocally('rm -rf {{build_path}}');
runLocally('mkdir -p {{build_path}}');
runLocally('git clone {{build_repository}} {{build_path}}');
});
task('build:composer', function () {
runLocally('cd {{build_path}} && composer {{composer_action}} {{composer_options}}');
});
task('build:theme', function () {
runLocally('cd {{build_path}} && composer build', timeout: 1000);
runLocally('ls {{build_path}}/{{theme_dir}}/build');
});
task('build:artifact', function () {
// Sanitize content by copying files into an artifact directory
$exclude = array_reduce(get('build_artifact_exclude'), function ($carry, $exclude) {
return $carry.' --exclude='.escapeshellarg($exclude);
}, '');
runLocally("rsync -r --delete --links $exclude '{{build_path}}/' '{{build_artifact_dir}}/'");
});
desc('Build release locally');
task('build', [
'build:setup',
'build:composer',
'build:theme',
'build:artifact',
]);
/**
* Cache clearing
*/
/**
* Flush every cache tag, so a CDN in front (Fastly, Cloudflare) is purged
* too: Kinsta's clear-all only reaches Kinsta's own caches.
*/
task('cache:clear:cachetags', function () {
run('cd {{deploy_path}}/current/web && {{bin/wp}} acorn cachetags:flush');
});
/**
* OPcache first: Kinsta never resets it, and caches each release under its own
* releases/NNN path, so a few deploys fill it and requests compile most of the
* code themselves (suomentyokalu c67a00b8). The object cache holds whatever the
* previous release wrote, so it is flushed with the rest.
*/
desc('Clear caches');
task('cache:clear', [
'cache:clear:opcache',
'cache:clear:kinsta',
'cache:clear:cachetags',
'cache:clear:wp:objectcache',
'cache:clear:wp:acorn',
]);
task('deploy:update_code', function () {
// Do not store the git repository on remote.
});
desc('Deploy release');
task('deploy', [
'deploy:prepare',
'build',
'rsync:warmup',
'rsync',
'deploy:publish',
]);
after('deploy:failed', 'deploy:unlock');
after('deploy:symlink', 'cache:clear');
after('rollback', 'cache:clear');