Skip to content

Commit dd0b023

Browse files
authored
Merge pull request #16 from ByteInternet/new_configuration_api
New way of defining deploy strategies based on deployer
2 parents 12b0332 + 8c9207b commit dd0b023

File tree

14 files changed

+383
-386
lines changed

14 files changed

+383
-386
lines changed

recipes/magento1.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Deployer;
4+
5+
use Hypernode\DeployConfiguration\RecipeLoader;
6+
7+
RecipeLoader::get()->loadRecipe('common.php');
8+
9+
add('recipes', ['magento1']);
10+
11+
set('default_timeout', 3600); // Increase when tasks take longer than that.
12+
13+
// These files are shared among all releases.
14+
set('shared_files', [
15+
'app/etc/local.xml',
16+
'errors/local.xml',
17+
]);
18+
19+
// These directories are shared among all releases.
20+
set('shared_dirs', [
21+
'media',
22+
'sitemap',
23+
'var',
24+
]);
25+
26+
// These directories are made writable (the definition of "writable" requires attention).
27+
set('writable_dirs', [
28+
'media',
29+
'sitemap',
30+
'var',
31+
]);
32+
33+
task('magento1:maintenance_mode:enable', static function () {
34+
if (has('previous_release') && test('[ -f {{previous_release}}/{{public_folder}}/.maintenance.flag ]')) {
35+
run('touch {{public_folder}}/.maintenance.flag');
36+
}
37+
});
38+
39+
task('magento1:sys:setup:run', static function () {
40+
run('magerun sys:setup:run');
41+
});
42+
43+
task('magento1:cache:flush', static function () {
44+
run('magerun cache:flush');
45+
});

recipes/shopware6.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Deployer;
4+
5+
use Hypernode\DeployConfiguration\RecipeLoader;
6+
7+
RecipeLoader::get()->loadRecipe('common.php');
8+
9+
add('recipes', ['shopware']);
10+
11+
set('default_timeout', 3600); // Increase when tasks take longer than that.
12+
13+
// These files are shared among all releases.
14+
set('shared_files', [
15+
'.env',
16+
'install.lock',
17+
'public/.htaccess',
18+
'public/.user.ini',
19+
]);
20+
21+
// These directories are shared among all releases.
22+
set('shared_dirs', [
23+
'config/jwt',
24+
'files',
25+
'var/log',
26+
'public/media',
27+
'public/thumbnail',
28+
'public/sitemap',
29+
]);
30+
31+
// These directories are made writable (the definition of "writable" requires attention).
32+
// Please note that the files in `config/jwt/*` receive special attention in the `sw:writable:jwt` task.
33+
set('writable_dirs', [
34+
'config/jwt',
35+
'custom/plugins',
36+
'files',
37+
'public/bundles',
38+
'public/css',
39+
'public/fonts',
40+
'public/js',
41+
'public/media',
42+
'public/sitemap',
43+
'public/theme',
44+
'public/thumbnail',
45+
'var',
46+
]);
47+
48+
task('sw:deploy:vendors_recovery', static function () {
49+
run('{{bin/composer}} {{composer_action}} -d vendor/shopware/recovery {{composer_options}} 2>&1');
50+
});
51+
52+
// This task remotely executes the `cache:clear` console command on the target server.
53+
task('sw:cache:clear', static function () {
54+
run('cd {{release_path}} && bin/console cache:clear');
55+
});
56+
57+
// This task remotely executes the cache warmup console commands on the target server, so that the first user, who
58+
// visits the website, doesn't have to wait for the cache to be built up.
59+
task('sw:cache:warmup', static function () {
60+
run('cd {{release_path}} && bin/console cache:warmup');
61+
run('cd {{release_path}} && bin/console http:cache:warm:up');
62+
});
63+
64+
// This task remotely executes the `database:migrate` console command on the target server.
65+
task('sw:database:migrate', static function () {
66+
run('cd {{release_path}} && bin/console database:migrate --all');
67+
});
68+
69+
task('sw:writable:jwt', static function () {
70+
run('cd {{release_path}} && chmod -R 660 config/jwt/*');
71+
});
72+
73+
task('sw:build', static function () {
74+
run('./bin/build.sh');
75+
});
76+
77+
task('sw:touch_install_lock', static function () {
78+
run('touch install.lock');
79+
});

src/ApplicationTemplate/Magento1.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
namespace Hypernode\DeployConfiguration\ApplicationTemplate;
44

