/**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $options['username'] = isset($options['username']) ? $options['username'] . '@' : '';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath() . '/';
     if (!is_dir($configurationPath)) {
         return;
     }
     $encryptedConfiguration = glob($configurationPath . '*.yaml.encrypted');
     if (count($encryptedConfiguration) > 0) {
         throw new \TYPO3\Surf\Exception\TaskExecutionException('You have sealed configuration files, please open the configuration for "' . $deployment->getName() . '"', 1317229449);
     }
     $configurations = glob($configurationPath . '*.yaml');
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         if ($node->isLocalhost()) {
             $commands[] = "mkdir -p '{$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "cp {$configuration} {$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         } else {
             $username = $options['username'];
             $hostname = $node->getHostname();
             $sshPort = $node->hasOption('port') ? '-p ' . escapeshellarg($node->getOption('port')) : '';
             $scpPort = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
             $commands[] = "ssh {$sshPort} {$username}{$hostname} 'mkdir -p {$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "scp {$scpPort} {$configuration} {$username}{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $options['username'] = isset($options['username']) ? $options['username'] . '@' : '';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath() . '/';
     if (!is_dir($configurationPath)) {
         return;
     }
     $configurations = glob($configurationPath . '*');
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         if ($node->isLocalhost()) {
             $commands[] = "mkdir -p '{$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "cp {$configuration} {$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         } else {
             $username = $options['username'];
             $hostname = $node->getHostname();
             $sshPort = $node->hasOption('port') ? '-p ' . escapeshellarg($node->getOption('port')) : '';
             $scpPort = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
             $commands[] = "ssh {$sshPort} {$username}{$hostname} 'mkdir -p {$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "scp {$scpPort} {$configuration} {$username}{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
Exemple #3
0
 /**
  * Executes this task
  *
  * Options:
  *   command: The command to execute
  *   rollbackCommand: The command to execute as a rollback (optional)
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @return void
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     if (!isset($options['folders'])) {
         return;
     }
     $folders = $options['folders'];
     if (!is_array($folders)) {
         $folders = array($folders);
     }
     $replacePaths = array('{deploymentPath}' => escapeshellarg($application->getDeploymentPath()), '{sharedPath}' => escapeshellarg($application->getSharedPath()), '{releasePath}' => escapeshellarg($deployment->getApplicationReleasePath($application)), '{currentPath}' => escapeshellarg($application->getReleasesPath() . '/current'), '{previousPath}' => escapeshellarg($application->getReleasesPath() . '/previous'));
     $commands = array();
     $username = isset($options['username']) ? $options['username'] . '@' : '';
     $hostname = $node->getHostname();
     $port = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
     foreach ($folders as $folderPair) {
         if (!is_array($folderPair) || count($folderPair) !== 2) {
             throw new InvalidConfigurationException('Each rsync folder definition must be an array of exactly two folders', 1405599056);
         }
         $sourceFolder = rtrim(str_replace(array_keys($replacePaths), $replacePaths, $folderPair[0]), '/') . '/';
         $targetFolder = rtrim(str_replace(array_keys($replacePaths), $replacePaths, $folderPair[1]), '/') . '/';
         $commands[] = "rsync -avz --delete -e ssh {$sourceFolder} {$username}{$hostname}:{$targetFolder}";
     }
     $ignoreErrors = isset($options['ignoreErrors']) && $options['ignoreErrors'] === true;
     $logOutput = !(isset($options['logOutput']) && $options['logOutput'] === false);
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment, $ignoreErrors, $logOutput);
 }
Exemple #4
0
 /**
  * Execute this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $this->assertRequiredOptionsExist($options);
     $dumpCommand = new ProcessBuilder();
     $dumpCommand->setPrefix('mysqldump');
     $dumpCommand->setArguments(array('-h', $options['sourceHost'], '-u', $options['sourceUser'], '-p' . $options['sourcePassword'], $options['sourceDatabase']));
     $mysqlCommand = new ProcessBuilder();
     $mysqlCommand->setPrefix('mysql');
     $mysqlCommand->setArguments(array('-h', $options['targetHost'], '-u', $options['targetUser'], '-p' . $options['targetPassword'], $options['targetDatabase']));
     $arguments = array();
     $username = isset($options['username']) ? $options['username'] . '@' : '';
     $hostname = $node->getHostname();
     $arguments[] = $username . $hostname;
     if ($node->hasOption('port')) {
         $arguments[] = '-P';
         $arguments[] = $node->getOption('port');
     }
     $arguments[] = $mysqlCommand->getProcess()->getCommandLine();
     $sshCommand = new ProcessBuilder();
     $sshCommand->setPrefix('ssh');
     $sshCommand->setArguments($arguments);
     $command = $dumpCommand->getProcess()->getCommandLine() . ' | ' . $sshCommand->getProcess()->getCommandLine();
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($command, $localhost, $deployment);
 }
Exemple #5
0
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $configurationFileExtension = isset($options['configurationFileExtension']) ? $options['configurationFileExtension'] : 'yaml';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath();
     if (!is_dir($configurationPath)) {
         return;
     }
     $commands = array();
     $configurationFiles = Files::readDirectoryRecursively($configurationPath, $configurationFileExtension);
     foreach ($configurationFiles as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         $escapedSourcePath = escapeshellarg($configuration);
         $escapedTargetPath = escapeshellarg(Files::concatenatePaths(array($targetReleasePath, 'Configuration', $targetConfigurationPath)) . '/');
         if ($node->isLocalhost()) {
             $commands[] = 'mkdir -p ' . $escapedTargetPath;
             $commands[] = 'cp ' . $escapedSourcePath . ' ' . $escapedTargetPath;
         } else {
             $username = isset($options['username']) ? $options['username'] . '@' : '';
             $hostname = $node->getHostname();
             $sshPort = isset($options['port']) ? '-p ' . escapeshellarg($options['port']) . ' ' : '';
             $scpPort = isset($options['port']) ? '-P ' . escapeshellarg($options['port']) . ' ' : '';
             $createDirectoryCommand = '"mkdir -p ' . $escapedTargetPath . '"';
             $commands[] = "ssh {$sshPort}{$username}{$hostname} {$createDirectoryCommand}";
             $commands[] = "scp {$scpPort}{$escapedSourcePath} {$username}{$hostname}:\"{$escapedTargetPath}\"";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
 /**
  * Execute this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws InvalidConfigurationException
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $this->assertRequiredOptionsExist($options);
     $username = isset($options['username']) ? $options['username'] . '@' : '';
     $hostname = $node->getHostname();
     $port = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
     $commands[] = "mysqldump -h {$options['sourceHost']} -u{$options['sourceUser']} -p{$options['sourcePassword']} {$options['sourceDatabase']} | ssh {$port} {$username}{$hostname} 'mysql -h {$options['targetHost']} -u{$options['targetUser']} -p{$options['targetPassword']} {$options['targetDatabase']}'";
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @return void
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $this->hosting = $application->getOption('hosting');
     $this->username = $options['username'];
     $this->hostname = $node->getHostname();
     $this->deployment = $deployment;
     $this->resourcePath = $this->packageManager->getPackage('Famelo.Surf.SharedHosting')->getResourcesPath() . 'Private/' . $this->hosting;
     $this->temporaryPath = FLOW_PATH_ROOT . '/Data/Temporary/Deployment/' . $this->hosting;
     if (!is_dir($this->temporaryPath)) {
         \TYPO3\Flow\Utility\Files::createDirectoryRecursively($this->temporaryPath);
     }
 }
 /**
  * Executes this task
  *
  * @param Node $node
  * @param Application $application
  * @param Deployment $deployment
  * @param array $options
  * @throws TaskExecutionException
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     if ($node->isLocalhost()) {
         $deployment->getLogger()->log('node seems not to be a remote node', LOG_DEBUG);
     } else {
         $username = $node->hasOption('username') ? $node->getOption('username') : NULL;
         if (!empty($username)) {
             $username = $username . '@';
         }
         $hostname = $node->getHostname();
         $sshOptions = array('-A', '-q', '-o BatchMode=yes');
         if ($node->hasOption('port')) {
             $sshOptions[] = '-p ' . escapeshellarg($node->getOption('port'));
         }
         $command = 'ssh ' . implode(' ', $sshOptions) . ' ' . escapeshellarg($username . $hostname) . ' exit;';
         $this->shell->execute($command, $deployment->getNode('localhost'), $deployment);
         $deployment->getLogger()->log('SSH connection successfully established', LOG_DEBUG);
     }
 }
Exemple #9
0
 /**
  * @param Node $node
  * @param string $file
  * @return string
  */
 protected function getArgument(Node $node, $file)
 {
     if ($node->isLocalhost() === TRUE) {
         return $file;
     }
     $argument = '';
     if ($node->hasOption('port')) {
         $port = $node->getOption('port');
         if (!empty($port)) {
             $argument .= '-P ' . $port . ' ';
         }
     }
     if ($node->hasOption('username')) {
         $username = $node->getOption('username');
         if (!empty($username)) {
             $argument .= $username . '@';
         }
     }
     $argument .= $node->getHostname() . ':';
     $argument .= $file;
     return $argument;
 }
 /**
  * @param Node $node
  * @param Application $application
  * @param string $path
  * @param string $file
  * @return string
  */
 protected function getArgument(Node $node, Application $application, $path, $file)
 {
     $argument = '';
     if ($node->hasOption('username')) {
         $username = $node->getOption('username');
         if (!empty($username)) {
             $argument .= $username . '@';
         }
     }
     $argument .= $node->getHostname() . ':';
     $argument .= rtrim($application->getReleasesPath(), '/') . '/';
     $argument = rtrim($argument . $path, '/') . '/';
     $argument .= $file;
     return $argument;
 }
 /**
  * @param string $localPath
  * @param string $remotePath
  */
 protected function upload($localPath, $remotePath)
 {
     $cmd = sprintf('rsync  -e "ssh -p %d" -avz %s %s@%s:%s', $this->remoteNode->getOption('port'), $localPath, $this->remoteNode->getOption('username'), $this->remoteNode->getHostname(), $remotePath);
     $this->log('Uploading files to remote instance');
     $this->shell->executeOrSimulate($cmd, $this->localNode, $this->deployment);
 }
Exemple #12
0
 /**
  * @param Node $node
  * @param string $path
  * @return string
  */
 protected function getFullPath(Node $node, $path)
 {
     $hostArgument = '';
     if ($node->isLocalhost() === FALSE) {
         if ($node->hasOption('username')) {
             $hostArgument .= $node->getOption('username') . '@';
         }
         $hostArgument .= $node->getHostname() . ':';
     }
     return escapeshellarg($hostArgument . rtrim($path, '/') . '/');
 }