1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheAentMachine\Aent\Event\CI; |
4
|
|
|
|
5
|
|
|
use Safe\Exceptions\StringsException; |
6
|
|
|
use TheAentMachine\Aent\Context\Context; |
7
|
|
|
use TheAentMachine\Aent\Event\AbstractJsonEvent; |
8
|
|
|
use TheAentMachine\Aent\K8SProvider\Provider; |
9
|
|
|
use TheAentMachine\Aent\Payload\CI\KubernetesDeployJobPayload; |
10
|
|
|
use function Safe\sprintf; |
11
|
|
|
|
12
|
|
|
abstract class AbstractCIKubernetesDeployJobEvent extends AbstractJsonEvent |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param string $directoryName |
16
|
|
|
* @param Provider $provider |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
abstract protected function addDeployJob(string $directoryName, Provider $provider): void; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
protected function getEventName(): string |
25
|
|
|
{ |
26
|
|
|
return 'KUBERNETES_DEPLOY_JOB'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
protected function shouldRegisterEvents(): bool |
33
|
|
|
{ |
34
|
|
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return void |
39
|
|
|
* @throws StringsException |
40
|
|
|
*/ |
41
|
|
|
protected function beforeExecute(): void |
42
|
|
|
{ |
43
|
|
|
/** @var Context $context */ |
44
|
|
|
$context = Context::fromMetadata(); |
45
|
|
|
$this->output->writeln(sprintf( |
46
|
|
|
"\nš Hello! I'm the aent <info>%s</info> and I'm going to setup a deploy job for Kubernetes on your <info>%s</info> environment <info>%s</info>.", |
47
|
|
|
$this->getAentName(), |
48
|
|
|
$context->getEnvironmentType(), |
49
|
|
|
$context->getEnvironmentName() |
50
|
|
|
)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array<string,string> $payload |
55
|
|
|
* @return mixed[]|null |
56
|
|
|
*/ |
57
|
|
|
protected function executeJsonEvent(array $payload): ?array |
58
|
|
|
{ |
59
|
|
|
$payload = KubernetesDeployJobPayload::fromArray($payload); |
60
|
|
|
$this->addDeployJob($payload->getDirectoryName(), $payload->getProvider()); |
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return void |
66
|
|
|
* @throws StringsException |
67
|
|
|
*/ |
68
|
|
|
protected function afterExecute(): void |
69
|
|
|
{ |
70
|
|
|
/** @var Context $context */ |
71
|
|
|
$context = Context::fromMetadata(); |
72
|
|
|
$this->output->writeln( |
73
|
|
|
sprintf( |
74
|
|
|
"\nI've added the deploy job for Kubernetes on your <info>%s</info> environment <info>%s</info>. See you later!", |
75
|
|
|
$context->getEnvironmentType(), |
76
|
|
|
$context->getEnvironmentName() |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|