Skip to content

Commit 054897f

Browse files
authored
Local deployment
Add the possibility to deploy from the remote server to the path's server. Add somes tests.
1 parent f69cd8b commit 054897f

30 files changed

+859
-318
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"romaricdrigon/metayaml": "^1.1",
1212
"phpseclib/phpseclib": "~2.0",
1313
"padraic/phar-updater": "^1.0",
14-
"guzzlehttp/guzzle": "^6.3"
14+
"guzzlehttp/guzzle": "^6.3",
15+
"symfony/process": "^3.4"
1516
},
1617
"require-dev": {
1718
"phake/phake": "~2.0",

composer.lock

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Automate/Application.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Automate;
1313

1414
use Automate\Command\DeployCommand;
15+
use Automate\Command\LocalDeployCommand;
1516
use Automate\Command\SelfUpdateCommand;
16-
use KevinGH\Amend;
1717
use Symfony\Component\Console\Application as BaseApplication;
1818

1919
class Application extends BaseApplication
@@ -53,12 +53,12 @@ protected function getDefaultCommands()
5353
$commands = parent::getDefaultCommands();
5454

5555
$commands[] = new DeployCommand();
56+
$commands[] = new LocalDeployCommand();
5657

5758
if (('@'.'git-version@') !== $this->getVersion()) {
5859
$commands[] = new SelfUpdateCommand();
5960
}
6061

6162
return $commands;
6263
}
63-
6464
}

src/Automate/Command/DeployCommand.php

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Automate\Command;
1313

14-
use Automate\Context;
14+
use Automate\Context\SSHContext;
1515
use Automate\Loader;
1616
use Automate\Model\Platform;
1717
use Automate\VariableResolver;
@@ -28,7 +28,7 @@ protected function configure()
2828
{
2929
$this
3030
->setName('deploy')
31-
->setDescription('Start deployment.')
31+
->setDescription('Start remote deployment.')
3232
->addArgument('platform', InputArgument::REQUIRED, 'Platform name')
3333
->addArgument('gitRef', InputArgument::OPTIONAL, 'Branch or tag name')
3434
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Configuration file path', self::CONFIG_FILE)
@@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6060
array('Version', $input->getArgument('gitRef') ?: $platform->getDefaultBranch()),
6161
));
6262

63-
$context = new Context($project, $platform, $gitRef, $logger, $input->getOption('force'));
63+
$context = new SSHContext($project, $platform, $gitRef, $logger, $input->getOption('force'));
6464
$workflow = new Deployer($context);
6565

6666
if (!$workflow->deploy()) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Automate package.
5+
*
6+
* (c) Julien Jacottet <jjacottet@gmail.com>
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 Automate\Command;
13+
14+
use Automate\Loader;
15+
use Automate\Context\LocalContext;
16+
use Automate\Model\Platform;
17+
use Automate\Model\Server;
18+
use Automate\VariableResolver;
19+
use Automate\Workflow\Deployer;
20+
use Symfony\Component\Console\Input\InputArgument;
21+
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Input\InputOption;
23+
use Symfony\Component\Console\Output\OutputInterface;
24+
use Symfony\Component\Console\Style\SymfonyStyle;
25+
26+
class LocalDeployCommand extends BaseCommand
27+
{
28+
protected function configure()
29+
{
30+
$this
31+
->setName('run')
32+
->setDescription('Start local deployment.')
33+
->addArgument('path', InputArgument::REQUIRED, 'Project\'s local path')
34+
->addArgument('gitRef', InputArgument::REQUIRED, 'Branch or tag name')
35+
->addOption('max-releases', null, InputOption::VALUE_REQUIRED, 'The number of releases to be kept', 3)
36+
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Configuration file path', self::CONFIG_FILE)
37+
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to deploy')
38+
;
39+
}
40+
41+
protected function execute(InputInterface $input, OutputInterface $output)
42+
{
43+
$loader = new Loader();
44+
$project = $loader->load($input->getOption('config'));
45+
46+
$platform = $this->createLocalPlatforme($input->getArgument('path'), $input->getOption('max-releases'));
47+
48+
$io = new SymfonyStyle($input, $output);
49+
50+
$variableResolver = new VariableResolver($io);
51+
$variableResolver->resolveRepository($project);
52+
53+
$logger = $this->getLogger($io);
54+
55+
$logger->section('Start local deployment');
56+
57+
$gitRef = $input->getArgument('gitRef');
58+
59+
$io->table(array(), array(
60+
array('Repository', $project->getRepository()),
61+
array('Version', $input->getArgument('gitRef') ?: $platform->getDefaultBranch()),
62+
));
63+
64+
$context = new LocalContext($project, $platform, $gitRef, $logger, $input->getOption('force'));
65+
$workflow = new Deployer($context);
66+
67+
if (!$workflow->deploy()) {
68+
throw new \RuntimeException('Deployment failed');
69+
}
70+
71+
$io->success('All is OK');
72+
}
73+
74+
private function createLocalPlatforme($path, $maxReleases)
75+
{
76+
$serveur = new Server();
77+
$serveur
78+
->setPath($path)
79+
->setName('local')
80+
;
81+
82+
$platform = new Platform();
83+
$platform->setMaxReleases($maxReleases);
84+
$platform->addServer($serveur);
85+
return $platform;
86+
}
87+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy