2020-05-29 13:52:24 +02:00
|
|
|
<?php
|
2021-11-05 15:33:35 +01:00
|
|
|
/**
|
|
|
|
* ## Usage
|
|
|
|
*
|
|
|
|
* Add {{repository}} to your _deploy.php_ file:
|
|
|
|
*
|
|
|
|
* ```php
|
|
|
|
* set('repository', 'git@github.com:shopware/production.git');
|
|
|
|
* ```
|
|
|
|
*
|
2023-04-29 12:47:42 +02:00
|
|
|
* configure host:
|
|
|
|
* host('SSH-HOSTNAME')
|
2023-10-24 17:06:56 +02:00
|
|
|
* ->set('remote_user', 'SSH-USER')
|
2023-04-29 12:47:42 +02:00
|
|
|
* ->set('deploy_path', '/var/www/shopware') // This is the path, where deployer will create its directory structure
|
2023-10-24 17:06:56 +02:00
|
|
|
* ->set('http_user', 'www-data') // Not needed, if the `user` is the same user, the webserver is running with
|
|
|
|
* ->set('http_group', 'www-data')
|
|
|
|
* ->set('writable_mode', 'chmod')
|
|
|
|
* ->set('writable_recursive', true)
|
|
|
|
* ->set('become', 'www-data'); // You might want to change user to execute remote tasks because of access rights of created cache files
|
2023-04-29 12:47:42 +02:00
|
|
|
*
|
2021-11-06 19:02:51 +01:00
|
|
|
* :::note
|
2021-11-05 15:33:35 +01:00
|
|
|
* Please remember that the installation must be modified so that it can be
|
|
|
|
* [build without database](https://developer.shopware.com/docs/guides/hosting/installation-updates/deployments/build-w-o-db#compiling-the-storefront-without-database).
|
2021-11-06 19:02:51 +01:00
|
|
|
* :::
|
2021-11-05 15:33:35 +01:00
|
|
|
*/
|
2020-05-29 13:52:24 +02:00
|
|
|
namespace Deployer;
|
|
|
|
|
2021-03-08 13:53:51 +01:00
|
|
|
require_once __DIR__ . '/common.php';
|
|
|
|
|
2020-10-25 16:00:05 +01:00
|
|
|
add('recipes', ['shopware']);
|
|
|
|
|
2023-02-24 18:22:55 +01:00
|
|
|
set('bin/console', '{{bin/php}} {{release_or_current_path}}/bin/console');
|
2020-08-31 09:32:00 +02:00
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
set('default_timeout', 3600); // Increase when tasks take longer than that.
|
|
|
|
|
|
|
|
// These files are shared among all releases.
|
2020-05-29 13:52:24 +02:00
|
|
|
set('shared_files', [
|
2024-04-16 11:18:11 +02:00
|
|
|
'.env.local',
|
2021-11-05 15:33:35 +01:00
|
|
|
'install.lock',
|
|
|
|
'public/.htaccess',
|
|
|
|
'public/.user.ini',
|
2020-05-29 13:52:24 +02:00
|
|
|
]);
|
2021-11-05 15:33:35 +01:00
|
|
|
|
|
|
|
// These directories are shared among all releases.
|
2020-05-29 13:52:24 +02:00
|
|
|
set('shared_dirs', [
|
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
|
|
|
]);
|
2021-11-05 15:33:35 +01:00
|
|
|
|
|
|
|
// These directories are made writable (the definition of "writable" requires attention).
|
|
|
|
// Please note that the files in `config/jwt/*` receive special attention in the `sw:writable:jwt` task.
|
2020-05-29 13:52:24 +02:00
|
|
|
set('writable_dirs', [
|
2021-11-05 15:33:35 +01:00
|
|
|
'config/jwt',
|
2020-08-06 13:22:03 +02:00
|
|
|
'custom/plugins',
|
|
|
|
'files',
|
2021-11-05 15:33:35 +01:00
|
|
|
'public/bundles',
|
|
|
|
'public/css',
|
|
|
|
'public/fonts',
|
|
|
|
'public/js',
|
2020-05-29 13:52:24 +02:00
|
|
|
'public/media',
|
2020-09-03 15:15:56 +02:00
|
|
|
'public/sitemap',
|
2021-11-05 15:33:35 +01:00
|
|
|
'public/theme',
|
|
|
|
'public/thumbnail',
|
|
|
|
'var',
|
2020-05-29 13:52:24 +02:00
|
|
|
]);
|
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
// This task remotely executes the `cache:clear` console command on the target server.
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:cache:clear', static function () {
|
2023-03-07 23:22:45 +01:00
|
|
|
run('cd {{release_path}} && {{bin/console}} cache:clear --no-warmup');
|
2020-08-06 12:28:39 +02:00
|
|
|
});
|
2021-11-05 15:33:35 +01:00
|
|
|
|
|
|
|
// This task remotely executes the cache warmup console commands on the target server, so that the first user, who
|
|
|
|
// visits the website, doesn't have to wait for the cache to be built up.
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:cache:warmup', static function () {
|
2023-02-24 18:22:55 +01: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
|
|
|
});
|
2021-11-05 15:33:35 +01:00
|
|
|
|
|
|
|
// This task remotely executes the `database:migrate` console command on the target server.
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:database:migrate', static function () {
|
2023-02-24 18:22:55 +01:00
|
|
|
run('cd {{release_path}} && {{bin/console}} database:migrate --all');
|
2020-08-06 12:28:39 +02:00
|
|
|
});
|
2021-11-05 15:33:35 +01:00
|
|
|
|
2021-02-23 08:50:46 +01:00
|
|
|
task('sw:plugin:refresh', function () {
|
2023-02-24 18:22:55 +01:00
|
|
|
run('cd {{release_path}} && {{bin/console}} plugin:refresh');
|
2020-09-10 16:13:52 +02:00
|
|
|
});
|
2021-04-13 15:31:51 +02:00
|
|
|
|
2023-09-07 23:12:26 +02:00
|
|
|
task('sw:scheduled-task:register', function () {
|
|
|
|
run('cd {{release_path}} && {{bin/console}} scheduled-task:register');
|
|
|
|
});
|
|
|
|
|
2023-03-07 23:23:14 +01:00
|
|
|
task('sw:theme:refresh', function () {
|
|
|
|
run('cd {{release_path}} && {{bin/console}} theme:refresh');
|
|
|
|
});
|
|
|
|
|
2023-10-24 17:06:56 +02:00
|
|
|
// This task is not used per default, but can be used, e.g. in combination with `SHOPWARE_SKIP_THEME_COMPILE=1`,
|
|
|
|
// to build the theme remotely instead of locally.
|
2023-04-29 12:47:42 +02:00
|
|
|
task('sw:theme:compile', function () {
|
|
|
|
run('cd {{release_path}} && {{bin/console}} theme:compile');
|
|
|
|
});
|
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
function getPlugins(): array
|
2021-02-23 08:50:46 +01:00
|
|
|
{
|
2024-02-16 12:51:35 +01:00
|
|
|
$output = run('cd {{release_path}} && {{bin/console}} plugin:list --json');
|
|
|
|
$plugins = json_decode($output);
|
2021-02-23 08:50:46 +01:00
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
return $plugins;
|
2021-02-23 08:50:46 +01:00
|
|
|
}
|
2020-09-09 14:32:52 +02:00
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
task('sw:plugin:update:all', static function () {
|
|
|
|
$plugins = getPlugins();
|
|
|
|
foreach ($plugins as $plugin) {
|
2024-02-16 12:51:35 +01:00
|
|
|
if ($plugin->installedAt && $plugin->upgradeVersion) {
|
|
|
|
writeln("<info>Running plugin update for " . $plugin->name . "</info>\n");
|
|
|
|
run("cd {{release_path}} && {{bin/console}} plugin:update " . $plugin->name);
|
2020-09-09 14:32:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-06-24 20:16:26 +02:00
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
task('sw:writable:jwt', static function () {
|
|
|
|
run('cd {{release_path}} && chmod -R 660 config/jwt/*');
|
2021-04-13 15:31:51 +02:00
|
|
|
});
|
|
|
|
|
2020-08-31 09:32:00 +02:00
|
|
|
/**
|
2021-11-05 15:33:35 +01:00
|
|
|
* Grouped SW deploy tasks.
|
2020-08-31 09:32:00 +02:00
|
|
|
*/
|
2020-09-03 15:15:56 +02:00
|
|
|
task('sw:deploy', [
|
2020-08-06 12:28:39 +02:00
|
|
|
'sw:database:migrate',
|
2021-11-05 15:33:35 +01:00
|
|
|
'sw:plugin:refresh',
|
2023-09-07 23:12:26 +02:00
|
|
|
'sw:theme:refresh',
|
|
|
|
'sw:scheduled-task:register',
|
2021-11-05 15:33:35 +01:00
|
|
|
'sw:cache:clear',
|
|
|
|
'sw:plugin:update:all',
|
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
|
|
|
|
2021-11-08 22:59:39 +01:00
|
|
|
desc('Deploys 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',
|
2021-11-05 15:33:35 +01:00
|
|
|
'sw:writable:jwt',
|
2020-10-08 01:53:45 +02:00
|
|
|
'deploy:publish',
|
2020-10-29 23:16:36 +01:00
|
|
|
]);
|
2021-11-05 15:33:35 +01:00
|
|
|
|
2024-04-18 17:24:58 +02:00
|
|
|
task('deploy:update_code')->setCallback(static function () {
|
|
|
|
upload('.', '{{release_path}}', [
|
|
|
|
'options' => [
|
|
|
|
'--exclude=.git',
|
|
|
|
'--exclude=deploy.php',
|
|
|
|
'--exclude=node_modules',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-11-05 15:33:35 +01:00
|
|
|
task('sw-build-without-db:get-remote-config', static function () {
|
2021-11-18 20:28:00 +01:00
|
|
|
if (!test('[ -d {{current_path}} ]')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-05 15:33:35 +01:00
|
|
|
within('{{deploy_path}}/current', function () {
|
2023-02-24 18:22:55 +01:00
|
|
|
run('{{bin/php}} ./bin/console bundle:dump');
|
2021-11-05 15:33:35 +01:00
|
|
|
download('{{deploy_path}}/current/var/plugins.json', './var/');
|
|
|
|
|
2023-02-24 18:22:55 +01:00
|
|
|
run('{{bin/php}} ./bin/console theme:dump');
|
2021-11-05 15:33:35 +01:00
|
|
|
download('{{deploy_path}}/current/files/theme-config', './files/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
task('sw-build-without-db:build', static function () {
|
2023-10-24 17:06:56 +02:00
|
|
|
runLocally('CI=1 SHOPWARE_SKIP_BUNDLE_DUMP=1 ./bin/build-js.sh');
|
2021-11-05 15:33:35 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
task('sw-build-without-db', [
|
|
|
|
'sw-build-without-db:get-remote-config',
|
|
|
|
'sw-build-without-db:build',
|
|
|
|
]);
|
|
|
|
|
|
|
|
before('deploy:update_code', 'sw-build-without-db');
|