1
|
|
|
<?php |
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Deployer\Console; |
9
|
|
|
|
10
|
|
|
use Deployer\Deployer; |
11
|
|
|
use Deployer\Executor\ExecutorInterface; |
12
|
|
|
use Deployer\Executor\ParallelExecutor; |
13
|
|
|
use Deployer\Executor\SeriesExecutor; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface as Input; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption as Option; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface as Output; |
18
|
|
|
|
19
|
|
|
class TaskCommand extends Command |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Deployer |
23
|
|
|
*/ |
24
|
|
|
private $deployer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ExecutorInterface |
28
|
|
|
*/ |
29
|
|
|
public $executor; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $name |
33
|
|
|
* @param string $description |
34
|
|
|
* @param Deployer $deployer |
35
|
|
|
*/ |
36
|
15 |
|
public function __construct($name, $description, Deployer $deployer) |
37
|
|
|
{ |
38
|
15 |
|
parent::__construct($name); |
39
|
15 |
|
$this->setDescription($description); |
40
|
15 |
|
$this->deployer = $deployer; |
41
|
15 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Configures the command |
45
|
|
|
*/ |
46
|
15 |
|
protected function configure() |
47
|
|
|
{ |
48
|
15 |
|
$this->addOption( |
49
|
15 |
|
'parallel', |
50
|
15 |
|
'p', |
51
|
15 |
|
Option::VALUE_NONE, |
52
|
|
|
'Run tasks in parallel.' |
53
|
15 |
|
); |
54
|
15 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
15 |
|
protected function execute(Input $input, Output $output) |
60
|
|
|
{ |
61
|
15 |
|
$stage = $input->hasArgument('stage') ? $input->getArgument('stage') : null; |
62
|
15 |
|
|
63
|
15 |
|
$tasks = $this->deployer->getScriptManager()->getTasks($this->getName(), $stage); |
64
|
15 |
|
$servers = $this->deployer->getStageStrategy()->getServers($stage); |
65
|
|
|
$environments = iterator_to_array($this->deployer->environments); |
66
|
15 |
|
|
67
|
|
|
if (isset($this->executor)) { |
68
|
15 |
|
$executor = $this->executor; |
69
|
|
|
} else { |
70
|
15 |
|
if ($input->getOption('parallel')) { |
71
|
|
|
$executor = new ParallelExecutor($this->deployer->getConsole()->getUserDefinition()); |
72
|
15 |
|
} else { |
73
|
1 |
|
$executor = new SeriesExecutor(); |
74
|
1 |
|
} |
75
|
15 |
|
} |
76
|
2 |
|
|
77
|
2 |
|
$executor->run($tasks, $servers, $environments, $input, $output); |
78
|
12 |
|
} |
79
|
|
|
} |
80
|
|
|
|