Skip to content

Commit 4f0fa96

Browse files
MAGECLOUD-5185: Platform-agnostic Docker builder #102 (#149)
1 parent 855a6a1 commit 4f0fa96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2341
-1450
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ script:
1616
- ./vendor/bin/phpcs ./src --standard=./tests/static/phpcs-ruleset.xml -p -n
1717
- ./vendor/bin/phpmd ./src xml ./tests/static/phpmd-ruleset.xml
1818
- ./vendor/bin/phpunit --configuration ./tests/unit
19+
- ./vendor/bin/phpunit --configuration ./tests/integration

bin/ece-docker

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@
66
*/
77
$container = require __DIR__ . '/../bootstrap.php';
88

9-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
10-
use Symfony\Component\Config\FileLocator;
11-
12-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
13-
$loader->load('services.xml');
14-
15-
$container->compile();
16-
179
$application = new Magento\CloudDocker\Application($container);
1810
$application->run();

bootstrap.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
use Magento\CloudDocker\Filesystem\DirectoryList;
7-
use Symfony\Component\DependencyInjection\ContainerBuilder;
8-
96
require __DIR__ . '/autoload.php';
107

11-
$container = new ContainerBuilder();
12-
$container->set(DirectoryList::class, new DirectoryList(
13-
__DIR__,
14-
BP,
15-
ECE_BP
16-
));
8+
use Magento\CloudDocker\App\Container;
179

18-
return $container;
10+
return new Container(__DIR__, BP, ECE_BP);

