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