magallanes/src/Task/BuiltIn/Deploy/ReleaseTask.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2016-12-31 07:52:25 +01:00
<?php
2022-04-10 06:20:03 +02:00
2016-12-31 07:52:25 +01:00
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Deploy;
2017-01-07 05:53:57 +01:00
use Mage\Task\Exception\ErrorException;
2016-12-31 07:52:25 +01:00
use Mage\Task\ExecuteOnRollbackInterface;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
/**
* Release Task - Create the Symlink
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
{
2022-04-10 06:20:03 +02:00
public function getName(): string
2016-12-31 07:52:25 +01:00
{
return 'deploy/release';
}
2022-04-10 06:20:03 +02:00
public function getDescription(): string
2016-12-31 07:52:25 +01:00
{
return '[Release] Creating Symlink';
}
2022-04-10 06:20:03 +02:00
public function execute(): bool
2016-12-31 07:52:25 +01:00
{
2017-01-12 02:22:21 +01:00
if (!$this->runtime->getEnvOption('releases', false)) {
2017-01-07 05:53:57 +01:00
throw new ErrorException('This task is only available with releases enabled', 40);
}
2017-01-12 02:22:21 +01:00
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
2016-12-31 07:52:25 +01:00
$releaseId = $this->runtime->getReleaseId();
2022-04-10 23:35:38 +02:00
2018-06-12 15:20:37 +02:00
$symlink = $this->runtime->getEnvOption('symlink', 'current');
2016-12-31 07:52:25 +01:00
2018-06-12 15:20:37 +02:00
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s %s', $hostPath, $releaseId, $symlink);
2016-12-31 07:52:25 +01:00
/** @var Process $process */
2022-04-10 06:20:03 +02:00
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, 0);
2016-12-31 07:52:25 +01:00
return $process->isSuccessful();
}
}