|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Magallanes package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Andrés Montañez <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Mage\Task\BuiltIn\Deploy\Tar; |
|
12
|
|
|
|
|
13
|
|
|
use Mage\Task\Exception\ErrorException; |
|
14
|
|
|
use Symfony\Component\Process\Process; |
|
15
|
|
|
use Mage\Task\AbstractTask; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Tar Task - Copy Tar |
|
19
|
|
|
* |
|
20
|
|
|
* @author Andrés Montañez <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class CopyTask extends AbstractTask |
|
23
|
|
|
{ |
|
24
|
|
|
public function getName() |
|
25
|
|
|
{ |
|
26
|
|
|
return 'deploy/tar/copy'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getDescription() |
|
30
|
|
|
{ |
|
31
|
|
|
return '[Deploy] Copying files with Tar'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function execute() |
|
35
|
|
|
{ |
|
36
|
|
|
if (!$this->runtime->getEnvOption('releases', false)) { |
|
37
|
|
|
throw new ErrorException('This task is only available with releases enabled', 40); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser()); |
|
41
|
|
|
$host = $this->runtime->getHostName(); |
|
42
|
|
|
$sshConfig = $sshConfig = $this->runtime->getSSHConfig(); |
|
43
|
|
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/'); |
|
44
|
|
|
$currentReleaseId = $this->runtime->getReleaseId(); |
|
45
|
|
|
|
|
46
|
|
|
$tarPath = $this->runtime->getEnvOption('tar_extract_path', 'tar'); |
|
47
|
|
|
$flags = $this->runtime->getEnvOption('tar_extract', 'xfzop'); |
|
48
|
|
|
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId); |
|
49
|
|
|
|
|
50
|
|
|
$tarLocal = $this->runtime->getVar('tar_local'); |
|
51
|
|
|
$tarRemote = basename($tarLocal); |
|
52
|
|
|
|
|
53
|
|
|
$cmdCopy = sprintf('scp -P %d %s %s %s@%s:%s/%s', $sshConfig['port'], $sshConfig['flags'], $tarLocal, $user, $host, $targetDir, $tarRemote); |
|
54
|
|
|
|
|
55
|
|
|
/** @var Process $process */ |
|
56
|
|
|
$process = $this->runtime->runLocalCommand($cmdCopy, 300); |
|
57
|
|
|
if ($process->isSuccessful()) { |
|
58
|
|
|
$cmdUnTar = sprintf('cd %s && %s %s %s', $targetDir, $tarPath, $flags, $tarRemote); |
|
59
|
|
|
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600); |
|
60
|
|
|
if ($process->isSuccessful()) { |
|
61
|
|
|
$cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote); |
|
62
|
|
|
$process = $this->runtime->runRemoteCommand($cmdDelete, false); |
|
63
|
|
|
return $process->isSuccessful(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|