Inheritance: extends Pimple\Container
Exemple #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(Input $input, Output $output)
 {
     $stage = $input->hasArgument('stage') ? $input->getArgument('stage') : null;
     $tasks = $this->deployer->getScriptManager()->getTasks($this->getName(), $stage);
     $servers = $this->deployer->getStageStrategy()->getServers($stage);
     $environments = iterator_to_array($this->deployer->environments);
     if (isset($this->executor)) {
         $executor = $this->executor;
     } else {
         if ($input->getOption('parallel')) {
             $executor = new ParallelExecutor($this->deployer->getConsole()->getUserDefinition());
         } else {
             $executor = new SeriesExecutor();
         }
     }
     try {
         $executor->run($tasks, $servers, $environments, $input, $output);
     } catch (\Exception $exception) {
         \Deployer\logger($exception->getMessage(), Logger::ERROR);
         // Check if we have tasks to execute on failure.
         if ($this->deployer['onFailure']->has($this->getName())) {
             $taskName = $this->deployer['onFailure']->get($this->getName());
             $tasks = $this->deployer->getScriptManager()->getTasks($taskName, $stage);
             $executor->run($tasks, $servers, $environments, $input, $output);
         }
         throw $exception;
     }
     if (Deployer::hasDefault('terminate_message')) {
         $output->writeln(Deployer::getDefault('terminate_message'));
     }
 }
Exemple #2
0
 public function setUp()
 {
     // Create App tester.
     $console = new Application();
     $console->setAutoExit(false);
     $console->setCatchExceptions(false);
     $this->tester = new ApplicationTester($console);
     // Prepare Deployer
     $input = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface');
     $output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $this->deployer = new Deployer($console, $input, $output);
     // Load recipe
     $this->setUpServer();
     $this->loadRecipe();
     // Init Deployer
     $this->deployer->addConsoleCommands();
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(Input $input, Output $output)
 {
     $tasks = [];
     foreach ($this->deployer->scenarios->get($this->getName())->getTasks() as $taskName) {
         $tasks[] = $this->deployer->tasks->get($taskName);
     }
     $stage = $input->hasArgument('stage') ? $input->getArgument('stage') : null;
     $servers = $this->deployer->getStageStrategy()->getServers($stage);
     $environments = iterator_to_array($this->deployer->environments);
     if (isset($this->executor)) {
         $executor = $this->executor;
     } else {
         if ($input->getOption('parallel')) {
             $executor = new ParallelExecutor($this->deployer->getConsole()->getUserDefinition());
         } else {
             $executor = new SeriesExecutor();
         }
     }
     $executor->run($tasks, $servers, $environments, $input, $output);
 }
Exemple #4
0
/**
 * @param string $message
 * @return string
 * @codeCoverageIgnore
 */
function askHiddenResponse($message)
{
    if (isQuiet()) {
        return '';
    }
    $helper = Deployer::get()->getHelper('question');
    $message = "<question>{$message}</question> ";
    $question = new \Symfony\Component\Console\Question\Question($message);
    $question->setHidden(true);
    $question->setHiddenFallback(false);
    return $helper->ask(input(), output(), $question);
}
Exemple #5
0
                if (!empty($httpUser)) {
                    run("{$sudo} chmod +a \"{$httpUser} allow delete,write,append,file_inherit,directory_inherit\" {$dirs}");
                }
                run("{$sudo} chmod +a \"`whoami` allow delete,write,append,file_inherit,directory_inherit\" {$dirs}");
            } elseif (commandExist('setfacl')) {
                if (!empty($httpUser)) {
                    run("{$sudo} setfacl -R -m u:\"{$httpUser}\":rwX -m u:`whoami`:rwX {$dirs}");
                    run("{$sudo} setfacl -dR -m u:\"{$httpUser}\":rwX -m u:`whoami`:rwX {$dirs}");
                } else {
                    run("{$sudo} chmod 777 {$dirs}");
                }
            } else {
                run("{$sudo} chmod 777 {$dirs}");
            }
        } catch (\RuntimeException $e) {
            $formatter = \Deployer\Deployer::get()->getHelper('formatter');
            $errorMessage = ["Unable to setup correct permissions for writable dirs.                  ", "You need co configure sudo's sudoers files to don't prompt for password,", "or setup correct permissions manually.                                  "];
            write($formatter->formatBlock($errorMessage, 'error', true));
            throw $e;
        }
    }
})->desc('Make writable dirs');
/**
 * Installing vendors tasks.
 */
