Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions shipyard.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ settings:
# Target connection. Values: remote/local
target: remote
# Template directory path on the remote host
stack_path: /opt/shipyard/stacks
shipyard_tag: apps
stack_path: /opt/shipyard/stacks
3 changes: 1 addition & 2 deletions shipyard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ settings:
# Target connection. Values: remote/local
target: remote
# Template directory path on the remote host
stack_path: /opt/shipyard/stacks
shipyard_tag: apps
stack_path: /opt/shipyard/stacks
14 changes: 13 additions & 1 deletion src/Command/ApplyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
Expand All @@ -32,6 +33,16 @@ public function execute(InputInterface $input, OutputInterface $output)

$config = $serializer->deserialize(file_get_contents('shipyard.yaml'), ShipyardModel::class, 'yaml');

$tag = $input->getOption('tag') ? $input->getOption('tag') : False;
$settings = $config->getSettings();

if($tag) {
$settings->setShipyardTag($tag);
} else {
$settings->setShipyardTag(false);
}
$config->setSettings($settings);

Comment on lines +39 to +45
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kostiantyn,

Here's a improvement suggestion. This should have the same effect. I might be mistaken, so please verify if you decide to apply it.

Suggested change
if($tag) {
$settings->setShipyardTag($tag);
} else {
$settings->setShipyardTag(false);
}
$config->setSettings($settings);
$settings->setShipyardTag($tag);

Here's my reason:

  • The if removal: In case $tag been false we can set it to $settings->setShipyardTag($tag); the same way.
  • The $config->setSettings($settings); removal: $settings is a mutable object, therefore a reference and not a copy, meaning that $settings === $config->getSettings().

BR,

$shipyard = new Shipyard($config, $output);

$shipyard->apply();
Expand All @@ -43,7 +54,8 @@ protected function configure()
{
$this
->setName('apply')
->setDescription('Shipyard apply');
->setDescription('Shipyard apply')
->addOption('tag', 't', InputOption::VALUE_OPTIONAL, 'Tag for stacks to run');
}

}
2 changes: 1 addition & 1 deletion src/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function twigTemplateFile($filename, $dirPath)
*/
public function run()
{
if ($this->model->getTag() != $this->getSettings()->getShipyardTag()) {
if ($this->getSettings()->getShipyardTag() && $this->model->getTag() != $this->getSettings()->getShipyardTag()) {
$this->output->writeln(sprintf(
'- Skip stack `%s(%s)` because of tag difference.',
$this->model->getName(),
Expand Down