forked from magento/ece-tools
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MCLOUD-7072: Add CLI command for generating .magento.env.yaml (#3)
- Loading branch information
1 parent
e4bb6c3
commit eaea526
Showing
39 changed files
with
761 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Command; | ||
|
||
use Magento\MagentoCloud\Filesystem\ConfigFileList; | ||
use Magento\MagentoCloud\Filesystem\Driver\File; | ||
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; | ||
|
||
/** | ||
* Creates .magento.env.yaml | ||
*/ | ||
class ConfigCreate extends Command | ||
{ | ||
const NAME = 'cloud:config:create'; | ||
|
||
const ARG_CONFIGURATION = 'configuration'; | ||
|
||
/** | ||
* @var ConfigFileList | ||
*/ | ||
private $configFileList; | ||
|
||
/** | ||
* @var File | ||
*/ | ||
private $file; | ||
|
||
/** | ||
* @param ConfigFileList $configFileList | ||
* @param File $file | ||
*/ | ||
public function __construct(ConfigFileList $configFileList, File $file) | ||
{ | ||
$this->configFileList = $configFileList; | ||
$this->file = $file; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName(static::NAME) | ||
->setDescription( | ||
'Creates a `.magento.env.yaml` file with the specified build, deploy, and post-deploy variable ' . | ||
'configuration. Overwrites any existing `.magento,.env.yaml` file.' | ||
) | ||
->addArgument( | ||
self::ARG_CONFIGURATION, | ||
InputArgument::REQUIRED, | ||
'Configuration in JSON format' | ||
); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$configuration = $input->getArgument(self::ARG_CONFIGURATION); | ||
|
||
$decodedConfig = json_decode($configuration, true); | ||
|
||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
throw new \Exception('Wrong JSON format: ' . json_last_error_msg()); | ||
} | ||
|
||
$yaml = Yaml::dump($decodedConfig, 10, 2); | ||
$filePath = $this->configFileList->getEnvConfig(); | ||
|
||
$this->file->filePutContents($filePath, $yaml); | ||
|
||
$output->writeln(sprintf("Config file %s was created", $filePath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Command; | ||
|
||
use Magento\MagentoCloud\Filesystem\ConfigFileList; | ||
use Magento\MagentoCloud\Config\Environment\ReaderInterface; | ||
use Magento\MagentoCloud\Filesystem\Driver\File; | ||
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; | ||
|
||
/** | ||
* Updates .magento.env.yaml | ||
*/ | ||
class ConfigUpdate extends Command | ||
{ | ||
const NAME = 'cloud:config:update'; | ||
|
||
const ARG_CONFIGURATION = 'configuration'; | ||
|
||
/** | ||
* @var ConfigFileList | ||
*/ | ||
private $configFileList; | ||
|
||
/** | ||
* @var File | ||
*/ | ||
private $file; | ||
|
||
/** | ||
* @var ReaderInterface | ||
*/ | ||
private $reader; | ||
|
||
/** | ||
* @param ConfigFileList $configFileList | ||
* @param File $file | ||
* @param ReaderInterface $reader | ||
*/ | ||
public function __construct(ConfigFileList $configFileList, File $file, ReaderInterface $reader) | ||
{ | ||
$this->configFileList = $configFileList; | ||
$this->file = $file; | ||
$this->reader = $reader; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName(static::NAME) | ||
->setDescription( | ||
'Updates the existing `.magento.env.yaml` file with the specified configuration. ' . | ||
'Creates `.magento.env.yaml` file if it does not exist.' | ||
) | ||
->addArgument( | ||
self::ARG_CONFIGURATION, | ||
InputArgument::REQUIRED, | ||
'Configuration in JSON format' | ||
); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$configuration = $input->getArgument(self::ARG_CONFIGURATION); | ||
|
||
$decodedConfig = json_decode($configuration, true); | ||
|
||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
throw new \Exception('Wrong JSON format: ' . json_last_error_msg()); | ||
} | ||
|
||
$config = array_replace_recursive($this->reader->read(), $decodedConfig); | ||
|
||
$yaml = Yaml::dump($config, 10, 2); | ||
$filePath = $this->configFileList->getEnvConfig(); | ||
|
||
$this->file->filePutContents($filePath, $yaml); | ||
|
||
$output->writeln(sprintf("Config file %s was updated", $filePath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.