forked from ezsystems/launchpad
/
Initialize.php
209 lines (180 loc) · 7.2 KB
/
Initialize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Launchpad\Command\Docker;
use eZ\Launchpad\Console\Application;
use eZ\Launchpad\Core\Client\Docker;
use eZ\Launchpad\Core\Command;
use eZ\Launchpad\Core\DockerCompose;
use eZ\Launchpad\Core\ProcessRunner;
use eZ\Launchpad\Core\ProjectStatusDumper;
use eZ\Launchpad\Core\ProjectWizard;
use eZ\Launchpad\Core\TaskExecutor;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
/**
* Class Initialize.
*/
class Initialize extends Command
{
/**
* @var ProjectStatusDumper
*/
protected $projectStatusDumper;
/**
* Status constructor.
*/
public function __construct(ProjectStatusDumper $projectStatusDumper)
{
parent::__construct();
$this->projectStatusDumper = $projectStatusDumper;
}
/**
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
$this->projectStatusDumper->setIo($this->io);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
parent::configure();
$this->setName('docker:initialize')->setDescription('Initialize the project and all the services.');
$this->setAliases(['docker:init', 'initialize', 'init']);
$this->addArgument('repository', InputArgument::OPTIONAL, 'eZ Platform Repository', 'ezsystems/ezplatform');
$this->addArgument('version', InputArgument::OPTIONAL, 'eZ Platform Version', '2.*');
$this->addArgument('initialdata', InputArgument::OPTIONAL, 'eZ Platform Initial', 'clean');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$fs = new Filesystem();
$application = $this->getApplication();
/* @var Application $application */
$output->writeln($application->getLogo());
// Get the Payload docker-compose.yml
$compose = new DockerCompose("{$this->getPayloadDir()}/dev/docker-compose.yml");
$wizard = new ProjectWizard($this->io, $this->projectConfiguration);
// Ask the questions
list(
$networkName,
$networkPort,
$httpBasics,
$selectedServices,
$provisioningName,
$composeFileName
) = $wizard(
$compose
);
$compose->filterServices($selectedServices);
// start the scafolding of the Payload
$provisioningFolder = "{$this->projectPath}/{$provisioningName}";
$fs->mkdir("{$provisioningFolder}/dev");
$fs->mirror("{$this->getPayloadDir()}/dev", "{$provisioningFolder}/dev");
$fs->chmod(
[
"{$provisioningFolder}/dev/nginx/entrypoint.bash",
"{$provisioningFolder}/dev/engine/entrypoint.bash",
"{$provisioningFolder}/dev/solr/entrypoint.bash",
],
0755
);
unset($selectedServices);
// Clean the Compose File
$compose->removeUselessEnvironmentsVariables();
// Get the Payload README.md
$fs->copy("{$this->getPayloadDir()}/README.md", "{$provisioningFolder}/README.md");
// create the local configurations
$localConfigurations = [
'provisioning.folder_name' => $provisioningName,
'docker.compose_filename' => $composeFileName,
'docker.network_name' => $networkName,
'docker.network_prefix_port' => $networkPort,
];
foreach ($httpBasics as $name => $httpBasic) {
list($host, $user, $pass) = $httpBasic;
$localConfigurations["composer.http_basic.{$name}.host"] = $host;
$localConfigurations["composer.http_basic.{$name}.login"] = $user;
$localConfigurations["composer.http_basic.{$name}.password"] = $pass;
}
$this->projectConfiguration->setMultiLocal($localConfigurations);
// Create the docker Client
$options = [
'compose-file' => "{$provisioningFolder}/dev/{$composeFileName}",
'network-name' => $networkName,
'network-prefix-port' => $networkPort,
'project-path' => $this->projectPath,
'provisioning-folder-name' => $provisioningName,
'host-machine-mapping' => $this->projectConfiguration->get('docker.host_machine_mapping'),
'composer-cache-dir' => $this->projectConfiguration->get('docker.host_composer_cache_dir'),
];
$dockerClient = new Docker($options, new ProcessRunner(), $this->optimizer);
$this->projectStatusDumper->setDockerClient($dockerClient);
// do the real work
$this->innerInitialize(
$dockerClient,
$compose,
"{$provisioningFolder}/dev/{$composeFileName}",
$input
);
// remove unused solr
if (!$compose->hasService('solr')) {
$fs->remove("{$provisioningFolder}/dev/solr");
}
// remove unused varnish
if (!$compose->hasService('varnish')) {
$fs->remove("{$provisioningFolder}/dev/varnish");
}
$this->projectConfiguration->setEnvironment('dev');
$this->projectStatusDumper->dump('ncsi');
}
/**
* @param string $composeFilePath
*/
protected function innerInitialize(
Docker $dockerClient,
DockerCompose $compose,
$composeFilePath,
InputInterface $input
) {
$tempCompose = clone $compose;
$tempCompose->cleanForInitialize();
// dump the temporary DockerCompose.yml without the mount and env vars in the provisioning folder
$tempCompose->dump($composeFilePath);
unset($tempCompose);
// Do the first pass to get eZ Platform and related files
$dockerClient->build(['--no-cache']);
$dockerClient->up(['-d']);
$executor = new TaskExecutor($dockerClient, $this->projectConfiguration, $this->requiredRecipes);
$executor->composerInstall();
// Fix #7
// if eZ EE is selected then the DB is not selected by the install process
// we have to do it manually here
$repository = $input->getArgument('repository');
$initialdata = $input->getArgument('initialdata');
if ('clean' === $initialdata && false !== strpos($repository, 'ezplatform-ee')) {
$initialdata = 'ezplatform-ee-clean';
}
$executor->eZInstall($input->getArgument('version'), $repository, $initialdata);
if ($compose->hasService('solr')) {
$executor->eZInstallSolr();
}
$compose->dump($composeFilePath);
$dockerClient->up(['-d']);
$executor->composerInstall();
if ($compose->hasService('solr')) {
$executor->createCore();
$executor->indexSolr();
}
}
}