Skip to content

Commit ef43872

Browse files
MAGECLOUD-3231: Rewrite AcceptanceTest to use Cloud Docker (#429)
1 parent 9ffd558 commit ef43872

25 files changed

+699
-514
lines changed

.travis.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,11 @@ addons:
1717
update: true
1818

1919
env:
20-
global:
21-
- DIR_TOOLS="/var/www/ece-tools"
2220
matrix:
2321
- TEST_SUITE=static-unit XDEBUG=true
2422
- TEST_SUITE=integration
2523
- TEST_SUITE=docker-integration
2624

27-
matrix:
28-
exclude:
29-
- php: '7.0'
30-
env: TEST_SUITE=docker-integration
31-
- php: '7.1'
32-
env: TEST_SUITE=docker-integration
33-
3425
cache:
3526
apt: true
3627
directories:
@@ -41,9 +32,7 @@ before_install:
4132
- echo "COMPOSER_MAGENTO_PASSWORD=${REPO_PASSWORD}" >> ./docker/composer.env
4233
- if [ $XDEBUG == "true" ]; then echo "PHP_ENABLE_XDEBUG=true" >> ./docker/global.env; fi;
4334

44-
install:
45-
- composer update -n --no-suggest
46-
- ./bin/ece-tools docker:build:integration ${TRAVIS_PHP_VERSION} 10.0 latest
35+
install: composer update -n --no-suggest
4736

4837
script: ./tests/travis/script.sh
4938

src/Command/Docker/BuildIntegration.php

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Input\InputArgument;
1919
use Symfony\Component\Console\Input\InputInterface;
20+
use Symfony\Component\Console\Input\InputOption;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122
use Symfony\Component\Yaml\Yaml;
2223

2324
/**
2425
* Docker build for internal integration testing.
26+
*
27+
* @codeCoverageIgnore
2528
*/
2629
class BuildIntegration extends Command
2730
{
2831
const NAME = 'docker:build:integration';
29-
const ARGUMENT_PHP = 'php';
30-
const ARGUMENT_NGINX = 'nginx';
31-
const ARGUMENT_DB = 'db';
32+
const ARGUMENT_VERSION = 'version';
33+
const OPTION_PHP = 'php';
34+
const OPTION_NGINX = 'nginx';
35+
const OPTION_DB = 'db';
3236

3337
/**
3438
* @var BuilderFactory
@@ -78,17 +82,31 @@ protected function configure()
7882
$this->setName(self::NAME)
7983
->setDescription('Build test docker configuration')
8084
->addArgument(
81-
self::ARGUMENT_PHP,
85+
self::ARGUMENT_VERSION,
8286
InputArgument::REQUIRED,
83-
'PHP version'
84-
)->addArgument(
85-
self::ARGUMENT_DB,
86-
InputArgument::REQUIRED,
87-
'DB version'
88-
)->addArgument(
89-
self::ARGUMENT_NGINX,
90-
InputArgument::REQUIRED,
91-
'Nginx version'
87+
sprintf(
88+
'Version of integration framework configuration (%s/%s)',
89+
BuilderFactory::BUILDER_TEST_V1,
90+
BuilderFactory::BUILDER_TEST_V2
91+
)
92+
)->addOption(
93+
self::OPTION_PHP,
94+
null,
95+
InputOption::VALUE_OPTIONAL,
96+
'PHP version',
97+
'7.2'
98+
)->addOption(
99+
self::OPTION_DB,
100+
null,
101+
InputOption::VALUE_OPTIONAL,
102+
'DB version',
103+
'10.2'
104+
)->addOption(
105+
self::OPTION_NGINX,
106+
null,
107+
InputOption::VALUE_OPTIONAL,
108+
'Nginx version',
109+
'latest'
92110
);
93111

94112
parent::configure();
@@ -102,17 +120,23 @@ protected function configure()
102120
*/
103121
public function execute(InputInterface $input, OutputInterface $output)
104122
{
105-
$builder = $this->builderFactory->create(BuilderFactory::BUILDER_TEST);
123+
$strategy = $input->getArgument(self::ARGUMENT_VERSION);
124+
125+
if (!in_array($strategy, [BuilderFactory::BUILDER_TEST_V1, BuilderFactory::BUILDER_TEST_V2], true)) {
126+
throw new ConfigurationMismatchException('Wrong framework version');
127+
}
128+
129+
$builder = $this->builderFactory->create($strategy);
106130
$config = $this->configFactory->create();
107131

108132
$map = [
109-
self::ARGUMENT_PHP => BuilderInterface::PHP_VERSION,
110-
self::ARGUMENT_DB => BuilderInterface::DB_VERSION,
111-
self::ARGUMENT_NGINX => BuilderInterface::NGINX_VERSION,
133+
self::OPTION_PHP => BuilderInterface::PHP_VERSION,
134+
self::OPTION_DB => BuilderInterface::DB_VERSION,
135+
self::OPTION_NGINX => BuilderInterface::NGINX_VERSION,
112136
];
113137

114138
array_walk($map, function ($key, $option) use ($config, $input) {
115-
$config->set($key, $input->getArgument($option));
139+
$config->set($key, $input->getOption($option));
116140
});
117141

118142
$this->file->filePutContents(

src/Docker/BuilderFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
class BuilderFactory
1414
{
1515
const BUILDER_DEV = 'dev';
16-
const BUILDER_TEST = 'test';
16+
const BUILDER_TEST_V1 = 'test-v1';
17+
const BUILDER_TEST_V2 = 'test-v2';
1718

1819
/**
1920
* @var array
2021
*/
2122
private static $map = [
2223
self::BUILDER_DEV => DevBuilder::class,
23-
self::BUILDER_TEST => IntegrationBuilder::class,
24+
/** Internal CI configurations. */
25+
self::BUILDER_TEST_V1 => IntegrationV1Builder::class,
26+
self::BUILDER_TEST_V2 => IntegrationV2Builder::class
2427
];
2528

2629
/**

src/Docker/IntegrationBuilder.php renamed to src/Docker/IntegrationV1Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @codeCoverageIgnore
1818
*/
19-
class IntegrationBuilder implements BuilderInterface
19+
class IntegrationV1Builder implements BuilderInterface
2020
{
2121
/**
2222
* @var FileList

src/Docker/IntegrationV2Builder.php

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Docker;
9+
10+
use Illuminate\Contracts\Config\Repository;
11+
use Magento\MagentoCloud\Docker\Service\ServiceFactory;
12+
use Magento\MagentoCloud\Filesystem\FileList;
13+
14+
/**
15+
* Docker integration test builder.
16+
*
17+
* @codeCoverageIgnore
18+
*/
19+
class IntegrationV2Builder implements BuilderInterface
20+
{
21+
/**
22+
* @var FileList
23+
*/
24+
private $fileList;
25+
26+
/**
27+
* @var ServiceFactory
28+
*/
29+
private $serviceFactory;
30+
31+
/**
32+
* @param FileList $fileList
33+
* @param ServiceFactory $serviceFactory
34+
*/
35+
public function __construct(FileList $fileList, ServiceFactory $serviceFactory)
36+
{
37+
$this->fileList = $fileList;
38+
$this->serviceFactory = $serviceFactory;
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*
44+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
45+
*/
46+
public function build(Repository $repository): array
47+
{
48+
$phpVersion = $repository->get(self::PHP_VERSION);
49+
$dbVersion = $repository->get(self::DB_VERSION);
50+
$nginxVersion = $repository->get(self::NGINX_VERSION);
51+
52+
$services = [
53+
'version' => '2',
54+
'services' => [
55+
'fpm' => $this->serviceFactory->create(
56+
ServiceFactory::SERVICE_FPM,
57+
$phpVersion,
58+
[
59+
'ports' => [9000],
60+
'links' => [
61+
'db',
62+
],
63+
'volumes' => [
64+
$this->getMagentoVolume(false)
65+
],
66+
'volumes_from' => [
67+
'appdata',
68+
],
69+
'env_file' => [
70+
'./docker/global.env',
71+
'./docker/composer.env',
72+
],
73+
]
74+
),
75+
'db' => $this->serviceFactory->create(
76+
ServiceFactory::SERVICE_DB,
77+
$dbVersion,
78+
[
79+
'ports' => [3306],
80+
'volumes' => [
81+
'/var/lib/mysql',
82+
],
83+
'environment' => [
84+
'MYSQL_ROOT_PASSWORD=magento2',
85+
'MYSQL_DATABASE=magento2',
86+
'MYSQL_USER=magento2',
87+
'MYSQL_PASSWORD=magento2',
88+
],
89+
]
90+
),
91+
'web' => $this->serviceFactory->create(
92+
ServiceFactory::SERVICE_NGINX,
93+
$nginxVersion,
94+
[
95+
'ports' => [
96+
'8030:80',
97+
],
98+
'links' => [
99+
'fpm',
100+
'db',
101+
],
102+
'volumes' => [
103+
$this->getMagentoVolume(false)
104+
],
105+
'volumes_from' => [
106+
'appdata',
107+
],
108+
'env_file' => [
109+
'./docker/global.env',
110+
'./docker/composer.env',
111+
],
112+
]
113+
),
114+
],
115+
'volumes' => [
116+
'magento' => []
117+
]
118+
];
119+
120+
$services['services']['build'] = $this->getCliService(
121+
$phpVersion,
122+
false,
123+
['db'],
124+
'build.magento2.docker'
125+
);
126+
$services['services']['deploy'] = $this->getCliService(
127+
$phpVersion,
128+
false,
129+
['db'],
130+
'deploy.magento2.docker'
131+
);
132+
$services['services']['cron'] = $this->getCliService(
133+
$phpVersion,
134+
false,
135+
['db'],
136+
'cron.magento2.docker',
137+
true
138+
);
139+
$services ['services']['appdata'] = [
140+
'image' => 'tianon/true',
141+
'volumes' => [
142+
'.:/var/www/ece-tools',
143+
'/var/www/magento/pub/static',
144+
'/var/www/magento/pub/media',
145+
'/var/www/magento/var',
146+
'/var/www/magento/app/etc',
147+
],
148+
];
149+
150+
return $services;
151+
}
152+
153+
/**
154+
* @param string $version
155+
* @param bool $isReadOnly
156+
* @param array $depends
157+
* @param string $hostname
158+
* @param bool $cron
159+
* @return array
160+
* @throws ConfigurationMismatchException
161+
*/
162+
private function getCliService(
163+
string $version,
164+
bool $isReadOnly,
165+
array $depends,
166+
string $hostname,
167+
bool $cron = false
168+
): array {
169+
$composeCacheDirectory = file_exists(getenv('HOME') . '/.cache/composer')
170+
? '~/.cache/composer'
171+
: '~/.composer/cache';
172+
173+
$config = $this->serviceFactory->create(
174+
ServiceFactory::SERVICE_CLI,
175+
$version,
176+
[
177+
'hostname' => $hostname,
178+
'depends_on' => $depends,
179+
'volumes' => [
180+
$composeCacheDirectory . ':/root/.composer/cache',
181+
$this->getMagentoVolume($isReadOnly),
182+
],
183+
'volumes_from' => [
184+
'appdata',
185+
],
186+
'env_file' => [
187+
'./docker/global.env',
188+
'./docker/composer.env',
189+
],
190+
]
191+
);
192+
193+
if ($cron) {
194+
$config['command'] = 'run-cron';
195+
}
196+
197+
return $config;
198+
}
199+
200+
/**
201+
* @param bool $isReadOnly
202+
* @return string
203+
*/
204+
private function getMagentoVolume(bool $isReadOnly): string
205+
{
206+
$volume = 'magento:/var/www/magento';
207+
208+
return $isReadOnly
209+
? $volume . ':ro'
210+
: $volume . ':rw';
211+
}
212+
213+
/**
214+
* @inheritdoc
215+
*/
216+
public function getConfigPath(): string
217+
{
218+
return $this->fileList->getToolsDockerCompose();
219+
}
220+
}

0 commit comments

Comments
 (0)