Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #70 from ipunkt/restart-command
Browse files Browse the repository at this point in the history
Restart command
  • Loading branch information
Sven Speckmaier authored Oct 11, 2017
2 parents eca6c66 + c9bc118 commit 4eb234f
Show file tree
Hide file tree
Showing 38 changed files with 904 additions and 359 deletions.
8 changes: 7 additions & 1 deletion app/Blueprint/BlueprintProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php namespace Rancherize\Blueprint;

use Rancherize\Blueprint\Factory\BlueprintFactory;
use Rancherize\Blueprint\Factory\ContainerBlueprintFactory;
use Rancherize\Plugin\Provider;
use Rancherize\Plugin\ProviderTrait;
use Rancherize\Services\BlueprintService;

/**
* Class BlueprintProvider
Expand All @@ -15,9 +17,13 @@ class BlueprintProvider implements Provider {
/**
*/
public function register() {
$this->container['blueprint-factory'] = function($c) {
$this->container[BlueprintFactory::class] = function($c) {
return new ContainerBlueprintFactory($c);
};

$this->container[BlueprintService::class] = function($c) {
return new BlueprintService($c[BlueprintFactory::class]);
};
}

/**
Expand Down
19 changes: 17 additions & 2 deletions app/Blueprint/Commands/BlueprintAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@
* @package Rancherize\Commands
*
* Add the given blueprint name and classpath to the known blueprints
* @deprecated Blueprints are automatically added to the list via plugin providers now.
*/
class BlueprintAdd extends Command {
/**
* @var BlueprintFactory
*/
private $blueprintFactory;

/**
* BlueprintAdd constructor.
* @param BlueprintFactory $blueprintFactory
*/
public function __construct( BlueprintFactory $blueprintFactory) {
parent::__construct();
$this->blueprintFactory = $blueprintFactory;
}

/**
*
Expand All @@ -31,6 +45,8 @@ protected function configure() {
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('<info>This command is deprecated and will be removed in the future.</info>');

/**
* @var ProjectConfiguration $projectConfig
*/
Expand All @@ -50,8 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
/**
* @var BlueprintFactory $blueprintFactory
*/
$blueprintFactory = container('blueprint-factory');
$blueprintFactory->add($name, $classpath);
$this->blueprintFactory->add($name, $classpath);

/**
* TODO: logical combination of add -> projectConfig->save
Expand Down
43 changes: 33 additions & 10 deletions app/Blueprint/Commands/BlueprintList.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Rancherize\Blueprint\Commands;

use Rancherize\Blueprint\Factory\BlueprintFactory;
use Rancherize\Configuration\Configurable;
use Rancherize\Configuration\Services\ProjectConfiguration;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -12,6 +14,34 @@
* List all known blueprints
*/
class BlueprintList extends Command {
/**
* @var BlueprintFactory
*/
private $blueprintFactory;

/**
* @var ProjectConfiguration
*/
private $projectConfiguration;

/**
* @var Configurable
*/
private $configurable;

/**
* BlueprintList constructor.
* @param BlueprintFactory $blueprintFactory
* @param ProjectConfiguration $projectConfiguration
* @param Configurable $configurable
* @internal param Configuration $configuration
*/
public function __construct( BlueprintFactory $blueprintFactory, ProjectConfiguration $projectConfiguration, Configurable $configurable) {
parent::__construct();
$this->blueprintFactory = $blueprintFactory;
$this->projectConfiguration = $projectConfiguration;
$this->configurable = $configurable;
}

/**
*
Expand All @@ -28,19 +58,12 @@ protected function configure() {
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
/**
* @var ProjectConfiguration $projectConfig
*/
$projectConfig = container('project-config-service');
$configuration = container('configuration');
$projectConfig = $this->projectConfiguration;
$configuration = $this->configurable;
$configuration = $projectConfig->load($configuration);
container()->offsetSet('project-configuration', $configuration);

/**
* @var BlueprintFactory $blueprintFactory
*/
$blueprintFactory = container('blueprint-factory');
$blueprints = $blueprintFactory->available();
$blueprints = $this->blueprintFactory->available();

$output->writeln([
'Available Blueprints',
Expand Down
3 changes: 2 additions & 1 deletion app/Blueprint/ProjectName/ProjectNameProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Rancherize\Blueprint\ProjectName;

use Rancherize\Blueprint\ProjectName\ProjectNameService\ComposerProjectNameService;
use Rancherize\File\FileLoader;
use Rancherize\Plugin\Provider;
use Rancherize\Plugin\ProviderTrait;

Expand All @@ -16,7 +17,7 @@ class ProjectNameProvider implements Provider {
*/
public function register() {
$this->container['project-name-service'] = function($c) {
return new ComposerProjectNameService($c['file-loader'], $c['composer-packet-name-parser']);
return new ComposerProjectNameService($c[FileLoader::class], $c['composer-packet-name-parser']);
};
}

Expand Down
24 changes: 0 additions & 24 deletions app/Blueprint/Traits/BlueprintTrait.php

This file was deleted.

6 changes: 4 additions & 2 deletions app/Blueprint/Webserver/WebserverProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Rancherize\Blueprint\Factory\BlueprintFactory;
use Rancherize\Plugin\Provider;
use Rancherize\Plugin\ProviderTrait;
use Rancherize\RancherAccess\InServiceChecker;

/**
* Class WebserverProvider
Expand All @@ -24,7 +25,7 @@ public function boot() {
/**
* @var BlueprintFactory $blueprintFactory
*/
$blueprintFactory = container('blueprint-factory');
$blueprintFactory = $this->container[BlueprintFactory::class];
$blueprintFactory->add('webserver', function(Container $c) {
$webserverBlueprint = new WebserverBlueprint();

Expand All @@ -36,9 +37,10 @@ public function boot() {

$webserverBlueprint->setSlashPrefixer( $c['slash-prefixer'] );

$webserverBlueprint->setInServiceChecker($c['in-service-checker']);
$webserverBlueprint->setInServiceChecker($c[InServiceChecker::class]);

return $webserverBlueprint;
});

}
}
36 changes: 28 additions & 8 deletions app/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php namespace Rancherize\Commands;
use Rancherize\Blueprint\Traits\BlueprintTrait;
use Rancherize\Commands\Traits\BuildsTrait;
use Rancherize\Commands\Traits\ValidateTrait;
use Rancherize\Configuration\LoadsConfiguration;
use Rancherize\Configuration\Traits\LoadsConfigurationTrait;
use Rancherize\Services\BlueprintService;
use Rancherize\Services\BuildService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,13 +16,32 @@
* This command builds deployment files as if they were used in the start or push command.
* Can be used to inspect the files for correctness before starting or pushing
*/
class BuildCommand extends Command {
class BuildCommand extends Command implements LoadsConfiguration {

use LoadsConfigurationTrait;
use BlueprintTrait;
use BuildsTrait;
use ValidateTrait;

/**
* @var BuildService
*/
private $buildService;

/**
* @var BlueprintService
*/
private $blueprintService;

/**
* BuildCommand constructor.
* @param BuildService $buildService
* @param BlueprintService $blueprintService
*/
public function __construct( BuildService $buildService, BlueprintService $blueprintService) {
parent::__construct();
$this->buildService = $buildService;
$this->blueprintService = $blueprintService;
}

protected function configure() {
$this->setName('build')
->setDescription('Build deployment files for the given environment')
Expand All @@ -35,10 +55,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$environment = $input->getArgument('environment');
$version = $input->getArgument('version');

$buildService = $this->getBuildService();
$buildService = $this->buildService;

$configuration = $this->loadConfiguration();
$blueprint = $this->getBlueprintService()->byConfiguration($configuration, $input->getOptions());
$configuration = $this->getConfiguration();
$blueprint = $this->blueprintService->byConfiguration($configuration, $input->getOptions());

if($version !== null)
$buildService->setVersion($version);
Expand Down
87 changes: 81 additions & 6 deletions app/Commands/CommandsProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php namespace Rancherize\Commands;

use Rancherize\Blueprint\Commands\BlueprintAdd;
use Rancherize\Blueprint\Commands\BlueprintList;
use Rancherize\Blueprint\Factory\BlueprintFactory;
use Rancherize\Configuration\Services\EnvironmentConfigurationService;
use Rancherize\Docker\DockerAccessService;
use Rancherize\Plugin\Provider;
use Rancherize\Plugin\ProviderTrait;
use Rancherize\RancherAccess\InServiceChecker;
use Rancherize\RancherAccess\RancherAccessService;
use Rancherize\RancherAccess\RancherService;
use Rancherize\Services\BlueprintService;
use Rancherize\Services\BuildService;
use Rancherize\Services\DockerService;
use Symfony\Component\Console\Application;

/**
Expand All @@ -16,20 +27,74 @@ class CommandsProvider implements Provider {
*/
public function register() {
$this->container['environment-version-command'] = function($c) {
$environmentVersionCommand = new EnvironmentVersionCommand();
$environmentVersionCommand = new EnvironmentVersionCommand( $c[BlueprintService::class], $c[RancherAccessService::class], $c[EnvironmentConfigurationService::class], $c[RancherService::class] );

$environmentVersionCommand->setInServiceChecker( $c['in-service-checker'] );
$environmentVersionCommand->setInServiceChecker( $c[InServiceChecker::class] );

return $environmentVersionCommand;
};

$this->container['push-command'] = function($c) {
$pushCommand = new PushCommand();
$this->container['command.push'] = function($c) {
$pushCommand = new PushCommand( $c[RancherAccessService::class], $c[DockerService::class],
$c[BuildService::class], $c[BlueprintService::class], $c[EnvironmentConfigurationService::class],
$c[DockerAccessService::class], $c[RancherService::class] );

$pushCommand->setInServiceChecker( $c['in-service-checker'] );
$pushCommand->setInServiceChecker( $c[InServiceChecker::class] );

return $pushCommand;
};

$this->container['command.build'] = function($c) {
$buildCommand = new BuildCommand( $c[BuildService::class], $c[BlueprintService::class] );

return $buildCommand;
};

$this->container['command.start'] = function($c) {
$startCommand = new StartCommand( $c[DockerService::class], $c[BuildService::class], $c[BlueprintService::class], $c[EnvironmentConfigurationService::class] );

return $startCommand;
};

$this->container['command.stop'] = function($c) {
$stopCommand = new StopCommand( $c[DockerService::class], $c[BuildService::class], $c[BlueprintService::class], $c[EnvironmentConfigurationService::class] );

return $stopCommand;
};

$this->container['command.init'] = function($c) {
$initCommand = new InitCommand( $c[RancherAccessService::class], $c[BlueprintService::class], $c[DockerAccessService::class] );

return $initCommand;
};

$this->container['command.validate'] = function($c) {
$validateCommand = new ValidateCommand( $c[BuildService::class], $c[BlueprintService::class] );

return $validateCommand;
};

$this->container['command.restart'] = function($c) {
$restartCommand = new RestartCommand( $c[DockerService::class], $c[BuildService::class], $c[BlueprintService::class], $c[EnvironmentConfigurationService::class] );

return $restartCommand;
};

$this->container['command.blueprint.add'] = function($c) {
$blueprintAddCommand = new BlueprintAdd( $c[BlueprintFactory::class] );

return $blueprintAddCommand;
};

$this->container['command.blueprint.list'] = function($c) {
$blueprintListCommand = new BlueprintList( $c[BlueprintFactory::class], $c['project-config-service'], $c['configuration'] );

return $blueprintListCommand;
};

$this->container['command.environment.set'] = function($c) {
return new EnvironmentSetCommand( $c[EnvironmentConfigurationService::class] );
};
}

/**
Expand All @@ -40,7 +105,17 @@ public function boot() {
*/
$app = $this->container['app'];

$app->add( $this->container['push-command'] );
$app->add( $this->container['command.push'] );
$app->add( $this->container['command.build'] );
$app->add( $this->container['command.start'] );
$app->add( $this->container['command.stop'] );
$app->add( $this->container['command.restart'] );
$app->add( $this->container['command.validate'] );
$app->add( $this->container['command.init'] );
$app->add( $this->container['command.blueprint.add'] );
$app->add( $this->container['command.blueprint.list'] );
$app->add( $this->container['command.environment.set'] );

$app->add( $this->container['environment-version-command'] );
}
}
Loading

0 comments on commit 4eb234f

Please sign in to comment.