|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheAentMachine\AentGitLabCI\Question; |
|
5
|
|
|
|
|
6
|
|
|
use TheAentMachine\AentGitLabCI\Aenthill\Metadata; |
|
7
|
|
|
use TheAentMachine\Aenthill\Manifest; |
|
8
|
|
|
use TheAentMachine\Helper\AentHelper; |
|
9
|
|
|
use TheAentMachine\Question\CommonValidators; |
|
10
|
|
|
|
|
11
|
|
|
final class GitLabCICommonQuestions |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var AentHelper */ |
|
14
|
|
|
private $helper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* GitLabCICommonQuestions constructor. |
|
18
|
|
|
* @param AentHelper $helper |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(AentHelper $helper) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->helper = $helper; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function askForRemoteIP(): string |
|
26
|
|
|
{ |
|
27
|
|
|
$remoteIP = Manifest::getMetadata(Metadata::REMOTE_IP_KEY); |
|
28
|
|
|
|
|
29
|
|
|
if (null === $remoteIP) { |
|
30
|
|
|
$remoteIP = $this->helper->question('Remote IP') |
|
31
|
|
|
->setHelpText('The IP of the server where you want to deploy your stack.') |
|
32
|
|
|
->compulsory() |
|
33
|
|
|
->setValidator(CommonValidators::getIPv4Validator()) |
|
34
|
|
|
->ask(); |
|
35
|
|
|
|
|
36
|
|
|
Manifest::addMetadata(Metadata::REMOTE_IP_KEY, $remoteIP); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $remoteIP; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function askForRemoteUser(): string |
|
43
|
|
|
{ |
|
44
|
|
|
$remoteUser = Manifest::getMetadata(Metadata::REMOTE_USER_KEY); |
|
45
|
|
|
|
|
46
|
|
|
if (null === $remoteUser) { |
|
47
|
|
|
$remoteUser = $this->helper->question('Remote user') |
|
48
|
|
|
->setHelpText('The username of the user which will deploy over SSH your stack.') |
|
49
|
|
|
->compulsory() |
|
50
|
|
|
->setValidator(CommonValidators::getAlphaValidator(['_', '-'], 'User names can contain alphanumeric characters and "_", "-".')) |
|
51
|
|
|
->ask(); |
|
52
|
|
|
|
|
53
|
|
|
Manifest::addMetadata(Metadata::REMOTE_USER_KEY, $remoteUser); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $remoteUser; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function askForRemoteBasePath(): string |
|
60
|
|
|
{ |
|
61
|
|
|
$remoteBasePath = Manifest::getMetadata(Metadata::REMOTE_BASE_PATH_KEY); |
|
62
|
|
|
|
|
63
|
|
|
if (null === $remoteBasePath) { |
|
64
|
|
|
$remoteBasePath = $this->helper->question('Remote base path') |
|
65
|
|
|
->setHelpText('The absolute path (without trailing "/") on the server where your stack will be deployed.') |
|
66
|
|
|
->compulsory() |
|
67
|
|
|
->setValidator(CommonValidators::getAbsolutePathValidator()) |
|
68
|
|
|
->ask(); |
|
69
|
|
|
|
|
70
|
|
|
Manifest::addMetadata(Metadata::REMOTE_BASE_PATH_KEY, $remoteBasePath); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $remoteBasePath; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function askForManual(): bool |
|
77
|
|
|
{ |
|
78
|
|
|
$manual = Manifest::getMetadata(Metadata::IS_MANUAL_KEY); |
|
79
|
|
|
if (null !== $manual) { |
|
80
|
|
|
return (bool) $manual; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$manual = $this->helper->question('Do you want to deploy your stack <info>manually</info>?') |
|
84
|
|
|
->compulsory() |
|
85
|
|
|
->yesNoQuestion() |
|
86
|
|
|
->ask(); |
|
87
|
|
|
$manual = $manual ? 'true' : 'false'; |
|
88
|
|
|
|
|
89
|
|
|
Manifest::addMetadata(Metadata::IS_MANUAL_KEY, $manual); |
|
90
|
|
|
|
|
91
|
|
|
return $manual === 'true'; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|