Skip to content

Commit

Permalink
Local deployment
Browse files Browse the repository at this point in the history
Add the possibility to deploy from the remote server to the path's server. 
Add somes tests.
  • Loading branch information
romaricp authored Apr 9, 2018
1 parent f69cd8b commit 054897f
Show file tree
Hide file tree
Showing 30 changed files with 859 additions and 318 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"romaricdrigon/metayaml": "^1.1",
"phpseclib/phpseclib": "~2.0",
"padraic/phar-updater": "^1.0",
"guzzlehttp/guzzle": "^6.3"
"guzzlehttp/guzzle": "^6.3",
"symfony/process": "^3.4"
},
"require-dev": {
"phake/phake": "~2.0",
Expand Down
51 changes: 50 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Automate/Application.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Automate;

use Automate\Command\DeployCommand;
use Automate\Command\LocalDeployCommand;
use Automate\Command\SelfUpdateCommand;
use KevinGH\Amend;
use Symfony\Component\Console\Application as BaseApplication;

class Application extends BaseApplication
Expand Down Expand Up @@ -53,12 +53,12 @@ protected function getDefaultCommands()
$commands = parent::getDefaultCommands();

$commands[] = new DeployCommand();
$commands[] = new LocalDeployCommand();

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

return $commands;
}

}
6 changes: 3 additions & 3 deletions src/Automate/Command/DeployCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Automate\Command;

use Automate\Context;
use Automate\Context\SSHContext;
use Automate\Loader;
use Automate\Model\Platform;
use Automate\VariableResolver;
Expand All @@ -28,7 +28,7 @@ protected function configure()
{
$this
->setName('deploy')
->setDescription('Start deployment.')
->setDescription('Start remote deployment.')
->addArgument('platform', InputArgument::REQUIRED, 'Platform name')
->addArgument('gitRef', InputArgument::OPTIONAL, 'Branch or tag name')
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Configuration file path', self::CONFIG_FILE)
Expand Down Expand Up @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
array('Version', $input->getArgument('gitRef') ?: $platform->getDefaultBranch()),
));

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

if (!$workflow->deploy()) {
Expand Down
87 changes: 87 additions & 0 deletions src/Automate/Command/LocalDeployCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*
* This file is part of the Automate package.
*
* (c) Julien Jacottet <jjacottet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Automate\Command;

use Automate\Loader;
use Automate\Context\LocalContext;
use Automate\Model\Platform;
use Automate\Model\Server;
use Automate\VariableResolver;
use Automate\Workflow\Deployer;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class LocalDeployCommand extends BaseCommand
{
protected function configure()
{
$this
->setName('run')
->setDescription('Start local deployment.')
->addArgument('path', InputArgument::REQUIRED, 'Project\'s local path')
->addArgument('gitRef', InputArgument::REQUIRED, 'Branch or tag name')
->addOption('max-releases', null, InputOption::VALUE_REQUIRED, 'The number of releases to be kept', 3)
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Configuration file path', self::CONFIG_FILE)
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to deploy')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$loader = new Loader();
$project = $loader->load($input->getOption('config'));

$platform = $this->createLocalPlatforme($input->getArgument('path'), $input->getOption('max-releases'));

$io = new SymfonyStyle($input, $output);

$variableResolver = new VariableResolver($io);
$variableResolver->resolveRepository($project);

$logger = $this->getLogger($io);

$logger->section('Start local deployment');

$gitRef = $input->getArgument('gitRef');

$io->table(array(), array(
array('Repository', $project->getRepository()),
array('Version', $input->getArgument('gitRef') ?: $platform->getDefaultBranch()),
));

$context = new LocalContext($project, $platform, $gitRef, $logger, $input->getOption('force'));
$workflow = new Deployer($context);

if (!$workflow->deploy()) {
throw new \RuntimeException('Deployment failed');
}

$io->success('All is OK');
}

private function createLocalPlatforme($path, $maxReleases)
{
$serveur = new Server();
$serveur
->setPath($path)
->setName('local')
;

$platform = new Platform();
$platform->setMaxReleases($maxReleases);
$platform->addServer($serveur);
return $platform;
}
}
Loading

0 comments on commit 054897f

Please # to comment.