|
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\Worker; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputOption as Option; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
class WorkerCommand extends MainCommand |
|
18
|
|
|
{ |
|
19
|
11 |
|
public function __construct(Deployer $deployer) |
|
20
|
|
|
{ |
|
21
|
11 |
|
parent::__construct('worker', null, $deployer); |
|
22
|
11 |
|
$this->setHidden(true); |
|
23
|
11 |
|
} |
|
24
|
|
|
|
|
25
|
11 |
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
11 |
|
$this->addArgument('worker-task', InputArgument::REQUIRED); |
|
28
|
11 |
|
$this->addArgument('worker-host', InputArgument::REQUIRED); |
|
29
|
11 |
|
$this->addArgument('config-directory', InputArgument::REQUIRED); |
|
30
|
11 |
|
$this->addArgument('master-port', InputArgument::REQUIRED); |
|
31
|
11 |
|
$this->addArgument('original-task', InputArgument::REQUIRED); |
|
32
|
11 |
|
$this->addOption('decorated', null, Option::VALUE_NONE); |
|
33
|
11 |
|
parent::configure(); |
|
34
|
11 |
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
37
|
|
|
{ |
|
38
|
1 |
|
$this->deployer->input = $input; |
|
39
|
1 |
|
$this->deployer->output = $output; |
|
40
|
|
|
|
|
41
|
1 |
|
$output->setDecorated($input->getOption('decorated')); |
|
42
|
1 |
|
if (!$output->isDecorated() && !defined('NO_ANSI')) { |
|
43
|
|
|
define('NO_ANSI', 'true'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
$task = $this->deployer->tasks->get($input->getArgument('worker-task')); |
|
47
|
1 |
|
$host = $this->deployer->hosts->get($input->getArgument('worker-host')); |
|
48
|
|
|
|
|
49
|
1 |
|
$this->deployer->config->set('config_directory', $input->getArgument('config-directory')); |
|
50
|
1 |
|
$this->deployer->config->set('master_url', 'http://localhost:' . $input->getArgument('master-port')); |
|
51
|
1 |
|
$host->getConfig()->load(); |
|
52
|
|
|
|
|
53
|
1 |
|
foreach ($host->getConfig() as $name => $value) { |
|
54
|
|
|
$this->deployer->config->set($name, $value); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
$worker = new Worker($this->deployer); |
|
58
|
1 |
|
$exitCode = $worker->execute($task, $host); |
|
59
|
|
|
|
|
60
|
1 |
|
$host->getConfig()->save(); |
|
61
|
1 |
|
return $exitCode; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|