5-
use Hypernode\DeployConfiguration\ClusterSharedFolder;
65
use Hypernode\DeployConfiguration\Configuration;
7-
use Hypernode\DeployConfiguration\Command;
8-
use Hypernode\DeployConfiguration\SharedFolder;
96

107
class Magento1 extends Configuration
118
{
12-
/**
13-
* Magento1 constructor.
14-
*
15-
* @param string $gitRepository
16-
*/
17-
public function __construct(string $gitRepository)
9+
public function __construct()
1810
{
19-
parent::__construct($gitRepository);
11+
parent::__construct();
2012

2113
$this->initializeDefaultConfiguration();
2214
}
@@ -26,20 +18,22 @@ public function __construct(string $gitRepository)
2618
*/
2719
private function initializeDefaultConfiguration(): void
2820
{
29-
$this->addBuildCommand(new Command\Build\Composer());
30-
$this->addDeployCommand(new Command\Deploy\Magento1\MaintenanceMode());
31-
$this->addDeployCommand(new Command\Deploy\Magento1\MagerunSetupRun());
32-
$this->addDeployCommand(new Command\Deploy\Magento1\MagerunCacheFlush());
21+
$this->setRecipe('magento1');
22+
23+
$this->addBuildTask('deploy:vendors');
24+
$this->addDeployTask('magento1:maintenance_mode:enable');
25+
$this->addDeployTask('magento1:sys:setup:run');
26+
$this->addDeployTask('magento1:cache:flush');
3327

3428
$this->setSharedFiles([
3529
'app/etc/local.xml',
3630
'errors/local.xml',
3731
]);
3832

3933
$this->setSharedFolders([
40-
new SharedFolder('var'),
41-
new ClusterSharedFolder('media'),
42-
new ClusterSharedFolder('sitemap'),
34+
'var',
35+
'media',
36+
'sitemap',
4337
]);
4438
}
4539
}

src/ApplicationTemplate/Magento2.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,50 @@
22

33
namespace Hypernode\DeployConfiguration\ApplicationTemplate;
44

5-
use Hypernode\DeployConfiguration\ClusterSharedFolder;
65
use Hypernode\DeployConfiguration\Configuration;
7-
use Hypernode\DeployConfiguration\Command;
8-
use Hypernode\DeployConfiguration\SharedFolder;
96

