|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Magallanes package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Andrés Montañez <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Mage\Task\BuiltIn\Deploy; |
|
13
|
|
|
|
|
14
|
|
|
use Mage\Task\Exception\ErrorException; |
|
15
|
|
|
use Mage\Task\ExecuteOnRollbackInterface; |
|
16
|
|
|
use Symfony\Component\Process\Process; |
|
17
|
|
|
use Mage\Task\AbstractTask; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Release Task - Create the Symlink |
|
21
|
|
|
* |
|
22
|
|
|
* @author Andrés Montañez <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface |
|
25
|
|
|
{ |
|
26
|
48 |
|
public function getName(): string |
|
27
|
|
|
{ |
|
28
|
48 |
|
return 'deploy/release'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
14 |
|
public function getDescription(): string |
|
32
|
|
|
{ |
|
33
|
14 |
|
return '[Release] Creating Symlink'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
14 |
|
public function execute(): bool |
|
37
|
|
|
{ |
|
38
|
14 |
|
if (!$this->runtime->getEnvOption('releases', false)) { |
|
39
|
1 |
|
throw new ErrorException('This task is only available with releases enabled', 40); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
13 |
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/'); |
|
43
|
13 |
|
$releaseId = $this->runtime->getReleaseId(); |
|
44
|
|
|
|
|
45
|
13 |
|
$symlink = $this->runtime->getEnvOption('symlink', 'current'); |
|
46
|
|
|
|
|
47
|
13 |
|
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s %s', $hostPath, $releaseId, $symlink); |
|
48
|
|
|
|
|
49
|
|
|
/** @var Process $process */ |
|
50
|
13 |
|
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, 0); |
|
51
|
13 |
|
return $process->isSuccessful(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|