forked from magento/magento-cloud-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVolumeResolver.php
More file actions
156 lines (136 loc) · 3.74 KB
/
VolumeResolver.php
File metadata and controls
156 lines (136 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\CloudDocker\Compose\ProductionBuilder;
use Magento\CloudDocker\Compose\BuilderInterface;
/**
* Resolves the volume definitions.
*/
class VolumeResolver
{
public function getRootVolume(bool $isReadOnly): array
{
$mode = $isReadOnly ? 'ro,delegated' : 'rw,delegated';
return [
BuilderInterface::VOLUME_MAGENTO => [
'path' => BuilderInterface::DIR_MAGENTO,
'volume' => '/',
'mode' => $mode
]
];
}
/**
* @param bool $hasTest
* @return array
*/
public function getDevVolumes(bool $hasTest): array
{
if ($hasTest) {
return [
BuilderInterface::VOLUME_MAGENTO_DEV => [
'path' => BuilderInterface::DIR_MAGENTO . '/dev',
'volume' => '/dev',
'mode' => 'rw,delegated'
]
];
}
return [];
}
/**
* @param bool $isReadOnly
* @param bool $hasGenerated
* @return array
*/
public function getDefaultMagentoVolumes(bool $isReadOnly, bool $hasGenerated = true): array
{
$mode = $isReadOnly ? 'ro,delegated' : 'rw,delegated';
$volumes = [
BuilderInterface::VOLUME_MAGENTO_VENDOR => [
'path' => BuilderInterface::DIR_MAGENTO . '/vendor',
'volume' => '/vendor',
'mode' => $mode,
]
];
if ($hasGenerated) {
$volumes[BuilderInterface::VOLUME_MAGENTO_GENERATED] = [
'path' => BuilderInterface::DIR_MAGENTO . '/generated',
'volume' => '/generated',
'mode' => $mode
];
}
return $volumes;
}
/**
* @param array $mounts
* @param bool $isReadOnly
* @param bool $hasGenerated
* @return array
*/
public function getMagentoVolumes(
array $mounts,
bool $isReadOnly,
bool $hasGenerated = true
): array {
$volumes = $this->getDefaultMagentoVolumes($isReadOnly, $hasGenerated);
foreach ($mounts as $volumeData) {
$path = $volumeData['path'];
$volumeName = 'magento-' . str_replace('/', '-', $path);
$volumes[$volumeName] = [
'path' => BuilderInterface::DIR_MAGENTO . '/' . $path,
'volume' => '/' . $path,
'mode' => 'rw,delegated'
];
}
return $volumes;
}
/**
* @return array
*/
public function getComposerVolumes(): array
{
return [
'~/.composer/cache' => [
'path' => '/root/.composer/cache',
'mode' => 'rw,delegated'
]
];
}
/**
* @param bool $hasTmpMounts
* @return array
*/
public function getMountVolumes(bool $hasTmpMounts): array
{
if ($hasTmpMounts) {
return [
BuilderInterface::VOLUME_DOCKER_MNT => [
'path' => '/mnt',
'mode' => 'rw,delegated'
],
];
}
return [];
}
/**
* Normalize to name:path:mode format
*
* @param array $volumes
* @return array
*/
public function normalize(array $volumes): array
{
$normalized = [];
foreach ($volumes as $name => $config) {
$normalized[] = sprintf(
'%s:%s:%s',
$name,
$config['path'],
$config['mode'] ?? 'rw,delegated'
);
}
return $normalized;
}
}