107
class Magento2 extends Configuration
118
{
129
/**
13-
* Magento2 constructor.
14-
*
15-
* @param string $gitRepository
16-
* @param array|null $localesFrontend
17-
* @param array|null $localesBackend
10+
* @param string[] $locales
1811
*/
19-
public function __construct(string $gitRepository, array $localesFrontend, array $localesBackend)
12+
public function __construct(array $locales)
2013
{
21-
parent::__construct($gitRepository);
14+
parent::__construct();
2215

23-
$this->initializeDefaultConfiguration($localesFrontend, $localesBackend);
16+
$this->initializeDefaultConfiguration($locales);
2417
}
2518

2619
/**
2720
* Initialize defaults
2821
*
29-
* @param array|null $localesFrontend
30-
* @param array|null $localesBackend
22+
* @param string[] $locales
3123
*/
32-
private function initializeDefaultConfiguration(array $localesFrontend = null, array $localesBackend = null): void
24+
private function initializeDefaultConfiguration(array $locales): void
3325
{
34-
$this->setPhpVersion('php71');
35-
$this->addBuildCommand(new Command\Build\Composer());
36-
$this->addBuildCommand(new Command\Build\Magento2\SetupDiCompile());
37-
$this->addBuildCommand(new Command\Build\Magento2\SetupStaticContentDeploy($localesFrontend, 'frontend'));
38-
$this->addBuildCommand(new Command\Build\Magento2\SetupStaticContentDeploy($localesBackend, 'adminhtml'));
26+
$this->setRecipe('magento2');
27+
$this->setVariable('static_content_locales', $locales);
28+
$this->setVariable('ENV', ['MAGE_MODE' => 'production'], 'build');
29+
30+
$this->addBuildTask('deploy:vendors');
31+
$this->addBuildTask('magento:compile');
32+
$this->addBuildTask('magento:deploy:assets');
3933

40-
$this->addDeployCommand(new Command\Deploy\Magento2\MaintenanceMode());
41-
$this->addDeployCommand(new Command\Deploy\Magento2\SetupUpgrade());
42-
$this->addDeployCommand(new Command\Deploy\Magento2\CacheFlush());
34+
$this->addDeployTask('magento:config:import');
35+
$this->addDeployTask('magento:upgrade:db');
36+
$this->addDeployTask('magento:cache:flush');
4337

4438
$this->setSharedFiles([
4539
'app/etc/env.php',
4640
'pub/errors/local.xml',
41+
'pub/.user.ini',
4742
]);
4843

4944
$this->setSharedFolders([
50-
new SharedFolder('var/log'),
51-
new SharedFolder('var/report'),
52-
new ClusterSharedFolder('var/session'),
53-
new ClusterSharedFolder('pub/media'),
45+
'var/log',
46+
'var/report',
47+
'var/session',
48+
'pub/media',
5449
]);
5550

5651
$this->addDeployExclude('phpserver/');

src/ApplicationTemplate/Shopware6.php

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@
22

33
namespace Hypernode\DeployConfiguration\ApplicationTemplate;
44

5-
use Hypernode\DeployConfiguration\ClusterSharedFolder;
6-
use Hypernode\DeployConfiguration\Command\Build\Composer;
7-
use Hypernode\DeployConfiguration\Command\Build\Shopware6\BuildAdministration;
8-
use Hypernode\DeployConfiguration\Command\Build\Shopware6\BuildStorefront;
9-
use Hypernode\DeployConfiguration\Command\Build\Shopware6\ShopwareRecovery;
10-
use Hypernode\DeployConfiguration\Command\Deploy\Shopware6\AssetInstall;
11-
use Hypernode\DeployConfiguration\Command\Deploy\Shopware6\CacheClear;
12-
use Hypernode\DeployConfiguration\Command\Deploy\Shopware6\ThemeCompile;
135
use Hypernode\DeployConfiguration\Configuration;
14-
use Hypernode\DeployConfiguration\SharedFolder;
156

167
class Shopware6 extends Configuration
178
{
18-
/**
19-
* Shopware6 constructor.
20-
* @param string $gitRepository
21-
*/
22-
public function __construct(string $gitRepository)
9+
public function __construct()
2310
{
24-
parent::__construct($gitRepository);
11+
parent::__construct();
2512

2613
$this->initializeDefaultConfiguration();
2714
}
@@ -32,35 +19,37 @@ public function __construct(string $gitRepository)
3219
*/
3320
private function initializeDefaultConfiguration(): void
3421
{
35-
$this->setPhpVersion('php72');
22+
$this->setRecipe('shopware6');
3623

37-
38-
$this->addBuildCommand(new Composer([
24+
$this->setComposerOptions([
3925
'--verbose',
4026
'--no-progress',
4127
'--no-interaction',
4228
'--optimize-autoloader',
43-
'--ignore-platform-reqs',
44-
]));
29+
]);
4530

46-
$this->addBuildCommand(new ShopwareRecovery());
47-
$this->addBuildCommand(new BuildAdministration());
48-
$this->addBuildCommand(new BuildStorefront());
31+
$this->addBuildTask('deploy:vendors');
32+
$this->addBuildTask('sw:deploy:vendors_recovery');
33+
$this->addBuildTask('sw:touch_install_lock');
4934

50-
$this->addDeployCommand(new AssetInstall());
51-
$this->addDeployCommand(new ThemeCompile());
52-
$this->addDeployCommand(new CacheClear());
35+
$this->addDeployTask('sw:build');
36+
$this->addDeployTask('sw:database:migrate');
37+
$this->addDeployTask('sw:cache:clear');
38+
$this->addDeployTask('sw:cache:warmup');
5339

5440
$this->setSharedFiles([
5541
'.env',
42+
'install.lock',
43+
'public/.user.ini',
5644
]);
5745

5846
$this->setSharedFolders([
59-
new SharedFolder('var/log'),
60-
new ClusterSharedFolder('config/jwt'),
61-
new ClusterSharedFolder('public/sitemap'),
62-
new ClusterSharedFolder('public/media'),
63-
new ClusterSharedFolder('public/thumbnail'),
47+
'config/jwt',
48+
'files',
49+
'var/log',
50+
'public/sitemap',
51+
'public/media',
52+
'public/thumbnail',
6453
]);
6554
}
6655
}

src/ClusterSharedFolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Hypernode\DeployConfiguration;
66

77
/**
8-
* Folder will be shared over releases and all servers within cluster
8+
* @deprecated This class has been deprecated as DaaS configurations have been removed.
99
*/
1010
class ClusterSharedFolder extends SharedFolder
1111
{

0 commit comments

Comments
 (0)