|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheAentMachine\AentDockerCompose\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Safe\Exceptions\StringsException; |
|
6
|
|
|
use TheAentMachine\Aent\Context\BaseOrchestratorContext; |
|
7
|
|
|
use TheAentMachine\Aenthill\Aenthill; |
|
8
|
|
|
use TheAentMachine\Aenthill\Pheromone; |
|
9
|
|
|
use TheAentMachine\Exception\MissingEnvironmentVariableException; |
|
10
|
|
|
use function Safe\sprintf; |
|
11
|
|
|
|
|
12
|
|
|
final class DockerComposeContext extends BaseOrchestratorContext |
|
13
|
|
|
{ |
|
14
|
|
|
public const REVERSE_PROXY_SERVICE_DEPENDENCY_KEY = 'REVERSE_PROXY_SERVICE'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string */ |
|
17
|
|
|
private $projectDir; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
private $dockerComposeFilename; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* DockerComposeContext constructor. |
|
24
|
|
|
* @param BaseOrchestratorContext $context |
|
25
|
|
|
* @throws MissingEnvironmentVariableException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(BaseOrchestratorContext $context) |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct($context->getEnvironmentType(), $context->getEnvironmentName(), $context->getBaseVirtualHost()); |
|
30
|
|
|
$this->projectDir = Pheromone::getContainerProjectDirectory(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function toMetadata(): void |
|
37
|
|
|
{ |
|
38
|
|
|
parent::toMetadata(); |
|
39
|
|
|
Aenthill::update([ |
|
40
|
|
|
'DOCKER_COMPOSE_FILENAME' => $this->dockerComposeFilename, |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return self |
|
46
|
|
|
* @throws MissingEnvironmentVariableException |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function fromMetadata() |
|
49
|
|
|
{ |
|
50
|
|
|
$self = new self(parent::fromMetadata()); |
|
51
|
|
|
$self->dockerComposeFilename = Aenthill::metadata('DOCKER_COMPOSE_FILENAME'); |
|
52
|
|
|
return $self; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
* @throws StringsException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getDockerComposeFilePath(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return sprintf('%s/%s', $this->projectDir, $this->dockerComposeFilename); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getProjectDir(): string |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->projectDir; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getDockerComposeFilename(): string |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->dockerComposeFilename; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string $dockerComposeFilename |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setDockerComposeFilename(string $dockerComposeFilename): void |
|
84
|
|
|
{ |
|
85
|
|
|
$this->dockerComposeFilename = $dockerComposeFilename; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|