Skip to content

Commit

Permalink
Merge pull request ezsystems#15 from ezsystems/feature-wizard-optim
Browse files Browse the repository at this point in the history
Updates, wizard simplification, and fixes
  • Loading branch information
Plopix committed Nov 19, 2017
2 parents ec988b1 + 83c4be8 commit 3410334
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

## CHANGELOG

### 1.2.0

- use Redis for Session for Platform.sh configuration by default
- Wizard Simplification, to remove the questions in 'standard' mode
- Fix TCP port mapping with Memached Admin

### 1.1.0

- ezplatform-http-cache is enabled when not loaded
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added docs/backup/1.1.0/ez.phar
Binary file not shown.
14 changes: 14 additions & 0 deletions docs/backup/1.1.0/ez.phar.pubkey
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzzMKkvmPQvqdPGax6BQz
Wd4U3M2O2s/bgbX2KF5sXWitSzccrnoje2TIcWfhnRZXiqcgbagxconI2V3WJP7U
oiZ2iqhJs3WqEdciYmX8tdc3JMAMaNMkhpEDcJcXnhYVuoA/i2Ad3RAfnW/XIUYy
anD3VQNZTdu/oolhv5/kbMQdUFaf5NnI+j13qPQjoaqNOZh/5CaOkRYUnDdNPn7C
vzyF9YQ3nW5wSrWR9TqkvIeVoJ/4kdemeEh+DYZZlNa55f/nPkW2SXiXC4UJfbA/
EkfAJWSdJNR73XtCqen96BV8zeE0VsVGouPRFtKasNCPkhsUzpbf77QNnESatuDi
gaoYWZCRQJ3tmgQBV4o35H2ZI36mz48z2vUuqdtb4ONTKtc5yEZZNiqfDARAys5a
nr4V3CGifCoMq/2bmF4QxDc0//J7aDV63dc3W+b7dYOoCs5RvPLSAzei7QCvQmwN
3ihCp5qJurqm4boZVTiEtwGMKYPe04gHQKivwB196wBLMhgMpAw7tBebG6uJl2i2
0oe08WAASJ7agiE04gM0+0e4xHXopTfOjYtiLm4khLtHm4vORoCbX1hm+ZYo8fL5
ynl9opd2vopwukVIC2t2WXGa/0SLVcygnjq4ow4it6zq+zPemS/AiR23//UMKr8h
gkX9cNgYQNT9Ko+Plqe+kT8CAwEAAQ==
-----END PUBLIC KEY-----
1 change: 1 addition & 0 deletions docs/backup/1.1.0/ez.phar.version
@@ -0,0 +1 @@
5d16a58a3c1724fc77de301ac2d0aae9bd87a9d2 ez.phar
2 changes: 1 addition & 1 deletion payload/dev/docker-compose.yml
Expand Up @@ -94,7 +94,7 @@ services:
environment:
- "MEMCACHE_HOST=memcache"
ports:
- "${PROJECTPORTPREFIX}083:8080"
- "${PROJECTPORTPREFIX}083:9083"

# Blackfire
blackfire:
Expand Down
6 changes: 4 additions & 2 deletions payload/platformsh/.platform.app.yaml
Expand Up @@ -22,6 +22,7 @@ build:
relationships:
database: "mysqldb:mysql"
cache: "cache:memcached"
redis: "rediscache:redis"

# The configuration of app when it is exposed to the web.
web:
Expand Down Expand Up @@ -86,9 +87,10 @@ runtime:
- readline
- memcached
- msgpack
- redis

variables:
php:
memory_limit: 256M
session.save_handler: memcached
session.save_path: "cache.internal:11211?persistent=1&weight=1&timeout=1&retry_interval=15"
session.save_handler: redis
session.save_path: "tcp://redis.internal:6379"
2 changes: 2 additions & 0 deletions payload/platformsh/.platform/services.yaml
Expand Up @@ -3,3 +3,5 @@ mysqldb:
disk: 2048
cache:
type: 'memcached:1.4'
rediscache:
type: 'redis:3.2'
105 changes: 91 additions & 14 deletions src/Core/ProjectWizard.php
Expand Up @@ -22,6 +22,24 @@ class ProjectWizard
*/
protected $projectConfiguration;

const INIT_STD = 'standard';
const INIT_STD_COMPOER_AUTH = 'standard-with-composer-auth';
const INIT_EXPERT = 'expert';

/**
* @var array
*/
protected static $modes = [
self::INIT_STD,
self::INIT_STD_COMPOER_AUTH,
self::INIT_EXPERT,
];

/**
* @var string
*/
protected $mode;

