Fixes issue #1671, Range expansion in FileLoader when host.yml is loa… (#1686)

This commit is contained in:
J Randall 2018-09-04 02:28:33 -04:00 committed by Anton Medvedev
parent 17ce9a86b0
commit b4672dd2fb
5 changed files with 31 additions and 7 deletions

View File

@ -1,11 +1,15 @@
# Changelog
## master
[v6.3.0...master](https://github.com/deployphp/deployer/compare/v6.3.0...master)
### Changed
- Laravel recipe should not run `artisan:cache:clear` in `deploy` task
### Fixed
- Fixed Range expansion when hosts.yml is loaded. [#1671]
## v6.3.0
[v6.2.0...v6.3.0](https://github.com/deployphp/deployer/compare/v6.2.0...v6.3.0)
@ -403,7 +407,7 @@
- Fixed typo3 recipe
- Fixed remove of shared dir on first deploy
[#1671]: https://github.com/deployphp/deployer/issues/1671
[#1663]: https://github.com/deployphp/deployer/issues/1663
[#1661]: https://github.com/deployphp/deployer/pull/1661
[#1634]: https://github.com/deployphp/deployer/pull/1634

View File

@ -16,7 +16,25 @@ class FileLoader
* @var Host[]
*/
private $hosts = [];
/**
* @param array $datain
* @return array $dataexp
*/
public function expandOnLoad($datain)
{
$dataout = [];
foreach ($datain as $hostname => $config) {
if (preg_match('/\[(.+?)\]/', $hostname)) {
foreach (Range::expand([$hostname]) as $splithost) {
$dataout["$splithost"] = $config;
}
} else {
$dataout["$hostname"] = $config;
}
}
return $dataout;
}
/**
* @param string $file
* @return $this
@ -29,6 +47,7 @@ class FileLoader
}
$data = Yaml::parse(file_get_contents($file));
$data = $this->expandOnLoad($data);
if (!is_array($data)) {
throw new Exception("Hosts file `$file` should contains array of hosts.");

View File

@ -35,11 +35,7 @@ app.deployer.org:
roles: app
deploy_path: ~/app
db1.deployer.org:
stage: production
roles: db
db2.deployer.org:
db[1:2].deployer.org:
stage: production
roles: db

View File

@ -98,7 +98,7 @@ class FunctionsTest extends TestCase
{
inventory(__DIR__ . '/../fixture/inventory.yml');
foreach (['app.deployer.org', 'beta.deployer.org'] as $hostname) {
foreach (['app.deployer.org', 'beta.deployer.org', 'db1.deployer.org', 'db2.deployer.org'] as $hostname) {
self::assertInstanceOf(Host::class, $this->deployer->hosts->get($hostname));
}
}

View File

@ -51,6 +51,11 @@ class FileLoaderTest extends TestCase
'-f -A -someFlag value -p 22 -F configFile -i identityFile -o Option=Value',
$bar->getSshArguments()->getCliArguments()
);
$db1 = $this->getHost('db1.deployer.org');
self::assertEquals('db1.deployer.org', $db1->getHostname());
$db2 = $this->getHost('db2.deployer.org');
self::assertEquals('db2.deployer.org', $db2->getHostname());
}
/**