-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathRollbackCommand.php
More file actions
82 lines (66 loc) · 3.07 KB
/
Copy pathRollbackCommand.php
File metadata and controls
82 lines (66 loc) · 3.07 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
<?php
/*
* This file is part of the EasyDeploy project.
*
* (c) Javier Eguiluz <javier.eguiluz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EasyCorp\Bundle\EasyDeployBundle\Command;
use EasyCorp\Bundle\EasyDeployBundle\Context;
use EasyCorp\Bundle\EasyDeployBundle\Helper\SymfonyConfigPathGuesser;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class RollbackCommand extends Command
{
private $projectDir;
private $logDir;
private $configFilePath;
public function __construct(string $projectDir, string $logDir)
{
$this->projectDir = $projectDir;
$this->logDir = $logDir;
parent::__construct();
}
protected function configure(): void
{
$this
->setName('rollback')
->setDescription('Deploys a Symfony application to one or more remote servers.')
->setHelp('...')
->addArgument('stage', InputArgument::OPTIONAL, 'The stage to roll back ("production", "staging", etc.)', 'prod')
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Load configuration from the given file path')
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Shows the commands to perform the roll back without actually executing them')
;
}
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$customConfigPath = $input->getOption('configuration');
if (null !== $customConfigPath && !is_readable($customConfigPath)) {
throw new \RuntimeException(sprintf("The given configuration file ('%s') does not exist or it's not readable.", $customConfigPath));
}
if (null !== $customConfigPath && is_readable($customConfigPath)) {
$this->configFilePath = $customConfigPath;
return;
}
$defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage'));
if (is_readable($defaultConfigPath)) {
$this->configFilePath = $defaultConfigPath;
return;
}
throw new \RuntimeException(sprintf("The default configuration file does not exist or it's not readable, and no custom configuration file was given either. Create the '%s' configuration file and run this command again.", $defaultConfigPath));
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage'));
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose());
$deployer = include $this->configFilePath;
$deployer->initialize($context);
$deployer->doRollback();
return 0;
}
}