Skip to content

Commit e19c56a

Browse files
MCLOUD-7254: sync_engine native no longer references local folders in v1.2.0 (#33)
1 parent 94d2053 commit e19c56a

File tree

26 files changed

+394
-103
lines changed

26 files changed

+394
-103
lines changed

src/Compose/BuilderInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
interface BuilderInterface
1515
{
16-
public const DIR_MAGENTO = '/app';
16+
public const TARGET_ROOT = '/app';
1717

1818
public const SERVICE_GENERIC = ServiceInterface::SERVICE_GENERIC;
1919
public const SERVICE_DB = 'db';
@@ -41,8 +41,8 @@ interface BuilderInterface
4141

4242
public const VOLUME_DOCKER_MNT = '.docker/mnt';
4343
public const VOLUME_MARIADB_CONF = '.docker/mysql/mariadb.conf.d';
44-
public const VOLUME_MAGENTO_VENDOR = 'magento-vendor';
45-
public const VOLUME_MAGENTO_GENERATED = 'magento-generated';
44+
public const VOLUME_MAGENTO_VENDOR = 'vendor';
45+
public const VOLUME_MAGENTO_GENERATED = 'generated';
4646
public const VOLUME_MAGENTO_DB = 'magento-db';
4747
public const VOLUME_MAGENTO_DB_QUOTE = 'magento-db-quote';
4848
public const VOLUME_MAGENTO_DB_SALES = 'magento-db-sales';

src/Compose/DeveloperBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function __construct(
8585
*/
8686
public function build(Config $config): Manager
8787
{
88-
$volumePrefix = $config->getName() . '-';
88+
$volumePrefix = $config->getNameWithPrefix();
8989

9090
$manager = $this->builderFactory
9191
->create(BuilderFactory::BUILDER_PRODUCTION)
@@ -96,13 +96,13 @@ public function build(Config $config): Manager
9696
$volumePrefix . self::VOLUME_MAGENTO_DB => []
9797
];
9898

99-
$volumes = [$this->volumeResolver->getMagentoVolume($config) . ':' . self::DIR_MAGENTO . ':delegated'];
99+
$volumes = [$this->volumeResolver->getMagentoVolume($config) . ':' . self::TARGET_ROOT . ':delegated'];
100100

101101
if (in_array($syncEngine, [self::SYNC_ENGINE_MUTAGEN, self::SYNC_ENGINE_DOCKER_SYNC], true)) {
102102
$volumesList[$volumePrefix . self::VOLUME_MAGENTO_SYNC] = $syncEngine === self::SYNC_ENGINE_DOCKER_SYNC
103103
? ['external' => true]
104104
: [];
105-
$volumes = [$volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy'];
105+
$volumes = [$volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::TARGET_ROOT . ':nocopy'];
106106
}
107107

108108
$manager->setVolumes($volumesList);

src/Compose/ProductionBuilder.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ public function build(Config $config): Manager
106106

107107
$volumes = [];
108108

109-
foreach (array_keys($this->volumeResolver->getMagentoVolumes(
110-
$config->getMounts(),
111-
false,
112-
$hasGenerated
113-
)) as $volumeName) {
114-
$volumes[$volumeName] = [];
115-
}
109+
if ($config->getSyncEngine() !== self::SYNC_ENGINE_NATIVE) {
110+
foreach (array_keys($this->volumeResolver->getMagentoVolumes(
111+
$config,
112+
false,
113+
$hasGenerated
114+
)) as $volumeName) {
115+
$volumes[$volumeName] = [];
116+
}
116117

117-
$manager->setVolumes($volumes);
118+
$manager->setVolumes($volumes);
119+
}
118120

119121
$manager->addVolume($config->getNameWithPrefix() . BuilderInterface::VOLUME_MAGENTO_DB, []);
120122

src/Compose/ProductionBuilder/Service/Cron.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public function getConfig(Config $config): array
8282
$preparedCronConfig[] = sprintf(
8383
'%s root cd %s && %s >> %s/var/log/cron.log',
8484
$job['schedule'],
85-
BuilderInterface::DIR_MAGENTO,
85+
BuilderInterface::TARGET_ROOT,
8686
str_replace('php ', '/usr/local/bin/php ', $job['command']),
87-
BuilderInterface::DIR_MAGENTO
87+
BuilderInterface::TARGET_ROOT
8888
);
8989
}
9090

src/Compose/ProductionBuilder/Volume.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getRo(Config $config): array
4242
return $this->volumeResolver->normalize(array_merge(
4343
$this->volumeResolver->getRootVolume($config, true),
4444
$this->volumeResolver->getDevVolumes($config, $config->hasServiceEnabled(ServiceInterface::SERVICE_TEST)),
45-
$this->volumeResolver->getMagentoVolumes($config->getMounts(), true, $this->hasGenerated($config)),
45+
$this->volumeResolver->getMagentoVolumes($config, true, $this->hasGenerated($config)),
4646
$this->volumeResolver->getMountVolumes($config->hasTmpMounts())
4747
));
4848
}
@@ -59,7 +59,7 @@ public function getRw(Config $config): array
5959
return $this->volumeResolver->normalize(array_merge(
6060
$this->volumeResolver->getRootVolume($config, false),
6161
$this->volumeResolver->getDevVolumes($config, $config->hasServiceEnabled(ServiceInterface::SERVICE_TEST)),
62-
$this->volumeResolver->getMagentoVolumes($config->getMounts(), false, $this->hasGenerated($config)),
62+
$this->volumeResolver->getMagentoVolumes($config, false, $this->hasGenerated($config)),
6363
$this->volumeResolver->getMountVolumes($config->hasTmpMounts()),
6464
$this->volumeResolver->getComposerVolumes()
6565
));
@@ -76,7 +76,7 @@ public function getBuild(Config $config): array
7676
{
7777
return $this->volumeResolver->normalize(array_merge(
7878
$this->volumeResolver->getRootVolume($config, false),
79-
$this->volumeResolver->getDefaultMagentoVolumes(false, $this->hasGenerated($config)),
79+
$this->volumeResolver->getDefaultMagentoVolumes($config, false, $this->hasGenerated($config)),
8080
$this->volumeResolver->getComposerVolumes()
8181
));
8282
}

src/Compose/ProductionBuilder/VolumeResolver.php

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getRootVolume(Config $config, bool $isReadOnly): array
2727

2828
return [
2929
$this->getMagentoVolume($config) => [
30-
'path' => BuilderInterface::DIR_MAGENTO,
30+
'target' => BuilderInterface::TARGET_ROOT,
3131
'volume' => '/',
3232
'mode' => $mode
3333
]
@@ -44,7 +44,7 @@ public function getDevVolumes(Config $config, bool $hasTest): array
4444
if ($hasTest) {
4545
return [
4646
$this->getMagentoDevVolume($config) => [
47-
'path' => BuilderInterface::DIR_MAGENTO . '/dev',
47+
'target' => BuilderInterface::TARGET_ROOT . '/dev',
4848
'volume' => '/dev',
4949
'mode' => 'rw,delegated'
5050
]
@@ -55,25 +55,35 @@ public function getDevVolumes(Config $config, bool $hasTest): array
5555
}
5656

5757
/**
58+
* @param Config $config
5859
* @param bool $isReadOnly
5960
* @param bool $hasGenerated
6061
* @return array
62+
* @throws ConfigurationMismatchException
6163
*/
62-
public function getDefaultMagentoVolumes(bool $isReadOnly, bool $hasGenerated = true): array
64+
public function getDefaultMagentoVolumes(Config $config, bool $isReadOnly, bool $hasGenerated = true): array
6365
{
6466
$mode = $isReadOnly ? 'ro,delegated' : 'rw,delegated';
6567

6668
$volumes = [
67-
BuilderInterface::VOLUME_MAGENTO_VENDOR => [
68-
'path' => BuilderInterface::DIR_MAGENTO . '/vendor',
69+
$this->getVolume(
70+
$config,
71+
BuilderInterface::VOLUME_MAGENTO_VENDOR,
72+
BuilderInterface::VOLUME_MAGENTO_VENDOR
73+
) => [
74+
'target' => BuilderInterface::TARGET_ROOT . '/vendor',
6975
'volume' => '/vendor',
7076
'mode' => $mode,
7177
]
7278
];
7379

7480
if ($hasGenerated) {
75-
$volumes[BuilderInterface::VOLUME_MAGENTO_GENERATED] = [
76-
'path' => BuilderInterface::DIR_MAGENTO . '/generated',
81+
$volumes[$this->getVolume(
82+
$config,
83+
BuilderInterface::VOLUME_MAGENTO_GENERATED,
84+
BuilderInterface::VOLUME_MAGENTO_GENERATED
85+
)] = [
86+
'target' => BuilderInterface::TARGET_ROOT . '/generated',
7787
'volume' => '/generated',
7888
'mode' => $mode
7989
];
@@ -83,24 +93,23 @@ public function getDefaultMagentoVolumes(bool $isReadOnly, bool $hasGenerated =
8393
}
8494

8595
/**
86-
* @param array $mounts
96+
* @param Config $config
8797
* @param bool $isReadOnly
8898
* @param bool $hasGenerated
89-
* @return array
99+
* @return string[][]
100+
* @throws ConfigurationMismatchException
90101
*/
91102
public function getMagentoVolumes(
92-
array $mounts,
103+
Config $config,
93104
bool $isReadOnly,
94105
bool $hasGenerated = true
95106
): array {
96-
$volumes = $this->getDefaultMagentoVolumes($isReadOnly, $hasGenerated);
107+
$volumes = $this->getDefaultMagentoVolumes($config, $isReadOnly, $hasGenerated);
97108

98-
foreach ($mounts as $volumeData) {
109+
foreach ($config->getMounts() as $name => $volumeData) {
99110
$path = $volumeData['path'];
100-
$volumeName = 'magento-' . str_replace('/', '-', $path);
101-
102-
$volumes[$volumeName] = [
103-
'path' => BuilderInterface::DIR_MAGENTO . '/' . $path,
111+
$volumes[$this->getVolume($config, $name, $path)] = [
112+
'target' => BuilderInterface::TARGET_ROOT . '/' . $path,
104113
'volume' => '/' . $path,
105114
'mode' => 'rw,delegated'
106115
];
@@ -116,7 +125,7 @@ public function getComposerVolumes(): array
116125
{
117126
return [
118127
'~/.composer/cache' => [
119-
'path' => '/root/.composer/cache',
128+
'target' => '/root/.composer/cache',
120129
'mode' => 'rw,delegated'
121130
]
122131
];
@@ -131,7 +140,7 @@ public function getMountVolumes(bool $hasTmpMounts): array
131140
if ($hasTmpMounts) {
132141
return [
133142
BuilderInterface::VOLUME_DOCKER_MNT => [
134-
'path' => '/mnt',
143+
'target' => '/mnt',
135144
'mode' => 'rw,delegated'
136145
],
137146
];
@@ -154,7 +163,7 @@ public function normalize(array $volumes): array
154163
$normalized[] = sprintf(
155164
'%s:%s:%s',
156165
$name,
157-
$config['path'],
166+
$config['target'],
158167
$config['mode'] ?? 'rw,delegated'
159168
);
160169
}
@@ -181,4 +190,20 @@ public function getMagentoDevVolume(Config $config): string
181190
{
182191
return $config->getRootDirectory() . '/dev';
183192
}
193+
194+
/**
195+
* @param Config $config
196+
* @param string $name
197+
* @param string $path
198+
* @return string
199+
* @throws ConfigurationMismatchException
200+
*/
201+
private function getVolume(Config $config, string $name, string $path): string
202+
{
203+
if ($config->getSyncEngine() === BuilderInterface::SYNC_ENGINE_NATIVE) {
204+
return $config->getRootDirectory() . '/' . $path;
205+
}
206+
207+
return $config->getNameWithPrefix() . str_replace('/', '-', $name);
208+
}
184209
}

src/Test/Integration/BuildCustomComposeTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,61 @@ public function buildDataProvider(): array
126126
]
127127
]
128128
],
129+
'cloud-base-native' => [
130+
__DIR__ . '/_files/custom_cloud_base_native',
131+
[
132+
[
133+
BuildCustomCompose::ARG_SOURCE,
134+
json_encode([
135+
'name' => 'magento',
136+
'system' => [
137+
'mode' => 'production',
138+
'host' => 'magento2.test',
139+
'port' => '8080',
140+
'db' => [
141+
'increment_increment' => 3,
142+
'increment_offset' => 2
143+
],
144+
'mailhog' => [
145+
'smtp_port' => '1026',
146+
'http_port' => '8026'
147+
],
148+
'sync_mode' => 'native'
149+
],
150+
'services' => [
151+
'php' => [
152+
'version' => '7.2',
153+
'enabled' => true,
154+
'extensions' => [
155+
'enabled' => ['xsl']
156+
],
157+
],
158+
'mysql' => [
159+
'version' => '10.0',
160+
'image' => 'mariadb',
161+
'enabled' => true,
162+
],
163+
'mailhog' => [
164+
'enabled' => true,
165+
]
166+
],
167+
'hooks' => [
168+
'build' => 'set -e' . PHP_EOL
169+
. 'php ./vendor/bin/ece-tools run scenario/build/generate.xml' . PHP_EOL
170+
. 'php ./vendor/bin/ece-tools run scenario/build/transfer.xml',
171+
'deploy' => 'php ./vendor/bin/ece-tools run scenario/deploy.xml',
172+
'post_deploy' => 'php ./vendor/bin/ece-tools run scenario/post-deploy.xml'
173+
],
174+
'mounts' => [
175+
'var' => ['path' => 'var'],
176+
'app-etc' => ['path' => 'app/etc',],
177+
'pub-media' => ['path' => 'pub/media',],
178+
'pub-static' => ['path' => 'pub/static']
179+
]
180+
])
181+
]
182+
]
183+
],
129184
'cloud-base-with-custom-images' => [
130185
__DIR__ . '/_files/custom_cloud_custom_images',
131186
[

src/Test/Integration/_files/cloud_base/.magento.app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: mymagento
1+
name: magento
22

33
type: php:7.3
44
build:

src/Test/Integration/_files/cloud_base/docker-compose.exp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
volumes:
1515
- '.docker/mnt:/mnt:rw,delegated'
1616
- '.docker/mysql/mariadb.conf.d:/etc/mysql/mariadb.conf.d'
17-
- 'mymagento-magento-db:/var/lib/mysql'
17+
- 'magento-magento-db:/var/lib/mysql'
1818
- '.docker/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d'
1919
healthcheck:
2020
test: 'mysqladmin ping -h localhost -pmagento2'
@@ -203,7 +203,7 @@ volumes:
203203
magento-app-etc: { }
204204
magento-pub-media: { }
205205
magento-pub-static: { }
206-
mymagento-magento-db: { }
206+
magento-magento-db: { }
207207
networks:
208208
magento:
209209
driver: bridge

src/Test/Integration/_files/cloud_base_developer/.magento.app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: mymagento
1+
name: magento
22

33
type: php:7.3
44
build:

0 commit comments

Comments
 (0)