1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheAentMachine\Aenthill; |
4
|
|
|
|
5
|
|
|
use TheAentMachine\Service\Service; |
6
|
|
|
|
7
|
|
|
final class CommonEvents |
8
|
|
|
{ |
9
|
|
|
public const ADD_EVENT = 'ADD'; |
10
|
|
|
public const START_EVENT = 'START'; |
11
|
|
|
public const REPLY_EVENT = 'REPLY'; |
12
|
|
|
public const ENVIRONMENT_EVENT = 'ENVIRONMENT'; |
13
|
|
|
public const NEW_SERVICE_EVENT = 'NEW_SERVICE'; |
14
|
|
|
public const NEW_VIRTUAL_HOST_EVENT = 'NEW_VIRTUAL_HOST'; |
15
|
|
|
public const NEW_IMAGE_EVENT = 'NEW_IMAGE'; |
16
|
|
|
public const NEW_BUILD_IMAGE_EVENT = 'NEW_BUILD_IMAGE'; |
17
|
|
|
public const NEW_DEPLOY_JOB_DOCKER_COMPOSE_EVENT = 'NEW_DEPLOY_JOB_DOCKER_COMPOSE'; |
18
|
|
|
public const NEW_DEPLOY_JOB_KUBERNETES_EVENT = 'NEW_DEPLOY_JOB_KUBERNETES'; |
19
|
|
|
|
20
|
|
|
public static function dispatchService(Service $service): void |
21
|
|
|
{ |
22
|
|
|
Aenthill::dispatchJson(self::NEW_SERVICE_EVENT, $service); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $serviceName |
27
|
|
|
* @param int $virtualPort |
28
|
|
|
* @param string|null $virtualHost |
29
|
|
|
* @return mixed[]|null |
30
|
|
|
*/ |
31
|
|
|
public static function dispatchNewVirtualHost(string $serviceName, int $virtualPort = 80, string $virtualHost = null): ?array |
32
|
|
|
{ |
33
|
|
|
$message = [ |
34
|
|
|
'service' => $serviceName, |
35
|
|
|
'virtualPort' => $virtualPort |
36
|
|
|
]; |
37
|
|
|
if ($virtualHost !== null) { |
38
|
|
|
$message['virtualHost'] = $virtualHost; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return Aenthill::dispatchJson(self::NEW_VIRTUAL_HOST_EVENT, $message); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public static function dispatchImage(Service $service): void |
45
|
|
|
{ |
46
|
|
|
Aenthill::dispatchJson(self::NEW_IMAGE_EVENT, $service->imageJsonSerialize()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|