task('deploy:vendors', function () {
    if (commandExist('composer')) {
        $composer = 'composer';
    } else {
        run("cd {{release_path}} && curl -sS https://getcomposer.org/installer | php");
        $composer = 'php composer.phar';
Exemple #6
0
<?php

/* (c) Anton Medvedev <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Deployer;

use Deployer\Task\Context;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Style\SymfonyStyle;
desc('Print server configuration');
task('config:dump', function () {
    $server = Context::get()->getServer();
    $config = Deployer::get()->config;
    $env = Context::get()->getEnvironment();
    $dump = [];
    foreach ($config as $name => $value) {
        try {
            $env->get($name);
        } catch (\RuntimeException $exception) {
            // Ignore fails.
            $message = 'Failed to dump';
            $env->set($name, output()->isDecorated() ? "{$message}" : $message);
        }
    }
    foreach ($env->getValues() as $name => $value) {
        if (is_array($value)) {
            $value = json_encode($value);
        } elseif (is_bool($value)) {
Exemple #7
0
 public function testInstance()
 {
     $this->assertEquals($this->deployer, Deployer::get());
 }
Exemple #8
0
 /**
  * @param string $name
  * @return boolean
  */
 public static function hasDefault($name)
 {
     return isset(Deployer::get()->config[$name]);
 }
Exemple #9
0
 /**
  * @param string $serverName
  * @param string $exceptionClass
  * @param string $message
  */
 public function taskException($serverName, $exceptionClass, $message)
 {
     $formatter = Deployer::get()->getHelper('formatter');
     $messages = explode("\n", $message);
     array_unshift($messages, "Exception [{$exceptionClass}] on [{$serverName}] server:");
     $this->output->writeln($formatter->formatBlock($messages, 'error', true));
 }
Exemple #10
0
 /**
  * @param string $name
  * @param bool|int|string|array $default
  * @return bool|int|string|array
  * @throws \RuntimeException
  */
 public function get($name, $default = null)
 {
     if ($this->values->has($name)) {
         if ($this->isClosure($this->values[$name])) {
             $value = $this->values[$name] = call_user_func($this->values[$name]);
         } else {
             $value = $this->values[$name];
         }
     } else {
         $config = Deployer::get()->config;
         if (isset($config[$name])) {
             if ($this->isClosure($config[$name])) {
                 $value = $this->values[$name] = call_user_func($config[$name]);
             } else {
                 $value = $this->values[$name] = $config[$name];
             }
         } else {
             if (null === $default) {
                 throw new \RuntimeException("Configuration parameter `{$name}` does not exists.");
             } else {
                 $value = $default;
             }
         }
     }
     return $this->parse($value);
 }
Exemple #11
0
            return 'ln -nfs --relative';
        }
    }
    return 'ln -nfs';
});
/**
 * Default arguments and options.
 */
argument('stage', InputArgument::OPTIONAL, 'Run tasks only on this server or group of servers');
option('tag', null, InputOption::VALUE_OPTIONAL, 'Tag to deploy');
option('revision', null, InputOption::VALUE_OPTIONAL, 'Revision to deploy');
option('branch', null, InputOption::VALUE_OPTIONAL, 'Branch to deploy');
/**
 * Tasks
 */
desc('Show current release');
task('current', function () {
    writeln('Current release: ' . basename(get('current_path')));
});
/**
 * Success message
 */
task('success', function () {
    Deployer::setDefault('terminate_message', '<info>Successfully deployed!</info>');
})->once()->setPrivate();
/**
 * Deploy failure
 */
task('deploy:failed', function () {
})->setPrivate();
onFailure('deploy', 'deploy:failed');