|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ## Usage |
|
4
|
|
|
* |
|
5
|
|
|
* Add `repository` to your _deploy.php_ file: |
|
6
|
|
|
* |
|
7
|
|
|
* ```php |
|
8
|
|
|
* set('repository', '[email protected]:shopware/production.git'); |
|
9
|
|
|
* ``` |
|
10
|
|
|
* |
|
11
|
|
|
* configure host: |
|
12
|
|
|
* ```php |
|
13
|
|
|
* host('SSH-HOSTNAME') |
|
14
|
|
|
* ->set('remote_user', 'SSH-USER') |
|
15
|
|
|
* ->set('deploy_path', '/var/www/shopware') // This is the path where deployer will create its directory structure |
|
16
|
|
|
* ->set('http_user', 'www-data') // Not needed, if the `user` is the same, the web server is running with |
|
17
|
|
|
* ->set('http_group', 'www-data') |
|
18
|
|
|
* ->set('writable_mode', 'chmod') |
|
19
|
|
|
* ->set('writable_recursive', true) |
|
20
|
|
|
* ->set('become', 'www-data'); // You might want to change user to execute remote tasks because of access rights of created cache files |
|
21
|
|
|
* ``` |
|
22
|
|
|
* |
|
23
|
|
|
* :::note |
|
24
|
|
|
* Please remember that the installation must be modified so that it can be |
|
25
|
|
|
* [build without database](https://developer.shopware.com/docs/guides/hosting/installation-updates/deployments/build-w-o-db#compiling-the-storefront-without-database). |
|
26
|
|
|
* ::: |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace Deployer; |
|
30
|
|
|
|
|
31
|
|
|
require_once __DIR__ . '/common.php'; |
|
32
|
|
|
|
|
33
|
|
|
add('recipes', ['shopware']); |
|
34
|
|
|
|
|
35
|
|
|
set('bin/console', '{{bin/php}} {{release_or_current_path}}/bin/console'); |
|
36
|
|
|
|
|
37
|
|
|
set('default_timeout', 3600); // Increase when tasks take longer than that. |
|
38
|
|
|
|
|
39
|
|
|
// These files are shared among all releases. |
|
40
|
|
|
set('shared_files', [ |
|
41
|
|
|
'.env.local', |
|
42
|
|
|
'install.lock', |
|
43
|
|
|
'public/.htaccess', |
|
44
|
|
|
'public/.user.ini', |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
// These directories are shared among all releases. |
|
48
|
|
|
set('shared_dirs', [ |
|
49
|
|
|
'config/jwt', |
|
50
|
|
|
'files', |
|
51
|
|
|
'var/log', |
|
52
|
|
|
'public/media', |
|
53
|
|
|
'public/plugins' |
|
54
|
|
|
'public/thumbnail', |
|
|
|
|
|
|
55
|
|
|
'public/sitemap', |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
// These directories are made writable (the definition of "writable" requires attention). |
|
59
|
|
|
// Please note that the files in `config/jwt/*` receive special attention in the `sw:writable:jwt` task. |
|
60
|
|
|
set('writable_dirs', [ |
|
61
|
|
|
'config/jwt', |
|
62
|
|
|
'custom/plugins', |
|
63
|
|
|
'files', |
|
64
|
|
|
'public/bundles', |
|
65
|
|
|
'public/css', |
|
66
|
|
|
'public/fonts', |
|
67
|
|
|
'public/js', |
|
68
|
|
|
'public/media', |
|
69
|
|
|
'public/plugins' |
|
70
|
|
|
'public/sitemap', |
|
71
|
|
|
'public/theme', |
|
72
|
|
|
'public/thumbnail', |
|
73
|
|
|
'var', |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
|
|
// This sets the Shopware version to the version of the Shopware console command. |
|
77
|
|
|
set('shopware_version', function () { |
|
78
|
|
|
$versionOutput = run('cd {{release_path}} && {{bin/console}} -V'); |
|
79
|
|
|
preg_match('/(\d+\.\d+\.\d+\.\d+)/', $versionOutput, $matches); |
|
80
|
|
|
return $matches[0] ?? '6.6.0'; |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
// This task remotely executes the `cache:clear` console command on the target server. |
|
84
|
|
|
task('sw:cache:clear', static function () { |
|
85
|
|
|
run('cd {{release_path}} && {{bin/console}} cache:clear --no-warmup'); |
|
86
|
|
|
}); |
|
87
|
|
|
|
|
88
|
|
|
// This task remotely executes the cache warmup console commands on the target server, so that the first user, who |
|
89
|
|
|
// visits the website, doesn't have to wait for the cache to be built up. |
|
90
|
|
|
task('sw:cache:warmup', static function () { |
|
91
|
|
|
run('cd {{release_path}} && {{bin/console}} cache:warmup'); |
|
92
|
|
|
|
|
93
|
|
|
// Shopware 6.6+ dropped support for the http:cache:warmup command, so only execute it if the version is less than 6.6 |
|
94
|
|
|
if (version_compare(get('shopware_version'), '6.6.0') < 0) { |
|
95
|
|
|
run('cd {{release_path}} && {{bin/console}} http:cache:warm:up'); |
|
96
|
|
|
} |
|
97
|
|
|
}); |
|
98
|
|
|
|
|
99
|
|
|
// This task remotely executes the `database:migrate` console command on the target server. |
|
100
|
|
|
task('sw:database:migrate', static function () { |
|
101
|
|
|
run('cd {{release_path}} && {{bin/console}} database:migrate --all'); |
|
102
|
|
|
}); |
|
103
|
|
|
|
|
104
|
|
|
task('sw:plugin:refresh', function () { |
|
105
|
|
|
run('cd {{release_path}} && {{bin/console}} plugin:refresh'); |
|
106
|
|
|
}); |
|
107
|
|
|
|
|
108
|
|
|
task('sw:scheduled-task:register', function () { |
|
109
|
|
|
run('cd {{release_path}} && {{bin/console}} scheduled-task:register'); |
|
110
|
|
|
}); |
|
111
|
|
|
|
|
112
|
|
|
task('sw:theme:refresh', function () { |
|
113
|
|
|
run('cd {{release_path}} && {{bin/console}} theme:refresh'); |
|
114
|
|
|
}); |
|
115
|
|
|
|
|
116
|
|
|
// This task is not used by default, but can be used, e.g. in combination with `SHOPWARE_SKIP_THEME_COMPILE=1`, |
|
117
|
|
|
// to build the theme remotely instead of locally. |
|
118
|
|
|
task('sw:theme:compile', function () { |
|
119
|
|
|
run('cd {{release_path}} && {{bin/console}} theme:compile'); |
|
120
|
|
|
}); |
|
121
|
|
|
|
|
122
|
|
|
function getPlugins(): array |
|
123
|
|
|
{ |
|
124
|
|
|
$output = run('cd {{release_path}} && {{bin/console}} plugin:list --json'); |
|
125
|
|
|
$plugins = json_decode($output); |
|
126
|
|
|
|
|
127
|
|
|
return $plugins; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
task('sw:plugin:update:all', static function () { |
|
131
|
|
|
$plugins = getPlugins(); |
|
132
|
|
|
foreach ($plugins as $plugin) { |
|
133
|
|
|
if ($plugin->installedAt && $plugin->upgradeVersion) { |
|
134
|
|
|
writeln("<info>Running plugin update for " . $plugin->name . "</info>\n"); |
|
135
|
|
|
run("cd {{release_path}} && {{bin/console}} plugin:update " . $plugin->name); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
}); |
|
139
|
|
|
|
|
140
|
|
|
task('sw:writable:jwt', static function () { |
|
141
|
|
|
if (!test('[ -d {{deploy_path}}/config/jwt/ ]')) { |
|
142
|
|
|
return; |
|
143
|
|
|
} |
|
144
|
|
|
run('cd {{release_path}} && chmod -R 660 config/jwt/*'); |
|
145
|
|
|
}); |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Grouped SW deploy tasks. |
|
149
|
|
|
*/ |
|
150
|
|
|
task('sw:deploy', [ |
|
151
|
|
|
'sw:database:migrate', |
|
152
|
|
|
'sw:plugin:refresh', |
|
153
|
|
|
'sw:theme:refresh', |
|
154
|
|
|
'sw:scheduled-task:register', |
|
155
|
|
|
'sw:cache:clear', |
|
156
|
|
|
'sw:plugin:update:all', |
|
157
|
|
|
'sw:cache:clear', |
|
158
|
|
|
]); |
|
159
|
|
|
|
|
160
|
|
|
desc('Deploys your project'); |
|
161
|
|
|
task('deploy', [ |
|
162
|
|
|
'deploy:prepare', |
|
163
|
|
|
'sw:writable:jwt', |
|
164
|
|
|
'sw:deploy', |
|
165
|
|
|
'deploy:clear_paths', |
|
166
|
|
|
'sw:cache:warmup', |
|
167
|
|
|
'deploy:publish', |
|
168
|
|
|
]); |
|
169
|
|
|
|
|
170
|
|
|
task('deploy:update_code')->setCallback(static function () { |
|
171
|
|
|
upload('.', '{{release_path}}', [ |
|
172
|
|
|
'options' => [ |
|
173
|
|
|
'--exclude=.git', |
|
174
|
|
|
'--exclude=deploy.php', |
|
175
|
|
|
'--exclude=node_modules', |
|
176
|
|
|
], |
|
177
|
|
|
]); |
|
178
|
|
|
}); |
|
179
|
|
|
|
|
180
|
|
|
task('sw-build-without-db:get-remote-config', static function () { |
|
181
|
|
|
if (!test('[ -d {{current_path}} ]')) { |
|
182
|
|
|
return; |
|
183
|
|
|
} |
|
184
|
|
|
within('{{current_path}}', function () { |
|
185
|
|
|
run('{{bin/php}} ./bin/console bundle:dump'); |
|
186
|
|
|
download('{{current_path}}/var/plugins.json', './var/'); |
|
187
|
|
|
|
|
188
|
|
|
run('{{bin/php}} ./bin/console theme:dump -n'); |
|
189
|
|
|
download('{{current_path}}/files/theme-config', './files/'); |
|
190
|
|
|
}); |
|
191
|
|
|
}); |
|
192
|
|
|
|
|
193
|
|
|
task('sw-build-without-db:build', static function () { |
|
194
|
|
|
runLocally('CI=1 SHOPWARE_SKIP_BUNDLE_DUMP=1 ./bin/build-js.sh'); |
|
195
|
|
|
}); |
|
196
|
|
|
|
|
197
|
|
|
task('sw-build-without-db', [ |
|
198
|
|
|
'sw-build-without-db:get-remote-config', |
|
199
|
|
|
'sw-build-without-db:build', |
|
200
|
|
|
]); |
|
201
|
|
|
|
|
202
|
|
|
before('deploy:update_code', 'sw-build-without-db'); |
|
203
|
|
|
|