Skip to content

Commit

Permalink
Merge pull request #385 from magento/develop
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
shiftedreality authored Nov 13, 2018
2 parents a90c853 + 218b93b commit 17f194a
Show file tree
Hide file tree
Showing 28 changed files with 1,469 additions and 1,058 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ before_install:

install:
- composer update -n --no-suggest
- ./bin/ece-tools docker:build --test --php ${TRAVIS_PHP_VERSION}
- ./bin/ece-tools docker:build:integration ${TRAVIS_PHP_VERSION} 10.0 latest

before_script: docker-compose up -d

Expand Down
1 change: 1 addition & 0 deletions dist/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: help

# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## This help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

Expand Down
2 changes: 2 additions & 0 deletions src/App/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\App;

use Magento\MagentoCloud\Command\Build;
Expand Down
3 changes: 3 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud;

use Composer\Composer;
Expand Down Expand Up @@ -70,6 +72,7 @@ protected function getDefaultCommands()
$this->container->create(Command\Wizard\IdealState::class),
$this->container->create(Command\Wizard\MasterSlave::class),
$this->container->create(Command\Docker\Build::class),
$this->container->create(Command\Docker\BuildIntegration::class),
$this->container->create(Command\Docker\ConfigConvert::class),
$this->container->create(Command\CronKill::class),
]
Expand Down
106 changes: 39 additions & 67 deletions src/Command/Docker/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\Command\Docker;

use Magento\MagentoCloud\Config\Environment;
use Magento\MagentoCloud\Config\RepositoryFactory;
use Magento\MagentoCloud\Docker\BuilderFactory;
use Magento\MagentoCloud\Docker\BuilderInterface;
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
use Magento\MagentoCloud\Filesystem\Driver\File;
use Magento\MagentoCloud\Filesystem\FileList;
use Magento\MagentoCloud\Filesystem\FileSystemException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -31,8 +33,6 @@ class Build extends Command
const OPTION_ES = 'es';
const OPTION_RABBIT_MQ = 'rmq';

const OPTION_IS_TEST = 'test';

/**
* @var BuilderFactory
*/
Expand All @@ -44,31 +44,31 @@ class Build extends Command
private $file;

/**
* @var FileList
* @var Environment
*/
private $fileList;
private $environment;

/**
* @var Environment
* @var RepositoryFactory
*/
private $environment;
private $configFactory;

/**
* @param BuilderFactory $builderFactory
* @param File $file
* @param FileList $fileList
* @param Environment $environment
* @param RepositoryFactory $configFactory
*/
public function __construct(
BuilderFactory $builderFactory,
File $file,
FileList $fileList,
Environment $environment
Environment $environment,
RepositoryFactory $configFactory
) {
$this->builderFactory = $builderFactory;
$this->file = $file;
$this->fileList = $fileList;
$this->environment = $environment;
$this->configFactory = $configFactory;

parent::__construct();
}
Expand All @@ -84,47 +84,34 @@ protected function configure()
self::OPTION_PHP,
null,
InputOption::VALUE_OPTIONAL,
'PHP version',
BuilderInterface::DEFAULT_PHP_VERSION
'PHP version'
)->addOption(
self::OPTION_NGINX,
null,
InputOption::VALUE_OPTIONAL,
'Nginx version',
BuilderInterface::DEFAULT_NGINX_VERSION
'Nginx version'
)->addOption(
self::OPTION_DB,
null,
InputOption::VALUE_OPTIONAL,
'DB version',
BuilderInterface::DEFAULT_DB_VERSION
'DB version'
)->addOption(
self::OPTION_REDIS,
null,
InputOption::VALUE_OPTIONAL,
'Redis version',
BuilderInterface::DEFAULT_REDIS_VERSION
'Redis version'
)->addOption(
self::OPTION_ES,
null,
InputOption::VALUE_OPTIONAL,
'ElasticSearch version',
BuilderInterface::DEFAULT_ES_VERSION
'Elasticsearch version'
)->addOption(
self::OPTION_RABBIT_MQ,
null,
InputOption::VALUE_OPTIONAL,
'RabbitMQ version',
BuilderInterface::DEFAULT_RABBIT_MQ_VERSION
'RabbitMQ version'
);

$this->addOption(
self::OPTION_IS_TEST,
null,
InputOption::VALUE_NONE,
'Generates ECE-Tools testing configuration (internal usage only)'
);

parent::configure();
}

Expand All @@ -136,43 +123,28 @@ protected function configure()
*/
public function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption(self::OPTION_IS_TEST)) {
$strategy = BuilderFactory::BUILDER_TEST;
$path = $this->fileList->getToolsDockerCompose();
} else {
$strategy = BuilderFactory::BUILDER_DEV;
$path = $this->fileList->getMagentoDockerCompose();
}

