-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDeployer.php
More file actions
executable file
·87 lines (73 loc) · 2.09 KB
/
Deployer.php
File metadata and controls
executable file
·87 lines (73 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace BeSimple\DeploymentBundle\Deployer;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use BeSimple\DeploymentBundle\Events;
use BeSimple\DeploymentBundle\Event\DeployerEvent;
class Deployer
{
/**
* @var Rsync
*/
protected $rsync;
/**
* @var Ssh
*/
protected $ssh;
/**
* @var array
*/
protected $config;
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $dispatcher;
/**
* @param Rsync $rsync
* @param Ssh $ssh
* @param Config $config
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
*/
public function __construct(Rsync $rsync, Ssh $ssh, Config $config, EventDispatcherInterface $eventDispatcher)
{
$this->rsync = $rsync;
$this->ssh = $ssh;
$this->config = $config;
$this->dispatcher = $eventDispatcher;
}
/**
* @param null|string $server
* @return void
*/
public function launch($server = null)
{
$this->deploy($server, true);
}
/**
* @param null|string $server
* @return void
*/
public function test($server = null)
{
$this->deploy($server, false);
}
/**
* @param null|string $server
* @param bool $real
* @return
*/
protected function deploy($server = null, $real = false)
{
if(is_null($server)){
$serverNames = $this->config->getServerNames();
reset($serverNames);
return $this->deploy(current($serverNames), $real);
}
$this->dispatcher->dispatch(Events::onDeploymentStart, new DeployerEvent($server, $real));
$config = $this->config->getServerConfig($server);
$this->rsync->run($config['connection'], $config['rules'], $real);
if(false === empty($config['commands'])){
$this->ssh->run($config['connection'], $config['commands'], $real);
}
$this->dispatcher->dispatch(Events::onDeploymentSuccess, new DeployerEvent($server, $real));
}
}