-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-shopware.php
306 lines (280 loc) · 10.2 KB
/
deploy-shopware.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
namespace Deployer;
require_once 'recipe/common.php';
add('shared_files', ['{{shopware_public_dir}}/config.php']);
add(
'shared_dirs',
[
'{{shopware_public_dir}}/media',
'{{shopware_public_dir}}/files',
]
);
add(
'create_shared_dirs',
[
'{{shopware_public_dir}}/media/archive',
'{{shopware_public_dir}}/media/image',
'{{shopware_public_dir}}/media/image/thumbnail',
'{{shopware_public_dir}}/media/music',
'{{shopware_public_dir}}/media/pdf',
'{{shopware_public_dir}}/media/unknown',
'{{shopware_public_dir}}/media/video',
'{{shopware_public_dir}}/media/temp',
'{{shopware_public_dir}}/files/documents',
'{{shopware_public_dir}}/files/downloads',
]
);
add(
'writable_dirs',
[
'{{shopware_public_dir}}/var/cache',
'{{shopware_public_dir}}/web/cache',
'{{shopware_public_dir}}/recovery',
'{{shopware_public_dir}}/themes',
]
);
add(
'executable_files',
[
'{{shopware_public_dir}}/bin/console',
]
);
set('shopware_public_dir', 'web');
set('shopware_public_path', '{{release_path}}/{{shopware_public_dir}}');
set('shopware_temp_dir', '{{release_path}}/shopware-tmp');
set('shopware_temp_zip_file', '{{release_path}}/shopware.zip');
set('fcgi_sockets', []);
set('keep_releases', 10);
task(
'deploy:writable:create_dirs',
function () {
foreach (get('writable_dirs') as $dir) {
run("cd {{release_path}} && mkdir -p $dir");
}
}
)->desc('Create required directories, configure via deploy.php');
before('deploy:writable', 'deploy:writable:create_dirs');
task(
'deploy:shared:sub',
function () {
$sharedPath = "{{deploy_path}}/shared";
foreach (get('create_shared_dirs') as $dir) {
// Create shared dir if it does not exist.
run("mkdir -p $sharedPath/$dir");
}
}
)->desc('Creating shared subdirs');
after('deploy:shared', 'deploy:shared:sub');
task(
'kellerkinder:shopware:download',
function () {
run('wget -nc -O {{shopware_temp_zip_file}} {{shopware_download_path}}');
run('mkdir {{shopware_temp_dir}}');
run('unzip {{shopware_temp_zip_file}} -d {{shopware_temp_dir}}');
run('rm {{shopware_temp_zip_file}}');
run('rm -rf {{shopware_temp_dir}}/recovery');
run('rsync --ignore-existing --recursive {{shopware_temp_dir}}/ {{shopware_public_path}}/');
run('rm -rf {{shopware_temp_dir}}');
run('mkdir -p {{shopware_public_path}}/recovery/install/data');
run('touch {{shopware_public_path}}/recovery/install/data/install.lock');
}
)->desc('Download and include Shopware core data into project')->setPrivate();
task(
'kellerkinder:shopware:update',
function () {
if (test('cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:update:needed {{shopware_update_version}} -q')) {
run('wget -nc -O {{shopware_temp_zip_file}} {{shopware_update_path}}');
run('mkdir {{shopware_temp_dir}}');
run('unzip {{shopware_temp_zip_file}} -d {{shopware_temp_dir}}');
run('rm {{shopware_temp_zip_file}}');
run('rsync --recursive {{shopware_temp_dir}}/ {{shopware_public_path}}/');
run('rm -rf {{shopware_temp_dir}}');
run('cd {{shopware_public_path}} && {{bin/php}} recovery/update/index.php -n');
run('rm -rf {{shopware_public_path}}/update-assets');
run('rm -rf {{shopware_public_path}}/recovery');
run('mkdir -p {{shopware_public_path}}/recovery/install/data');
run('touch {{shopware_public_path}}/recovery/install/data/install.lock');
}
}
)->desc('Check if a Shopware update is needed and execute it');
task(
'kellerkinder:vendors',
function () {
foreach ([
'k10r/staging:1.0.3',
'k10r/deployment:1.2.0',
] as $dependency) {
run(
"cd {{shopware_public_path}} && {{bin/composer}} require --optimize-autoloader --prefer-dist --no-ansi --update-no-dev --no-scripts {$dependency}"
);
}
}
)->desc('Add required composer-based Shopware plugins for deployment')->setPrivate();
task(
'deploy:vendors',
function () {
run('cd {{shopware_public_path}} && {{bin/composer}} {{composer_options}}');
}
)->desc('Install composer dependencies');
task(
'kellerkinder:shopware:plugins',
function () {
run('cd {{shopware_public_path}} && {{bin/php}} bin/console sw:plugin:refresh -q');
run('cd {{shopware_public_path}} && {{bin/php}} bin/console sw:plugin:reinstall K10rDeployment');
run('cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:plugin:deactivate SwagUpdate');
foreach (get('plugins') as $plugin) {
run(
"cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:plugin:install --activate {$plugin}"
);
}
foreach (get('plugin_config') as $pluginName => $pluginConfigs) {
foreach ($pluginConfigs as $pluginConfig) {
run(
sprintf(
"cd {{shopware_public_path}} && {{bin/php}} bin/console sw:plugin:config:set %s %s \"%s\" %s",
$pluginName,
$pluginConfig['name'],
$pluginConfig['value'],
isset($pluginConfig['shopId']) ? "--shop {$pluginConfig['shopId']}" : ""
)
);
}
}
}
)->desc('Install Shopware plugins after deployment. Configure plugins via deploy.php.');
task(
'kellerkinder:shopware:config',
function () {
run("cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:snippets:update");
run("cd {{shopware_public_path}} && {{bin/php}} bin/console netcom:migrations:migrate:up");
foreach (get('shopware_config') as $config) {
run(
sprintf(
"cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:config:set %s %s %s",
$config['name'],
$config['value'],
isset($config['shopId']) ? "--shop {$config['shopId']}" : ""
)
);
}
}
)->desc('Update snippets and set Shopware core configuration');
task(
'kellerkinder:shopware:theme',
function () {
run(
"cd {{shopware_public_path}} && {{bin/php}} bin/console sw:theme:synchronize -q"
);
foreach (get('theme_config') as $themeName => $themeSettings) {
foreach ($themeSettings as $setting => $value) {
run(
sprintf(
"cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:theme:update -q --theme '%s' --setting '%s' --value '%s' %s",
$themeName,
$setting,
$value
)
);
}
}
}
)->desc('Configure theme via deploy.php');
task(
'kellerkinder:shopware:cache',
function () {
run('cd {{shopware_public_path}} && {{bin/php}} bin/console sw:cache:clear -q');
run('cd {{shopware_public_path}} && {{bin/php}} bin/console sw:theme:cache:generate -q');
if (get('warm_cache_after_deployment', false)) {
run('cd {{shopware_public_path}} && {{bin/php}} bin/console sw:warm:http:cache -c -q');
}
}
)->desc('Clear Shopware cache and warm up HTTP cache');
task(
'kellerkinder:shopware:opcache',
function () {
foreach (get('fcgi_sockets') as $socket) {
run("cd {{release_path}} && if [ -f bin/cachetool.phar ]; then {{bin/php}} bin/cachetool.phar opcache:reset --fcgi={$socket}; else true; fi");
}
}
)->desc('Clear PHP OPcache');
task(
'kellerkinder:shopware:staging',
function () {
run(
'cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:plugin:install --activate K10rStaging'
);
run(
sprintf('cd {{shopware_public_path}} && {{bin/php}} bin/console k10r:store:update --host %s --path %s --name %s --title %s',
escapeshellarg(get('shop_host')),
escapeshellarg(get('shop_path')),
escapeshellarg(get('shop_name')),
escapeshellarg(get('shop_title'))
)
);
}
)->desc('Set staging configuration');
task(
'kellerkinder:shopware:production',
function () {}
)->desc('Set production configuration');
/**
* Main task
*/
task(
'kellerkinder:shopware:install',
[
'kellerkinder:shopware:download',
'kellerkinder:vendors',
]
)->desc('Download current Shopware distribution and copy it into deployed directory, install composer-based Shopware plugins');
task(
'kellerkinder:shopware:configure',
[
'kellerkinder:shopware:opcache',
'kellerkinder:shopware:plugins',
'kellerkinder:shopware:config',
'kellerkinder:shopware:cache',
]
)->desc('Install remaining Shopware plugins, set configuration values and clear cache');
task(
'deploy:production',
[
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'kellerkinder:shopware:install',
'deploy:writable',
'deploy:vendors',
'deploy:clear_paths',
'deploy:symlink',
'kellerkinder:shopware:update',
'kellerkinder:shopware:configure',
'kellerkinder:shopware:production',
'deploy:unlock',
'cleanup',
'success',
]
)->desc('Deploys a production shopware project');
task(
'deploy:staging',
[
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'kellerkinder:shopware:install',
'deploy:writable',
'deploy:vendors',
'deploy:clear_paths',
'deploy:symlink',
'kellerkinder:shopware:update',
'kellerkinder:shopware:configure',
'kellerkinder:shopware:staging',
'deploy:unlock',
'cleanup',
'success',
]
)->desc('Deploys a staging shopware project');