/**
* ProjectWizard constructor.
*
Expand All @@ -41,7 +59,9 @@ public function __construct(SymfonyStyle $io, ProjectConfiguration $configuratio
*/
public function __invoke(DockerCompose $compose)
{
return [
$this->mode = $this->getInitializationMode();

$configuration = [
$this->getNetworkName(),
$this->getNetworkTCPPort(),
$this->getComposerHttpBasicCredentials(),
Expand All @@ -52,13 +72,38 @@ public function __invoke(DockerCompose $compose)
$this->getProvisioningFolderName(),
$this->getComposeFileName(),
];

return $configuration;
}

/**
* @return string
*/
public function getInitializationMode()
{
$standard = self::INIT_STD;
$withComposer = self::INIT_STD_COMPOER_AUTH;
$expert = self::INIT_EXPERT;
$question = <<<END
eZ Launchpad will install a new architecture for you.
Three modes are available:
- <fg=cyan>{$standard}</>: All the services, no composer auth
- <fg=cyan>{$withComposer}</>: Standard with ability to provide Composer Auth, useful for eZ Platform Enterprise
- <fg=cyan>{$expert}</>: All the questions will be asked and you can select the services you want only
Please select your <fg=yellow;options=bold>Init</>ialization mode
END;

return $this->io->choice($question, self::$modes, self::INIT_STD);
}

/**
* @return array
*/
protected function getComposerHttpBasicCredentials()
{
if (!$this->requireComposerAuth()) {
return [];
}
$credentials = [];
$endString = '<fg=yellow;options=bold>Composer HTTP-BASIC</> for this project?';
$questionString = 'Do you want to set '.$endString;
Expand Down Expand Up @@ -97,6 +142,14 @@ protected function getOneComposerHttpBasic()
*/
protected function getProvisioningFolderName()
{
$default = $this->projectConfiguration->get('provisioning.folder_name');
if (empty($default)) {
$default = 'provisioning';
}

if ($this->isStandardMode()) {
return $default;
}
$pattern = '^[a-zA-Z0-9]*$';

$validator = function ($value) use ($pattern) {
Expand All @@ -105,10 +158,6 @@ protected function getProvisioningFolderName()

$message = 'What is your preferred name for the <fg=yellow;options=bold>provisioning folder</>?';
$errorMessage = "The name of the folder MUST respect {$pattern}.";
$default = $this->projectConfiguration->get('provisioning.folder_name');
if (empty($default)) {
$default = 'provisioning';
}

return $this->io->askQuestion($this->getQuestion($message, $default, $validator, $errorMessage));
}
Expand All @@ -118,6 +167,14 @@ protected function getProvisioningFolderName()
*/
public function getComposeFileName()
{
$default = $this->projectConfiguration->get('docker.compose_file');
if (empty($default)) {
$default = 'docker-compose.yml';
}
if ($this->isStandardMode()) {
return $default;
}

$pattern = '^[a-zA-Z0-9\-]*\.yml$';

$validator = function ($value) use ($pattern) {
Expand All @@ -126,10 +183,6 @@ public function getComposeFileName()

$message = 'What is your preferred filename for the <fg=yellow;options=bold>Docker Compose file</>?';
$errorMessage = "The name of the filename MUST respect {$pattern}.";
$default = $this->projectConfiguration->get('docker.compose_file');
if (empty($default)) {
$default = 'docker-compose.yml';
}

return $this->io->askQuestion($this->getQuestion($message, $default, $validator, $errorMessage));
}
Expand All @@ -145,7 +198,8 @@ protected function getSelectedServices($services, $questionnable)
$selectedServices = [];
foreach ($services as $name => $service) {
if (in_array($name, $questionnable)) {
if ($this->io->confirm("Do you want the service <fg=yellow;options=bold>{$name}</>")) {
if ($this->isStandardMode() ||
$this->io->confirm("Do you want the service <fg=yellow;options=bold>{$name}</>")) {
$selectedServices[] = $name;
}
} else {
Expand All @@ -161,15 +215,18 @@ protected function getSelectedServices($services, $questionnable)
*/
protected function getNetworkName()
{
$pattern = '^[a-zA-Z0-9]*$';

$default = str_replace(['-', '_', '.'], '', strtolower(basename(getcwd())));
$pattern = '^[a-zA-Z0-9]*$';
$validator = function ($value) use ($pattern) {
return preg_match("/{$pattern}/", $value);
};

if ($validator($default) && $this->isStandardMode()) {
return $default;
}

$message = 'Please select a name for the containers <fg=yellow;options=bold>Docker Network</>';
$errorMessage = "The name of the network MUST respect {$pattern}.";
$default = strtolower(basename(getcwd()));

return $this->io->askQuestion($this->getQuestion($message, $default, $validator, $errorMessage));
}
Expand All @@ -179,6 +236,7 @@ protected function getNetworkName()
*/
protected function getNetworkTCPPort()
{
$default = 42;
$validator = function ($value) {
if (($value > 0) && ($value <= 65)) {
$socket = @fsockopen('127.0.0.1', intval("{$value}080"), $errno, $errstr, 5);
Expand All @@ -194,9 +252,12 @@ protected function getNetworkTCPPort()
return false;
};

if ($validator($default) && $this->isStandardMode()) {
return $default;
}

$message = 'What is the <fg=yellow;options=bold>TCP Port Prefix</> you want?';
$errorMessage = 'The TCP Port Prefix is not correct (already used or not between 1 and 65.';
$default = 42;

return (int) $this->io->askQuestion($this->getQuestion($message, $default, $validator, $errorMessage));
}
Expand Down Expand Up @@ -226,4 +287,20 @@ function ($value) use ($validator, $exceptionMessage) {

return $question;
}

/**
* @return bool
*/
protected function isStandardMode()
{
return self::INIT_STD == $this->mode;
}

/**
* @return bool
*/
protected function requireComposerAuth()
{
return self::INIT_STD !== $this->mode;
}
}

0 comments on commit 3410334

Please sign in to comment.