composer.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@
2929
],
3030
"autoload": {
3131
"psr-4": {
32-
"Magento\\CloudDocker\\": "src/"
32+
"Magento\\CloudDocker\\": "src/",
33+
"Magento\\CloudDocker\\Test\\Integration\\": "tests/integration"
3334
}
3435
},
3536
"scripts": {
36-
"test": [
37-
"@phpstan",
38-
"@phpcs",
39-
"@phpmd",
40-
"@phpunit"
37+
"test:all": [
38+
"@test:phpstan",
39+
"@test:phpcs",
40+
"@test:phpmd",
41+
"@test:unit",
42+
"@test:integration"
4143
],
42-
"phpstan": "phpstan analyse -c tests/static/phpstan.neon",
43-
"phpcs": "phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n",
44-
"phpmd": "phpmd src xml tests/static/phpmd-ruleset.xml",
45-
"phpunit": "phpunit --configuration tests/unit"
44+
"test:phpstan": "phpstan analyse -c tests/static/phpstan.neon",
45+
"test:phpcs": "phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n",
46+
"test:phpmd": "phpmd src xml tests/static/phpmd-ruleset.xml",
47+
"test:unit": "phpunit --configuration tests/unit",
48+
"test:integration": "phpunit --configuration tests/integration"
4649
},
4750
"config": {
4851
"sort-packages": true

config/services.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
<!-- Default configuration for services in *this* file -->
77
<defaults autowire="true" autoconfigure="true" public="true"/>
88

9-
<prototype namespace="Magento\CloudDocker\" resource="../src/*" exclude="../src/{App,Test}"/>
9+
<prototype namespace="Magento\CloudDocker\" resource="../src/*" exclude="../src/{Test}"/>
10+
<service id="Magento\CloudDocker\App\Container" autowire="false"/>
11+
<service id="Magento\CloudDocker\App\ContainerInterface" alias="container"/>
12+
<service id="Magento\CloudDocker\App\ContainerException" autowire="false"/>
1013
<service id="Magento\CloudDocker\Compose\BuilderFactory">
1114
<argument key="$strategies" type="collection">
1215
<argument key="developer">Magento\CloudDocker\Compose\DeveloperBuilder</argument>
@@ -16,10 +19,15 @@
1619
</service>
1720
<service id="Magento\CloudDocker\Filesystem\DirectoryList" autowire="false"/>
1821
<service id="Magento\CloudDocker\Filesystem\FilesystemException" autowire="false"/>
22+
<service id="Magento\CloudDocker\Config\Source\SourceException" autowire="false"/>
1923
<service id="Magento\CloudDocker\Filesystem\FileNotFoundException" autowire="false"/>
24+
<service id="Magento\CloudDocker\App\ConfigurationMismatchException" autowire="false"/>
25+
<service id="Magento\CloudDocker\App\GenericException" autowire="false"/>
2026
<service id="Magento\CloudDocker\Compose\DeveloperBuilder" shared="false"/>
2127
<service id="Magento\CloudDocker\Compose\ProductionBuilder" shared="false"/>
2228
<service id="Magento\CloudDocker\Compose\FunctionalBuilder" shared="false"/>
29+
<service id="Magento\CloudDocker\Config\Config" autowire="false"/>
30+
<service id="Magento\CloudDocker\Config\Source\CliSource" autowire="false"/>
2331
<service id="Composer\Semver\VersionParser"/>
2432
<service id="Composer\Semver\Semver"/>
2533
</services>

src/App/Container.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\CloudDocker\App;
9+
10+
use Magento\CloudDocker\Filesystem\DirectoryList;
11+
use Symfony\Component\DependencyInjection\ContainerBuilder;
12+
use Symfony\Component\DependencyInjection\Definition;
13+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
14+
use Symfony\Component\Config\FileLocator;
15+
use Exception;
16+
17+
/**
18+
* Application container
19+
*/
20+
class Container implements ContainerInterface
21+
{
22+
/**
23+
* @var \Symfony\Component\DependencyInjection\Container
24+
*/
25+
private $container;
26+
27+
/**
28+
* @param string $root
29+
* @param string $magentoRoot
30+
* @param string|null $eceToolsRoot
31+
* @throws ContainerException
32+
*/
33+
public function __construct(string $root, string $magentoRoot, string $eceToolsRoot = null)
34+
{
35+
$containerBuilder = new ContainerBuilder();
36+
$containerBuilder->set('container', $this);
37+
$containerBuilder->setDefinition('container', new Definition(__CLASS__))
38+
->setArguments([$root, $magentoRoot, $eceToolsRoot]);
39+
40+
$containerBuilder->set(DirectoryList::class, new DirectoryList(
41+
$root,
42+
$magentoRoot,
43+
$eceToolsRoot
44+
));
45+
46+
try {
47+
$loader = new XmlFileLoader($containerBuilder, new FileLocator([__DIR__ . '/../../config']));
48+
$loader->load('services.xml');
49+
} catch (Exception $exception) {
50+
throw new ContainerException($exception->getMessage(), $exception->getCode(), $exception);
51+
}
52+
53+
$containerBuilder->compile();
54+
55+
$this->container = $containerBuilder;
56+
}
57+
58+
/**
59+
* @inheritDoc
60+
*/
61+
public function get($id)
62+
{
63+
return $this->container->get($id);
64+
}
65+
66+
/**
67+
* @inheritDoc
68+
*/
69+
public function has($id): bool
70+
{
71+
return $this->container->has($id);
72+
}
73+
74+
/**
75+
* @inheritDoc
76+
*/
77+
public function create(string $abstract, array $params = [])
78+
{
79+
if (empty($params) && $this->has($abstract)) {
80+
return $this->get($abstract);
81+
}
82+
83+
return new $abstract(...array_values($params));
84+
}
85+
}

src/App/ContainerException.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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\CloudDocker\App;
9+
10+
/**
11+
* Container generic exception
12+
*/
13+
class ContainerException extends GenericException
14+
{
15+
}

src/App/ContainerInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\CloudDocker\App;
9+
10+
/**
11+
* Interface for DI container
12+
*/
13+
interface ContainerInterface extends \Psr\Container\ContainerInterface
14+
{
15+
/**
16+
* Create an object
17+
*
18+
* @param string $abstract
19+
* @param array $params
20+
* @return mixed
21+
*/
22+
public function create(string $abstract, array $params = []);
23+
}

src/App/GenericException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\CloudDocker\App;
99

10+
use Throwable;
11+
1012
/**
1113
* Base exception
1214
*/
@@ -15,7 +17,7 @@ class GenericException extends \Exception
1517
/**
1618
* @inheritDoc
1719
*/
18-
public function __construct(string $message, int $code = 0, \Throwable $previous = null)
20+
public function __construct(string $message, int $code = 0, Throwable $previous = null)
1921
{
2022
parent::__construct($message, $code, $previous);
2123
}

0 commit comments

Comments
 (0)