2020-05-29 13:52:24 +02:00
|
|
|
<?php
|
2021-02-23 08:50:46 +01:00
|
|
|
|
2020-05-29 13:52:24 +02:00
|
|
|
namespace Deployer;
|
|
|
|
|
2021-02-23 08:50:46 +01:00
|
|
|
use MJS\TopSort\Implementations\FixedArraySort;
|
|
|
|
|
2020-10-25 16:00:05 +01:00
|
|
|
add('recipes', ['shopware']);
|
|
|
|
|
2020-05-29 13:52:24 +02:00
|
|
|
set('repository', 'git@github.com:shopware/production.git');
|
|
|
|
|
2020-09-03 15:15:56 +02:00
|
|
|
set('release_name', static function () {
|
2020-08-31 09:32:00 +02:00
|
|
|
return date('YmdHis');
|
|
|
|
});
|
|
|
|
|
2020-05-29 13:52:24 +02:00
|
|
|
set('shared_files', [
|
2020-09-03 15:15:56 +02:00
|
|
|
'.env',
|
2020-05-29 13:52:24 +02:00
|
|
|
]);
|
|
|
|
set('shared_dirs', [
|
2020-08-06 13:22:03 +02:00
|
|
|
'custom/plugins',
|
2020-06-24 20:16:26 +02:00
|
|
|
'config/jwt',
|
2020-08-06 13:22:03 +02:00
|
|
|
'files',
|
|
|
|
'var/log',
|
2020-05-29 13:52:24 +02:00
|
|
|
'public/media',
|
2020-06-24 20:16:26 +02:00
|
|
|
'public/thumbnail',
|
2020-08-06 13:22:03 +02:00
|
|
|
'public/sitemap',
|
2020-05-29 13:52:24 +02:00
|
|
|
]);
|
|
|
|
set('writable_dirs', [
|
2020-08-06 13:22:03 +02:00
|
|
|
'custom/plugins',
|
|
|
|
'files',
|
2020-05-29 13:52:24 +02:00
|
|
|
'var',
|
|
|
|
'public/media',
|
2020-08-06 13:22:03 +02:00
|
|
|
'public/thumbnail',
|
2020-09-03 15:15:56 +02:00
|
|
|
'public/sitemap',
|
2020-05-29 13:52:24 +02:00
|
|
|
]);
|
|
|
|
set('static_folders', []);
|
|
|
|
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:update_code', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('git clone {{repository}} {{release_path}}');
|
2020-05-29 13:52:24 +02:00
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:system:install', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('cd {{release_path}} && bin/console system:install');
|
2020-06-24 20:16:26 +02:00
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:build', static function () {
|
|
|
|
run('cd {{release_path}}/bin && bash build.sh');
|
2020-06-24 20:16:26 +02:00
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:system:setup', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('cd {{release_path}} && bin/console system:setup');
|
2020-06-24 20:16:26 +02:00
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:theme:compile', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('cd {{release_path}} && bin/console theme:compile');
|
2020-05-29 13:52:24 +02:00
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:cache:clear', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('cd {{release_path}} && bin/console cache:clear');
|
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:cache:warmup', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('cd {{release_path}} && bin/console cache:warmup');
|
|
|
|
run('cd {{release_path}} && bin/console http:cache:warm:up');
|
2020-05-29 13:52:24 +02:00
|
|
|
});
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:database:migrate', static function () {
|
2020-08-06 12:28:39 +02:00
|
|
|
run('cd {{release_path}} && bin/console database:migrate --all');
|
|
|
|
});
|
2021-02-23 08:50:46 +01:00
|
|
|
task('sw:plugin:refresh', function () {
|
2020-09-10 16:13:52 +02:00
|
|
|
run('cd {{release_path}} && bin/console plugin:refresh');
|
|
|
|
});
|
2021-02-23 08:50:46 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
* @throws \MJS\TopSort\CircularDependencyException
|
|
|
|
* @throws \MJS\TopSort\ElementNotFoundException
|
|
|
|
*/
|
|
|
|
function getSortedPlugins(): array
|
|
|
|
{
|
|
|
|
cd('{{release_path}}');
|
|
|
|
$plugins = explode("\n", run('bin/console plugin:list'));
|
2020-09-09 14:32:52 +02:00
|
|
|
|
2020-09-10 16:13:52 +02:00
|
|
|
// take line over headlines and count "-" to get the size of the cells
|
2020-09-09 14:32:52 +02:00
|
|
|
$lengths = array_filter(array_map('strlen', explode(' ', $plugins[4])));
|
|
|
|
|
2020-09-10 16:13:52 +02:00
|
|
|
// ignore first seven lines (headline, title, table, ...)
|
2020-09-09 14:32:52 +02:00
|
|
|
$plugins = array_slice($plugins, 7, -3);
|
2021-02-23 08:50:46 +01:00
|
|
|
$parsedPlugins = [];
|
2020-09-09 14:32:52 +02:00
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
$pluginParts = [];
|
|
|
|
foreach ($lengths as $length) {
|
|
|
|
$pluginParts[] = trim(substr($plugin, 0, $length));
|
|
|
|
$plugin = substr($plugin, $length + 1);
|
|
|
|
}
|
2021-02-23 08:50:46 +01:00
|
|
|
$parsedPlugins[$pluginParts[0]] = $pluginParts;
|
|
|
|
}
|
|
|
|
|
|
|
|
$composer = json_decode(run('cat composer.lock'), true);
|
|
|
|
|
|
|
|
$pluginMapping = $dependencies = [];
|
|
|
|
foreach ($parsedPlugins as $plugin) {
|
|
|
|
$pluginName = $plugin[0];
|
|
|
|
// collect cpmposer plugin names
|
|
|
|
foreach ($composer['packages'] as $config) {
|
|
|
|
if (!isset($config['extra']['shopware-plugin-class'])) {
|
|
|
|
// we only collect a mapping for shopware modules name <-> composer name
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str_ends_with($config['extra']['shopware-plugin-class'], $pluginName)) {
|
|
|
|
$pluginMapping[$config['name']] = $pluginName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// collect dependencies
|
|
|
|
foreach ($composer['packages'] as $config) {
|
|
|
|
if (!isset($pluginMapping[$config['name']])) {
|
|
|
|
// if the composer.json doesn't belong to a shopware module
|
|
|
|
// or doesn't have dependencies, ignore it
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$dependencies[$config['name']] = array_filter(array_keys($config['require'] ?? []),
|
|
|
|
static function ($composerName) use ($pluginMapping) {
|
|
|
|
// only add dependencies between shopware modules
|
|
|
|
return isset($pluginMapping[$composerName]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sorter = new FixedArraySort();
|
|
|
|
foreach ($dependencies as $name => $dep) {
|
|
|
|
$sorter->add($name, $dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_map(static function ($name) use ($parsedPlugins, $pluginMapping) {
|
|
|
|
return $parsedPlugins[$pluginMapping[$name]];
|
|
|
|
}, $sorter->sort());
|
|
|
|
}
|
2020-09-09 14:32:52 +02:00
|
|
|
|
2021-02-23 08:50:46 +01:00
|
|
|
task('sw:plugin:activate:all', static function () {
|
|
|
|
invoke('sw:plugin:refresh');
|
|
|
|
|
|
|
|
foreach (getSortedPlugins() as $pluginInfo) {
|
2020-09-09 14:32:52 +02:00
|
|
|
[
|
|
|
|
$plugin,
|
|
|
|
$label,
|
|
|
|
$version,
|
|
|
|
$upgrade,
|
|
|
|
$author,
|
|
|
|
$installed,
|
|
|
|
$active,
|
|
|
|
$upgradeable,
|
2021-02-23 08:50:46 +01:00
|
|
|
] = $pluginInfo;
|
2020-09-09 14:32:52 +02:00
|
|
|
|
|
|
|
if ($installed === 'No' || $active === 'No') {
|
|
|
|
run("cd {{release_path}} && bin/console plugin:install --activate $plugin");
|
|
|
|
}
|
2020-09-10 16:13:52 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-23 08:50:46 +01:00
|
|
|
task('sw:plugin:migrate:all', static function () {
|
|
|
|
invoke('sw:plugin:refresh');
|
|
|
|
foreach (getSortedPlugins() as $pluginInfo) {
|
2020-09-10 16:13:52 +02:00
|
|
|
[
|
|
|
|
$plugin,
|
|
|
|
$label,
|
|
|
|
$version,
|
|
|
|
$upgrade,
|
|
|
|
$author,
|
|
|
|
$installed,
|
|
|
|
$active,
|
|
|
|
$upgradeable,
|
2021-02-23 08:50:46 +01:00
|
|
|
] = $pluginInfo;
|
2020-09-09 14:32:52 +02:00
|
|
|
|
2020-09-10 16:13:52 +02:00
|
|
|
if ($installed === 'Yes' || $active === 'Yes') {
|
|
|
|
run("cd {{release_path}} && bin/console database:migrate --all $plugin || true");
|
2020-09-09 14:32:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-06-24 20:16:26 +02:00
|
|
|
|
2020-08-31 09:32:00 +02:00
|
|
|
/**
|
|
|
|
* Grouped SW deploy tasks
|
|
|
|
*/
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:deploy', [
|
2020-08-31 09:32:00 +02:00
|
|
|
'sw:build',
|
2020-09-10 16:13:52 +02:00
|
|
|
'sw:plugin:activate:all',
|
2020-08-06 12:28:39 +02:00
|
|
|
'sw:database:migrate',
|
2020-09-10 16:13:52 +02:00
|
|
|
'sw:plugin:migrate:all',
|
2020-06-24 20:16:26 +02:00
|
|
|
'sw:theme:compile',
|
2020-09-03 15:15:56 +02:00
|
|
|
'sw:cache:clear',
|
2020-06-24 20:16:26 +02:00
|
|
|
]);
|
2020-08-31 09:32:00 +02:00
|
|
|
|
2020-05-29 13:52:24 +02:00
|
|
|
/**
|
|
|
|
* Main task
|
|
|
|
*/
|
2020-10-29 23:16:36 +01:00
|
|
|
desc('Deploy your project');
|
2020-05-29 13:52:24 +02:00
|
|
|
task('deploy', [
|
|
|
|
'deploy:prepare',
|
2020-06-24 20:16:26 +02:00
|
|
|
'sw:deploy',
|
2020-05-29 13:52:24 +02:00
|
|
|
'deploy:clear_paths',
|
2020-08-06 12:28:39 +02:00
|
|
|
'sw:cache:warmup',
|
2020-10-08 01:53:45 +02:00
|
|
|
'deploy:publish',
|
2020-10-29 23:16:36 +01:00
|
|
|
]);
|