$builder = $this->builderFactory->create($strategy);

if ($phpVersion = $input->getOption(self::OPTION_PHP)) {
$builder->setPhpVersion($phpVersion);
}

if ($nginxVersion = $input->getOption(self::OPTION_NGINX)) {
$builder->setNginxVersion($nginxVersion);
}

if ($dbVersion = $input->getOption(self::OPTION_DB)) {
$builder->setDbVersion($dbVersion);
}

if ($redisVersion = $input->getOption(self::OPTION_REDIS)) {
$builder->setRedisVersion($redisVersion);
}

if ($esVersion = $input->getOption(self::OPTION_ES)) {
$builder->setESVersion($esVersion);
}

if ($rabbitMQVersion = $input->getOption(self::OPTION_RABBIT_MQ)) {
$builder->setRabbitMQVersion($rabbitMQVersion);
}

$config = Yaml::dump($builder->build(), 4, 2);

$this->file->filePutContents($path, $config);
$builder = $this->builderFactory->create(BuilderFactory::BUILDER_DEV);
$config = $this->configFactory->create();

$map = [
self::OPTION_PHP => BuilderInterface::PHP_VERSION,
self::OPTION_DB => BuilderInterface::DB_VERSION,
self::OPTION_NGINX => BuilderInterface::NGINX_VERSION,
self::OPTION_REDIS => BuilderInterface::REDIS_VERSION,
self::OPTION_ES => BuilderInterface::ES_VERSION,
self::OPTION_RABBIT_MQ => BuilderInterface::RABBIT_MQ_VERSION,
];

array_walk($map, function ($key, $option) use ($config, $input) {
if ($value = $input->getOption($option)) {
$config->set($key, $value);
}
});

$this->file->filePutContents(
$builder->getConfigPath(),
Yaml::dump($builder->build($config), 4, 2)
);

$output->writeln('<info>Configuration was built</info>');
}
Expand Down
133 changes: 133 additions & 0 deletions src/Command/Docker/BuildIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\Command\Docker;

use Magento\MagentoCloud\Config\Environment;
use Magento\MagentoCloud\Config\RepositoryFactory;
use Magento\MagentoCloud\Docker\BuilderFactory;
use Magento\MagentoCloud\Docker\BuilderInterface;
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
use Magento\MagentoCloud\Filesystem\Driver\File;
use Magento\MagentoCloud\Filesystem\FileSystemException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;

/**
* Docker build for internal integration testing.
*/
class BuildIntegration extends Command
{
const NAME = 'docker:build:integration';
const ARGUMENT_PHP = 'php';
const ARGUMENT_NGINX = 'nginx';
const ARGUMENT_DB = 'db';

/**
* @var BuilderFactory
*/
private $builderFactory;

/**
* @var File
*/
private $file;

/**
* @var RepositoryFactory
*/
private $configFactory;

/**
* @var Environment
*/
private $environment;

/**
* @param BuilderFactory $builderFactory
* @param File $file
* @param RepositoryFactory $configFactory
* @param Environment $environment
*/
public function __construct(
BuilderFactory $builderFactory,
File $file,
RepositoryFactory $configFactory,
Environment $environment
) {
$this->builderFactory = $builderFactory;
$this->file = $file;
$this->configFactory = $configFactory;
$this->environment = $environment;

parent::__construct();
}

/**
* @inheritdoc
*/
protected function configure()
{
$this->setName(self::NAME)
->setDescription('Build test docker configuration')
->addArgument(
self::ARGUMENT_PHP,
InputArgument::REQUIRED,
'PHP version'
)->addArgument(
self::ARGUMENT_DB,
InputArgument::REQUIRED,
'DB version'
)->addArgument(
self::ARGUMENT_NGINX,
InputArgument::REQUIRED,
'Nginx version'
);

parent::configure();
}

/**
* {@inheritdoc}
*
* @throws FileSystemException
* @throws ConfigurationMismatchException
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$builder = $this->builderFactory->create(BuilderFactory::BUILDER_TEST);
$config = $this->configFactory->create();

$map = [
self::ARGUMENT_PHP => BuilderInterface::PHP_VERSION,
self::ARGUMENT_DB => BuilderInterface::DB_VERSION,
self::ARGUMENT_NGINX => BuilderInterface::NGINX_VERSION,
];

array_walk($map, function ($key, $option) use ($config, $input) {
$config->set($key, $input->getArgument($option));
});

$this->file->filePutContents(
$builder->getConfigPath(),
Yaml::dump($builder->build($config), 4, 2)
);

$output->writeln('<info>Configuration was built</info>');
}

/**
* @inheritdoc
*/
public function isEnabled(): bool
{
return !$this->environment->isMasterBranch();
}
}
Loading

0 comments on commit 17f194a

Please sign in to comment.